Exemplo 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))))
Exemplo 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)
Exemplo 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)
Exemplo 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))
Exemplo n.º 5
0
    def placement_move(self, game_uuid, player_name, x, y):
        game = self.load_game(game_uuid)
        player = Player(player_name)
        move = PlacementMove(x, y)

        self.apply_event(game, player, move)
        self._store_game(game, game_uuid)
        return game
Exemplo n.º 6
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
Exemplo n.º 7
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
                 }
             }
         })
Exemplo n.º 8
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))))
Exemplo 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))))
Exemplo 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)))
Exemplo n.º 11
0
 def _init_game(self):
     game = Game()
     game.player_a = Player('bob')
     game.player_b = Player('sam')
     return game
Exemplo n.º 12
0
 def test_from_dict_crappy(self):
     self.assertNotEqual(Player.from_dict({'name': 'sam'}), Player('same'))
Exemplo n.º 13
0
 def test_from_dict(self):
     self.assertEqual(Player.from_dict({'name': 'sam'}), Player('sam'))
Exemplo n.º 14
0
 def test_to_dict(self):
     self.assertEqual(Player('sam').to_dict(), {'name': 'sam'})
Exemplo n.º 15
0
 def join_game(self, game_uuid, player_name):
     game = self.load_game(game_uuid)
     player = Player(player_name)
     game.join_game(player)
     self._store_game(game, game_uuid)
     return game
Exemplo n.º 16
0
 def create_game(self, player_name):
     game = Game()
     game.join_game(Player(player_name))
     game_uuid = self._store_game(game)
     return game_uuid, game