awacke1 commited on
Commit
e600d70
·
1 Parent(s): 1203cdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -1,29 +1,25 @@
1
  import streamlit as st
2
  import numpy as np
3
 
4
- # Initialize the game board
5
  def initialize_board():
6
  board = np.zeros((8, 8), dtype=int)
7
  board[3, 3], board[4, 4], board[3, 4], board[4, 3] = 1, 1, -1, -1
8
  return board
9
 
10
- # Function to check valid moves, make a move, flip pieces...
11
-
12
  def check_end_game_condition(board):
13
- # Implement logic to check if all freedoms are covered
14
  pass
15
 
16
  def display_current_player():
17
- # Display current player
18
  if st.session_state.player == 1:
19
  st.header("Player 1's Turn (⚪️)")
20
  else:
21
  st.header("Player 2's Turn (⚫️)")
22
 
23
  def on_button_click(x, y):
24
- # Implement what happens when a button is clicked
25
- # Update the board, flip pieces, change player
26
- pass
 
27
 
28
  def display_board(board):
29
  for i in range(8):
@@ -33,20 +29,15 @@ def display_board(board):
33
  emoji = '⚪️' if piece == 1 else '⚫️' if piece == -1 else ' '
34
  cols[j].button(emoji, key=f'{i}{j}', on_click=on_button_click, args=(i, j))
35
 
36
- # Main app
37
  def main():
38
  st.title('Othello Game')
39
 
40
- # Initialize or load the board and player turn
41
  if 'board' not in st.session_state:
42
  st.session_state.board = initialize_board()
43
- st.session_state.player = 1 # Player 1 starts
44
 
45
  display_current_player()
46
  display_board(st.session_state.board)
47
-
48
- # Add logic for handling button presses, updating the board, and game flow
49
- # Check for end game condition
50
  check_end_game_condition(st.session_state.board)
51
 
52
  main()
 
1
  import streamlit as st
2
  import numpy as np
3
 
 
4
  def initialize_board():
5
  board = np.zeros((8, 8), dtype=int)
6
  board[3, 3], board[4, 4], board[3, 4], board[4, 3] = 1, 1, -1, -1
7
  return board
8
 
 
 
9
  def check_end_game_condition(board):
 
10
  pass
11
 
12
  def display_current_player():
 
13
  if st.session_state.player == 1:
14
  st.header("Player 1's Turn (⚪️)")
15
  else:
16
  st.header("Player 2's Turn (⚫️)")
17
 
18
  def on_button_click(x, y):
19
+ if st.session_state.board[x, y] == 0:
20
+ st.session_state.board[x, y] = st.session_state.player
21
+ st.session_state.player *= -1
22
+ display_current_player()
23
 
24
  def display_board(board):
25
  for i in range(8):
 
29
  emoji = '⚪️' if piece == 1 else '⚫️' if piece == -1 else ' '
30
  cols[j].button(emoji, key=f'{i}{j}', on_click=on_button_click, args=(i, j))
31
 
 
32
  def main():
33
  st.title('Othello Game')
34
 
 
35
  if 'board' not in st.session_state:
36
  st.session_state.board = initialize_board()
37
+ st.session_state.player = 1
38
 
39
  display_current_player()
40
  display_board(st.session_state.board)
 
 
 
41
  check_end_game_condition(st.session_state.board)
42
 
43
  main()