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
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
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
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]
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)
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"
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
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
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"
def get_next_move_11(board): """Return invalid state.""" available_moves = game.available_moves(board) return available_moves[0], tempfile.TemporaryFile()
def get_next_move_2(board): """Return second available move.""" available_moves = game.available_moves(board) return available_moves[1]
def get_next_move_1(board): """Return first available move.""" available_moves = game.available_moves(board) return available_moves[0]
def get_next_move(board): available_moves = game.available_moves(board) return random.choice(available_moves)