Beispiel #1
0
    def test_game_pick_taken(self):
        game = self._init_game()

        game.apply_event(Event(Player('bob'), PickingMove(Piece(0))))

        game.apply_event(Event(Player('sam'), PlacementMove(0, 0)))

        with self.assertRaises(Exception):
            game.apply_event(Event(Player('sam'), PickingMove(Piece(0))))
Beispiel #2
0
    def test_game_2nd_pick_good(self):
        game = self._init_game()

        game.apply_event(Event(Player('bob'), PickingMove(Piece(0))))

        game.apply_event(Event(Player('sam'), PlacementMove(0, 0)))

        game.apply_event(Event(Player('sam'), PickingMove(Piece(1))))

        self.assertEqual(game.turn, 3)

        self.assertEqual(game.next_piece.value, 1)
Beispiel #3
0
    def test_game_good_move(self):
        game = self._init_game()

        game.apply_event(Event(Player('bob'), PickingMove(Piece(0))))

        self.assertEqual(game.turn, 1)

        self.assertEqual(game.next_piece, Piece(0))
Beispiel #4
0
 def test_to_dict(self):
     self.assertEqual(
         PickingMove(Piece(4)).to_dict(), {
             'type': 'PickingMove',
             'piece': {
                 'value': 4
             }
         })
Beispiel #5
0
    def picking_move(self, game_uuid, player_name, number):
        game = self.load_game(game_uuid)
        player = Player(player_name)
        piece = Piece(number)
        move = PickingMove(piece)

        self.apply_event(game, player, move)
        self._store_game(game, game_uuid)
        return game
Beispiel #6
0
    def test_from_dict(self):
        picking_move = PickingMove.from_dict({
            'type': 'PickingMove',
            'piece': {
                'value': 5
            }
        })

        self.assertEqual(picking_move.piece.value, 5)
Beispiel #7
0
    def test_game_good_placement(self):
        game = self._init_game()

        game.apply_event(Event(Player('bob'), PickingMove(Piece(0))))

        game.apply_event(Event(Player('sam'), PlacementMove(0, 0)))

        self.assertEqual(game.turn, 2)

        self.assertEqual(game.next_piece, None)
Beispiel #8
0
 def test_to_dict(self):
     self.assertEqual(
         Event(Player('bob'), PickingMove(Piece(2))).to_dict(), {
             'player': {
                 'name': 'bob'
             },
             'move': {
                 'type': 'PickingMove',
                 'piece': {
                     'value': 2
                 }
             }
         })
Beispiel #9
0
    def test_game_victory_for_bob(self):
        game = self._init_game()

        game.apply_event(Event(Player('bob'), PickingMove(Piece(0))))

        game.apply_event(Event(Player('sam'), PlacementMove(0, 0)))

        game.apply_event(Event(Player('sam'), PickingMove(Piece(1))))

        game.apply_event(Event(Player('bob'), PlacementMove(0, 1)))

        game.apply_event(Event(Player('bob'), PickingMove(Piece(2))))

        game.apply_event(Event(Player('sam'), PlacementMove(0, 2)))

        game.apply_event(Event(Player('sam'), PickingMove(Piece(3))))

        self.assertEqual(game.winner, None)
        game.apply_event(Event(Player('bob'), PlacementMove(0, 3)))
        self.assertEqual(game.winner, Player('bob'))
        with self.assertRaises(Exception):
            game.apply_event(Event(Player('bob'), PickingMove(Piece(4))))
Beispiel #10
0
 def test_game_bad_player(self):
     game = self._init_game()
     with self.assertRaises(Exception):
         game.apply_event(Event(Player('sam'), PickingMove(Piece(1))))