Spaces:
Sleeping
Sleeping
File size: 1,226 Bytes
9674711 1203cdb e600d70 9674711 1203cdb 9674711 570ef7e 9674711 e600d70 9674711 1203cdb 9674711 1203cdb 9674711 570ef7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
import numpy as np
def initialize_board():
board = np.zeros((8, 8), dtype=int)
board[3, 3], board[4, 4], board[3, 4], board[4, 3] = 1, 1, -1, -1
return board
def check_end_game_condition(board):
pass
def display_current_player():
if st.session_state.player == 1:
st.header("Player 1's Turn (⚪️)")
else:
st.header("Player 2's Turn (⚫️)")
def on_button_click(x, y):
if st.session_state.board[x, y] == 0:
st.session_state.board[x, y] = st.session_state.player
st.session_state.player *= -1
display_current_player()
def display_board(board):
for i in range(8):
cols = st.columns(8)
for j in range(8):
piece = board[i, j]
emoji = '⚪️' if piece == 1 else '⚫️' if piece == -1 else ' '
cols[j].button(emoji, key=f'{i}{j}', on_click=on_button_click, args=(i, j))
def main():
st.title('Othello Game')
if 'board' not in st.session_state:
st.session_state.board = initialize_board()
st.session_state.player = 1
display_current_player()
display_board(st.session_state.board)
check_end_game_condition(st.session_state.board)
main()
|