Ejemplo n.º 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))))
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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))
Ejemplo n.º 5
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
                 }
             }
         })
Ejemplo n.º 6
0
    def test_from_dict(self):
        event = Event.from_dict({
            'player': {
                'name': 'bob'
            },
            'move': {
                'type': 'PickingMove',
                'piece': {
                    'value': 2
                }
            }
        })

        self.assertEqual(event.player.name, 'bob')
        self.assertIsInstance(event.move, PickingMove)
        self.assertEqual(event.move.piece.value, 2)
Ejemplo n.º 7
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))))
Ejemplo n.º 8
0
    def test_placement_move(self):
        event_dict = {
            'player': {
                'name': 'bob'
            },
            'move': {
                'type': 'PlacementMove',
                'x': 5,
                'y': 1
            }
        }
        event = Event.from_dict(event_dict)

        self.assertEqual(event.player.name, 'bob')
        self.assertIsInstance(event.move, PlacementMove)
        self.assertEqual(event.move.x, 5)
        self.assertEqual(event.move.y, 1)

        self.assertEqual(event.to_dict(), event_dict)
Ejemplo n.º 9
0
 def test_game_bad_player(self):
     game = self._init_game()
     with self.assertRaises(Exception):
         game.apply_event(Event(Player('sam'), PickingMove(Piece(1))))
Ejemplo n.º 10
0
 def test_game_bad_move(self):
     game = self._init_game()
     with self.assertRaises(Exception):
         game.apply_event(Event(Player('bob'), PlacementMove(0, 1)))
Ejemplo n.º 11
0
 def apply_event(self, game, player, move):
     event = Event(player, move)
     game.apply_event(event)