Exemple #1
0
def play_game():
    # Create the game
    game = ChessGame()
    # Create the two players
    player1 = StudentPlayer(Color.WHITE, game, 4)
    player2 = StudentPlayer(Color.BLACK, game, 4)
    move_list = []
    for move in game.play_game(player1, player2, verbose=True):
        move_list.append(move)
Exemple #2
0
def on_reset_game():
    global game
    global sim
    game = ChessGame()
    sim = game.play_game(player1, player2)
Exemple #3
0
# Small Flask app that starts a socket.io server for the game. Run with:
# > FLASK_APP=app.py python3.5 -m flask run

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

# Create the chess game
game = ChessGame()
# Create the two players
player1 = StudentPlayer(Color.WHITE, game, 3)
player2 = StudentPlayer(Color.BLACK, game, 3)

# Create a simulation of the game
sim = game.play_game(player1, player2)


@socketio.on('connect')
def on_connect():
    # For each move in the game we send the move to the frontend to be displayed
    # Note that play_game is a generator function and is thus iterable
    emit('server-ready')


@socketio.on('request-move')
def on_request_move():
    global sim
    move = next(sim)
    emit('move', (move['start'], move['end'], move['captured']))