Пример #1
0
    def test28aPlayIsOnlyAppliedWhenThePieceMovedIsFromTheOwner(self):
        aChessBoard = NewGameChessBoard()

        whitePlayer = Player(aChessBoard.whitePieces())
        blackPlayer = Player(aChessBoard.blackPieces())

        aWhitePawn = aChessBoard.pieceAt(aRow=1, aColumn=0)
        aMovement = Movement(anInitialRow=1,
                             anInitialColumn=0,
                             aNewRow=3,
                             aNewColumn=0)
        aPlay = Play(aPiece=aWhitePawn, aMovement=aMovement)
        aChessBoard.applyAPlay(aPlay)
        whitePlayer._assertPlayIsValid(aPlay)
        with self.assertRaises(Exception):
            blackPlayer._assertPlayIsValid(aPlay)

        aBlackPawn = aChessBoard.pieceAt(aRow=6, aColumn=1)
        aMovement = Movement(anInitialRow=6,
                             anInitialColumn=1,
                             aNewRow=4,
                             aNewColumn=1)
        aPlay = Play(aPiece=aBlackPawn, aMovement=aMovement)
        blackPlayer._assertPlayIsValid(aPlay)
        with self.assertRaises(Exception):
            whitePlayer._assertPlayIsValid(aPlay)
Пример #2
0
def human_input_selection_screen_handler(interface_items, players,
                                         mouse_position):
    """
    Captures the user input during the selection screen, initializes the player class instances depending on the user's
    selection on and append them into the players list.

    :param interface_items: type: dict
    Dictionary containing all of the user interface (UI) items to be displayed. From this dict, we can find the
    references for the objects that the user selects

    :param players: type: list
    Starts off as an empty list, used to contain the initialized players when the user selects a mark

    :param mouse_position: type: tuple
    Tuple of the X & Y coordinates of the mouse cursor on the pygame window
    """
    if interface_items['x_sign'].is_mouse_hover(
            mouse_position) or interface_items['x_label'].is_mouse_hover(
                mouse_position):
        # Create players
        bot = Player(bot=True, state=BOT_STATE, mark="O")
        human = Player(bot=False, state=HUMAN_STATE, mark="X")
        players.append(bot)
        players.append(human)

    elif interface_items['o_sign'].is_mouse_hover(
            mouse_position) or interface_items['o_label'].is_mouse_hover(
                mouse_position):
        # Create players
        bot = Player(bot=True, state=BOT_STATE, mark="X")
        human = Player(bot=False, state=HUMAN_STATE, mark="O")
        players.append(bot)
        players.append(human)
Пример #3
0
    def test_update_position(self):
        chloe = Player("Chloe", 1234)
        lucien = Player("Lucien", 5678)
        gildas = Player("Gildas", 9000)
        board = Board()

        board.boxes[0].players.append(1234)
        chloe.update_position([3, 4], board)
        self.assertEqual(7, chloe.position)
        self.assertNotIn(1234, board.boxes[0].players)
        self.assertIn(1234, board.boxes[7].players)
        chloe.update_position([35, 0], board)
        self.assertEqual(2, chloe.position)
        self.assertNotIn(1234, board.boxes[7].players)
        self.assertIn(1234, board.boxes[2].players)
        self.assertEqual(INITIAL_MONEY + 200, chloe.money)

        board.boxes[2].players.append(5678)
        lucien.position = 2
        lucien.update_position([-3], board)
        self.assertEqual(39, lucien.position)
        self.assertNotIn(5678, board.boxes[2].players)
        self.assertIn(5678, board.boxes[39].players)
        self.assertEqual(INITIAL_MONEY, lucien.money)

        board.boxes[3].players.append(9000)
        gildas.position = 3
        gildas.update_position([-3], board)
        self.assertEqual(0, gildas.position)
        self.assertNotIn(9000, board.boxes[3].players)
        self.assertIn(9000, board.boxes[0].players)
        self.assertEqual(INITIAL_MONEY + 200, gildas.money)
Пример #4
0
 def test_create_4x4_board(self):
     player1 = Player(name="test1", symbol="o")
     player2 = Player(name="test2", symbol="x")
     self.board = Board(player1, player2, 4)
     self.assertEqual(self.board.grid_map,
                      [['1', '2', '3', '4'], ['5', '6', '7', '8'],
                       ['9', '10', '11', '12'], ['13', '14', '15', '16']])
Пример #5
0
 def __init__(self, snakes, apples, speed, autoplay):
     if getattr(sys, 'frozen', False):
         CurrentPath = sys._MEIPASS
     else:
         CurrentPath = os.path.dirname(__file__)
     self.speed = speed
     self.window = Window()
     self.apples = Apples(apples)
     self.go = False
     self.goCount = 0
     fontFile = os.path.join(CurrentPath, "freesansbold.ttf")
     if not os.path.exists(fontFile):
         fontFile = "freesansbold.ttf"
     self.font = pygame.font.Font(fontFile, 240)
     self.font.set_bold(True)
     self.fontSmall = pygame.font.Font(fontFile, 120)
     self.fontSmall.set_bold(True)
     self.textSurf = None
     self.end = False
     self.startPlayers = snakes
     self.players = []
     self.players.append(Player(window = self.window, apples = self.apples, players = self.players, ki = bool(autoplay)))
     for i in range(snakes - 1):
         self.players.append(Player(color = (randint(0, 255), randint(0, 255), randint(0, 255)) ,window = self.window, apples = self.apples, players = self.players, ki = True))
     self.loop()
Пример #6
0
    def __init__(self):
        self.high = np.array([1.1, 1.1, 0.85, 1.03, 1.03])
        self.low = np.array([-1.1, -1.1, -0.01, -0.04, -0.04])

        self.WIDTH = world_settings["WIDTH"]
        self.HEIGHT = world_settings["HEIGHT"]

        self.display_render = False
        self.game_over = False

        self.player = Player(
            self,
            random.randint(0, self.WIDTH -
                           player_setting["width"]),  #Randon position x 
            self.HEIGHT - player_setting["height"] -
            player_setting["padding"],  #position bottom
        )
        self.autoplayer = Player(
            self,
            random.randint(0, self.WIDTH -
                           player_setting["width"]),  #Randon position x 
            player_setting["height"] -
            player_setting["padding"],  #position top
        )
        self.ball = Ball(
            self,
            random.randint(16, self.WIDTH - 16),
            self.HEIGHT / 2 - 8,
            [self.player, self.autoplayer]  #Interact with
        )
        self.clock = pg.time.Clock()
Пример #7
0
def test_play(game_factory, faker):
    lobby = Lobby()

    player1 = Player(faker.pystr(), faker.name())
    player2 = Player(faker.pystr(), faker.name())

    lobby.register_player(player1)
    lobby.register_player(player2)

    char1 = lobby.create_character()
    char2 = lobby.create_character()

    lobby.assign_character(player1, char1)
    lobby.assign_character(player2, char2)

    game = lobby.start_game(Grid(20, 20))

    char1.spawn(game.grid, (1, 1), Direction.DOWN)
    char2.spawn(game.grid, (1, 2), Direction.UP)

    with pytest.raises(ActionNotAllowedError):
        game.action(char1, ActionType.STEP, step=Step.FORWARD)

    game.action(char1, ActionType.TURN, turn=Turn.LEFT)
    game.action(char1, ActionType.STEP, step=Step.FORWARD)
    game.action(char1, ActionType.STEP, step=Step.FORWARD)
    game.action(char1, ActionType.TURN, turn=Turn.LEFT)

    assert game.turn_manager.current_character() == char2
    assert game.characters[char1.char_id].address == (3, 1)
    assert game.characters[char1.char_id].direction == Direction.UP
Пример #8
0
 def test_pay_player(self):
     chloe = Player("Chloe", 0)
     lucien = Player("Lucien", 1)
     amount = 1000
     chloe.pay_player(lucien, amount)
     self.assertEqual(INITIAL_MONEY - amount, chloe.money)
     self.assertEqual(INITIAL_MONEY + amount, lucien.money)
Пример #9
0
 def __init__(self, seed):
     self.random = Random(seed)
     self.lanes = [Lane(self), Lane(self), Lane(self)]
     self.players = [Player(0, self.lanes), Player(1, self.lanes)]
     self.current_lane, self.current_player = 0, 0
     self.pass_lane = 0
     self.initialize_game()
     pass
def test_card_validation():
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        Player(cards=[1])
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        cards = index.serialize_cards(make_cards([1, 2]))
        Player(cards=cards)
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        Player(cards=Card(1))
Пример #11
0
 def test_acid_bath_multi(self):
     test = Room(RoomType.acid_bath, False)
     player = Player()
     event = test.on_room_enter(
         [], player,
         [player, Player(), Player(), Player()])
     self.assertEqual(player.current_room, test)
     self.assertEqual([], event)
Пример #12
0
 def new_player(self, *args):
     p = None
     if len(self.players) == 0:
         p = self.owner = Player(0, *args)
     else:
         p = Player(len(self.players), *args)
     self.players.append(p)
     return p
Пример #13
0
    def test03AGameStartsWithaChessBoardThatHas32Pieces(self):
        aChessBoard = NewGameChessBoard()
        twoPlayers = [
            Player(aChessBoard.whitePieces()),
            Player(aChessBoard.blackPieces())
        ]
        aChessGame = ChessGame(aChessBoard, twoPlayers[0], twoPlayers[1])

        self.assertTrue(len(aChessGame.board().pieces()) is 32)
Пример #14
0
 def test_acid_bath_two_same_room(self):
     test = Room(RoomType.acid_bath, False)
     player = Player()
     player2 = Player()
     players = [player, Player(), player2, Player()]
     test.on_room_enter([], player2, players)
     event = test.on_room_enter([], player, players)[0]
     self.assertEqual(player.current_room, test)
     self.assertEqual(RoomEvent(RoomEventType.player_death, player2), event)
Пример #15
0
    def test01AGameHasAChessBoard(self):
        aChessBoard = NewGameChessBoard()
        twoPlayers = [
            Player(aChessBoard.whitePieces()),
            Player(aChessBoard.blackPieces())
        ]
        aChessGame = ChessGame(aChessBoard, twoPlayers[0], twoPlayers[1])

        self.assertIsInstance(aChessGame.board(), ChessBoard)
Пример #16
0
    def test_player_input(self):
        player1 = Player(name="test1", symbol="o")
        player2 = Player(name="test2", symbol="x")
        self.board = Board(player1, player2)

        with mock.patch('builtins.input', return_value="1"):
            player1.input_move(self.board)
        new_grid_map = [['o', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
        self.assertEqual(self.board.grid_map, new_grid_map)
Пример #17
0
 def setUp(self) -> None:
     ball = Ball(pong.config.white, 10)
     engine = ComputerControlEngine(ball)
     self.left_player = Player('left', 'left', engine)
     self.right_player = Player('right', 'right', engine)
     self.score_manager = ScoreManager(self.left_player, self.right_player,
                                       (1, 5))
     self.score_board = ScoreBoard(self.score_manager)
     self.scene = Scene(Window(100, 100, 'Test'))
Пример #18
0
 def __init__(self, on_player_moves_executed: Optional[Callable] = None):
     self.on_player_moves_executed = on_player_moves_executed
     self.board = Board()
     self.player_1 = Player(PLAYER_1_ID, self.board, self)
     self.player_2 = Player(PLAYER_2_ID, self.board, self)
     self.starting_player = self.player_1
     self.first_move_executed = False
     self.player_moves = {PLAYER_1_ID: list(), PLAYER_2_ID: list()}
     self.turns = 0
     self.result: GameResult = None
Пример #19
0
    def setUp(self):
        start_pos = (1, 2)
        self.knight = Player("Knightsebbe", "knight", start_pos)
        self.wizard = Player("wizSeb", "wizard", start_pos)
        self.thief = Player("thiefSeb", "thief", start_pos)

        self.dungeon = Map(4)

        self.char = Player("Bob", "knight", self.dungeon.get_room(1, 1))
        self.char2 = Player("Bob", "knight", self.dungeon.get_room(0, 1))
Пример #20
0
    def setUp(self):
        self.player1 = Player("Player 1")
        self.player2 = Player("Player 2")

        self.edges, self.city_edges = self.create_test_board()
        self.deck, self.destinations = self.create_test_deck()

        self.game = Game([self.player1, self.player2], custom_settings=True, edges=self.edges,
                         city_edges=self.city_edges, deck=self.deck, num_cars=12,
                         destinations=self.destinations)
Пример #21
0
    def test_constructor(self):
        pe = Player(name='Explanee')
        pg = Player(name='Guessee')
        t = Turn(explaining=pe, guessing=pg)

        assert t.guessing == pg
        assert t.explaining == pe
        assert type(t.missed_words) == list
        assert len(t.missed_words) == 0
        assert t.result() == 0
        assert t.word is None
def test_cards():
    # No cards should make empty list
    assert Player().cards == []
    assert Dealer().cards == []

    # Provided cards should be set on player
    actual_cards = make_cards([4, 5])
    player = Player(cards=actual_cards)
    dealer = Dealer(cards=actual_cards)
    assert player.cards == actual_cards
    assert dealer.cards == actual_cards
Пример #23
0
    def test_render_two_player_moves(self):
        self.game_board.make_player_move(0, 0, Player('Player1', 'X'))
        self.game_board.make_player_move(1, 1, Player('Player2', 'O'))

        render_result = self.game_board.render()

        self.assertEqual(render_result,
                         "    A   B   C   \n"
                         "1 | X | - | - | \n"
                         "2 | - | O | - | \n"
                         "3 | - | - | - | \n")
Пример #24
0
 def test_get_number_of_stations(self):
     chloe = Player("Chloe", 0)
     lucien = Player("Lucien", 1)
     gildas = Player("Gildas", 2)
     board = Board()
     chloe.buy_good(board.boxes[5])
     chloe.buy_good(board.boxes[15])
     lucien.buy_good(board.boxes[25])
     self.assertEqual(2, chloe.get_number_of_stations())
     self.assertEqual(1, lucien.get_number_of_stations())
     self.assertEqual(0, gildas.get_number_of_stations())
Пример #25
0
    def test21aGameHasTwoPlayers(self):
        aChessBoard = NewGameChessBoard()
        twoPlayers = [
            Player(aChessBoard.whitePieces()),
            Player(aChessBoard.blackPieces())
        ]
        aChessGame = ChessGame(aChessBoard, twoPlayers[0], twoPlayers[1])
        players = aChessGame.players()

        self.assertTrue(len(players) == 2)
        self.assertIsInstance(players[0], Player)
        self.assertIsInstance(players[1], Player)
Пример #26
0
    def test02AGameHasAChessBoardWithPieces(self):
        aChessBoard = NewGameChessBoard()
        twoPlayers = [
            Player(aChessBoard.whitePieces()),
            Player(aChessBoard.blackPieces())
        ]
        aChessGame = ChessGame(aChessBoard, twoPlayers[0], twoPlayers[1])

        self.assertIsInstance(aChessGame.board().pieces(), list)

        for piece in aChessGame.board().pieces():
            self.assertIsInstance(piece, Piece)
Пример #27
0
 def test_backwards(self):
     chloe = Player("Chloe", 0)
     lucien = Player("Lucien", 1)
     board = Board()
     board.boxes[3].players.append(0)
     chloe.position = 3
     board.boxes[20].players.append(1)
     lucien.position = 20
     card = Card(card_id="666", name="", card_type="backwards", value=4)
     card.execute(chloe, None, board)
     card.execute(lucien, None, board)
     self.assertEqual(39, chloe.position)
     self.assertEqual(16, lucien.position)
Пример #28
0
def spawn_players(players, bullets, explosions, player_1_id, start_location_1,
                  player_control_scheme_1, power_gauge_1, player_2_id,
                  start_location_2, player_control_scheme_2, power_gauge_2,
                  player_lives):
    players[:] = []
    bullets[:] = []
    explosions[:] = []
    players.append(
        Player(player_1_id, start_location_1, player_control_scheme_1,
               power_gauge_1, player_lives, PowerUps()))
    players.append(
        Player(player_2_id, start_location_2, player_control_scheme_2,
               power_gauge_2, player_lives, PowerUps()))
Пример #29
0
    def test_is_sorted_by_test_hand(self):
        mock_hand1 = MagicMock()
        mock_hand1.best_rank.return_value = [0, "Royal Flush", []]

        mock_hand2 = MagicMock()
        mock_hand2.best_rank.return_value = [2, "Four of a Kind", []]

        player1 = Player(name="Axl", hand=mock_hand1)
        player2 = Player(name="Brick", hand=mock_hand2)

        players = [player1, player2]

        self.assertEqual(max(players), player1)
Пример #30
0
 def test_can_buy_good(self):
     chloe = Player("Chloe", 0, money=300)
     lucien = Player("Lucien", 1)
     board = Board()
     chloe.buy_good(board.boxes[3])
     lucien.buy_good(board.boxes[9])
     self.assertTrue(chloe.can_buy_good(board.boxes[1]))
     self.assertTrue(chloe.can_buy_good(board.boxes[5]))
     self.assertTrue(chloe.can_buy_good(board.boxes[12]))
     self.assertFalse(chloe.can_buy_good(board.boxes[2]))  # not a good
     self.assertFalse(chloe.can_buy_good(board.boxes[3]))  # chloe is owner
     self.assertFalse(chloe.can_buy_good(board.boxes[9]))  # lucien is owner
     self.assertFalse(chloe.can_buy_good(
         board.boxes[39]))  # not enough money