Example #1
0
def get_next_move_4(board):
    """Return player O move to ensure draw."""

    available_moves = game.available_moves(board)
    for move in [2, 3, 4, 8]:
        if move in available_moves:
            return move
Example #2
0
def get_next_move_3(board):
    """Return player X move to ensure draw."""

    available_moves = game.available_moves(board)
    for move in [0, 1, 5, 6, 7]:
        if move in available_moves:
            return move
Example #3
0
def get_next_move_8(board):
    """Return invalid move."""

    available_moves = game.available_moves(board)

    for move in range(9):
        if move not in available_moves:
            return move
Example #4
0
def get_next_move_10(board):
    """Burn through lots of opcodes and then return first available move."""

    x = 0
    for i in range(1000):
        x += 1

    available_moves = game.available_moves(board)
    return available_moves[0]
Example #5
0
def get_next_move(board, token):
    available_moves = game.available_moves(board)

    if token == "O":
        for move in range(9):
            if move not in available_moves:
                return move

    return random.choice(available_moves)
Example #6
0
def get_next_move_6(board, state):
    """Return first available move and a state.

    Also assert state is passed back to function correctly."""

    available_moves = game.available_moves(board)

    if len(available_moves) < 8:
        assert state == "Wyoming"

    return available_moves[0], "Wyoming"
Example #7
0
def get_next_move_human(board):
    available_moves = game.available_moves(board)

    while True:
        col = input("> ")
        try:
            col = int(col)
        except ValueError:
            continue

        if col not in available_moves:
            continue

        return col
Example #8
0
def play_game(fn1, fn2):
    board = game.new_board()
    display(board)

    for token, fn in itertools.cycle(zip(game.TOKENS, [fn1, fn2])):
        available_moves = game.available_moves(board)
        if available_moves == []:
            announce_draw()
            return

        pos = fn(board)
        game.make_move(board, pos, token)
        display(board)

        winner = game.check_winner(board)
        if winner is not None:
            announce_winner(winner)
            return
Example #9
0
def get_next_move_7(board, token, state, move_list):
    """Return first available move and a state.

    Also assert all params are passed in correctly."""

    assert token == game.TOKENS[len(move_list) % 2]

    board1 = game.new_board()
    for move, token in zip(move_list, itertools.cycle(game.TOKENS)):
        game.make_move(board1, move, token)

    assert board == board1

    available_moves = game.available_moves(board)

    if len(available_moves) < 8:
        assert state == "Idaho"

    return available_moves[0], "Idaho"
Example #10
0
def get_next_move_11(board):
    """Return invalid state."""

    available_moves = game.available_moves(board)
    return available_moves[0], tempfile.TemporaryFile()
Example #11
0
def get_next_move_2(board):
    """Return second available move."""

    available_moves = game.available_moves(board)
    return available_moves[1]
Example #12
0
def get_next_move_1(board):
    """Return first available move."""

    available_moves = game.available_moves(board)
    return available_moves[0]
Example #13
0
def get_next_move(board):
    available_moves = game.available_moves(board)
    return random.choice(available_moves)