Пример #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
Пример #2
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 '------------'