Exemplo n.º 1
0
def make_moves(url, headers, data):
    logging.debug('Attempting to make moves...')
    while True:  # Play until game ends
        message, state = await_turn(url, headers, data)  # Poll until we get a state (it's our turn)
        if message is None:  # Game complete
            return
        if message == 'Game complete':  # TODO: this is horrible. Do printing elsewhere.
            print_state(state)
            return

        print_state(state)
        data['message'] = 'move'  # Making a move
        data['move'] = ai.make_move(state)  # Determine move
        print('Posting move: <{}>'.format(data['move']))
        output = post_to_game(url, headers, data)
        if output is None:
            logging.error('Received <None> output from server')
            return

        del data['move']  # Erase contents each turn
        del data['message']

        print('Message: {}'.format(output['message']))
        if output['message'] == 'Game complete':
            return
        elif output['message'] in ('Move accepted', 'Move rejected'):
            continue
Exemplo n.º 2
0
def make_ai_move(board: chess.Board):
    board_copy = chess.Board(board.fen(), chess960=True)
    move = ai.make_move(
        board_copy, 10.0
    )  # Change this float if you want to test your AI under time pressure

    if isinstance(move, str):
        move = chess.Move.from_uci(move)

    return move
Exemplo n.º 3
0
def test_make_move_full_board():
    with pytest.raises(ValueError):
        make_move(create_full_board(), 0, AI)
Exemplo n.º 4
0
def test_make_move(board, move, result):
    assert make_move(board, move, AI) == result
Exemplo n.º 5
0
def test_find_moves(moves, result):
    board = create_board()
    for move in moves:
        board = make_move(board, move, AI)
    assert (find_moves(board)) == result
Exemplo n.º 6
0
"""
    app.py
    ~~~~~~

    The main function of the Tic-Tac-Toe game

    author: Sharad Shivmath
"""

from board import Board
import ai
import human

if __name__ == '__main__':
    symbols = human.get_symbol()
    b = Board(symbols['human_symbol'], symbols['ai_symbol'])
    game_over = False

    # For the game to end, either the board should be full,
    # in which case it will be a draw, or one of the players
    # should win.
    while b.is_board_full() is False and game_over is False:
        b.print_board()
        human.make_move(b)
        game_over = ai.make_move(b)
    b.print_board()
    print '------------'
    print ' Game over!'
    print '------------'