Example #1
0
    def test_game_2nd_move_taken(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))))

        with self.assertRaises(Exception):
            game.apply_event(Event(Player('bob'), PlacementMove(0, 0)))
Example #2
0
    def test_game_2nd_move_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))))

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

        self.assertEqual(game.turn, 4)

        self.assertEqual(game.next_piece, None)
Example #3
0
 def test_to_dict(self):
     self.assertEqual(
         PlacementMove(1, 2).to_dict(), {
             'type': 'PlacementMove',
             'x': 1,
             'y': 2
         })
Example #4
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
Example #5
0
 def test_from_dict(self):
     placement_move = PlacementMove.from_dict({
         'x': 1,
         'y': 2,
         'type': 'PlacementMove'
     })
     self.assertEqual(placement_move.x, 1)
     self.assertEqual(placement_move.y, 2)
Example #6
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))))
Example #7
0
 def test_game_bad_move(self):
     game = self._init_game()
     with self.assertRaises(Exception):
         game.apply_event(Event(Player('bob'), PlacementMove(0, 1)))