def test_undo_moves(players, expected): game = g.Game(5, 5, 3, players) game.make_turn(Vector([0, 0])) game.make_turn(Vector([0, 1])) game.make_turn(Vector([0, 2])) game.undo_turn() assert game.current_player.color == expected assert game.board[0, 2] == Color.non
def test_make_move_to(): game = g.Game( 3, 3, 3, [HumanPlayer(Color.black), RandomBot(Color.white, PlayerEntity.bot)]) human_player = game.players[0] bot_player = game.players[1] x, y = bot_player.make_move(game) assert human_player.make_move(game) is None assert 0 <= x < 3 and 0 <= y < 3
def test_check_fouls_forks(two_human_players): game = g.Game(5, 5, 5, two_human_players, True) game.make_turn(Vector([3, 1])) game.make_turn(Vector([0, 0])) game.make_turn(Vector([3, 2])) game.make_turn(Vector([0, 1])) game.make_turn(Vector([1, 3])) game.make_turn(Vector([1, 0])) game.make_turn(Vector([2, 3])) game.make_turn(Vector([1, 1])) game.make_turn(Vector([3, 3])) assert game.board[Vector([3, 3])] == Color.non
def test_check_fouls_long(two_human_players): game = g.Game(10, 10, 5, two_human_players, True) game.make_turn(Vector([1, 3])) game.make_turn(Vector([0, 0])) game.make_turn(Vector([2, 3])) game.make_turn(Vector([0, 1])) game.make_turn(Vector([3, 3])) game.make_turn(Vector([1, 0])) game.make_turn(Vector([5, 3])) game.make_turn(Vector([1, 1])) game.make_turn(Vector([6, 3])) game.make_turn(Vector([9, 9])) game.make_turn(Vector([4, 3])) assert game.board[Vector([4, 3])] == Color.non
def test_game_cycle_with_bot(bot_and_human_players): game = g.Game(5, 5, 3, bot_and_human_players) game.make_turn(Vector([0, 0])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[0][1] == Color.non: game.make_turn(Vector([0, 1])) else: game.make_turn(Vector([1, 0])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[2][0] == Color.non: game.make_turn(Vector([2, 0])) else: game.make_turn(Vector([1, 1])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[2][2] == Color.non: game.make_turn(Vector([2, 2])) else: game.make_turn(Vector([2, 1])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[0][2] == Color.non: game.make_turn(Vector([0, 2])) elif game.board.map[1][0] == Color.non: game.make_turn(Vector([1, 0])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[2][0] == Color.non: game.make_turn(Vector([2, 0])) elif game.board.map[1][1] == Color.non: game.make_turn(Vector([1, 1])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[1][2] == Color.non: game.make_turn(Vector([1, 2])) elif game.board.map[2][1] == Color.non: game.make_turn(Vector([2, 1])) elif game.board.map[2][2] == Color.non: game.make_turn(Vector([2, 2])) else: assert game.winner == Color.white return else: assert game.winner == Color.white return else: game.make_turn(Vector([1, 1])) game.make_turn(Vector(game.current_player.make_move(game))) if game.board.map[2][2] == Color.non: game.make_turn(Vector([2, 2])) else: game.make_turn(Vector([1, 2])) assert game.winner == Color.black
def test_check_draw(two_human_players): game = g.Game(3, 3, 4, two_human_players) for i in range(game.board.width): for j in range(game.board.height): game.make_turn(Vector([i, j])) assert game.winner == Color.non
def test_sorted_players(test_input, expected): game = g.Game(5, 5, 3, test_input) assert game.players[0].color == expected[0] assert game.players[1].color == expected[1] assert game.players[2].color == expected[2] assert game.current_player.color == expected[0]
def test_game_init_with_human(two_human_players): game = g.Game(5, 5, 3, two_human_players) assert game.players[0].color == Color.black assert game.players[1].color == Color.white
def game(two_human_players): game = g.Game(5, 5, 3, two_human_players) return game