コード例 #1
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))
コード例 #2
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))))
コード例 #3
0
 def test_check_no_win_horizontal(self):
     game = Game()
     a = Piece.from_attributes(True, True, False, True)
     b = Piece.from_attributes(True, False, False, True)
     c = Piece.from_attributes(False, True, False, False)
     d = Piece.from_attributes(True, False, True, False)
     game.board.put(a, 0, 0)
     game.board.put(b, 1, 0)
     game.board.put(c, 2, 0)
     game.board.put(d, 3, 0)
     self.assertEqual(game.check_win(0, 0), False)
コード例 #4
0
    def test_check_win_negative_diagonal(self):
        game = Game()
        a = Piece.from_attributes(True, True, False, True)
        b = Piece.from_attributes(True, False, False, True)
        c = Piece.from_attributes(True, True, False, False)
        d = Piece.from_attributes(True, False, True, False)

        game.board.put(a, 0, 3)
        game.board.put(b, 1, 2)
        game.board.put(c, 2, 1)
        game.board.put(d, 3, 0)
        self.assertEqual(game.check_win(0, 3), True)
コード例 #5
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)
コード例 #6
0
    def test_check_win_vertical(self):
        game = Game()
        a = Piece.from_attributes(True, True, False, True)
        b = Piece.from_attributes(True, False, False, True)
        c = Piece.from_attributes(True, True, False, False)
        d = Piece.from_attributes(True, False, True, False)

        game.board.put(a, 0, 0)
        game.board.put(b, 0, 1)
        game.board.put(c, 0, 2)
        game.board.put(d, 0, 3)
        self.assertEqual(game.check_win(0, 0), True)
コード例 #7
0
    def test_creation_with_positive_attributes(self):
        standard_piece = Piece.from_attributes(True)
        self.assertEqual(standard_piece.value, 1)

        standard_piece = Piece.from_attributes(True, True)
        self.assertEqual(standard_piece.value, 3)

        standard_piece = Piece.from_attributes(True, True, True, True)
        self.assertEqual(standard_piece.value, 15)

        standard_piece = Piece.from_attributes(True, False, True, True)
        self.assertEqual(standard_piece.value, 13)

        standard_piece = Piece.from_attributes(True, False, False, True)
        self.assertEqual(standard_piece.value, 9)
コード例 #8
0
    def test_full_overlap(self):
        pieces = []
        for black in (True, False):
            for tall in (True, False):
                for hole in (True, False):
                    for square in (True, False):
                        pieces.append(
                            Piece.from_attributes(black, tall, hole, square))
        for piece in pieces:
            overlaps = 0
            for other_piece in pieces:
                if piece == other_piece:
                    continue
                if Piece.overlap(piece, other_piece):
                    overlaps += 1

            self.assertEqual(overlaps, 14)
コード例 #9
0
 def test_to_dict(self):
     self.assertEqual(
         PickingMove(Piece(4)).to_dict(), {
             'type': 'PickingMove',
             'piece': {
                 'value': 4
             }
         })
コード例 #10
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
コード例 #11
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)
コード例 #12
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))))
コード例 #13
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
                 }
             }
         })
コード例 #14
0
 def test_game_bad_player(self):
     game = self._init_game()
     with self.assertRaises(Exception):
         game.apply_event(Event(Player('sam'), PickingMove(Piece(1))))
コード例 #15
0
 def test_from_dict(self):
     self.assertEqual(Piece.from_dict({'value': 5}), Piece(5))
コード例 #16
0
 def test_to_dict(self):
     self.assertEqual(Piece(5).to_dict(), {'value': 5})
コード例 #17
0
 def test_no_overlap(self):
     a = Piece.from_attributes(True, True, False, True)
     b = Piece.from_attributes(True, False, True, True)
     c = Piece.from_attributes(False, True, False, False)
     d = Piece.from_attributes(True, False, False, False)
     self.assertFalse(Piece.overlap(a, b, c, d))
コード例 #18
0
 def test_piece_overlap(self):
     standard_piece = Piece.from_attributes()
     opposite_piece = Piece.from_attributes(True, True, False, True)
     self.assertTrue(Piece.overlap(standard_piece, opposite_piece))
コード例 #19
0
 def test_creation(self):
     standard_piece = Piece.from_attributes()
     self.assertEqual(standard_piece.value, 0)
コード例 #20
0
 def test_put_simple(self):
     board = Board(2)
     piece = Piece.from_attributes(True, False)
     board.put(piece, 1, 1)
     with self.assertRaises(Exception):
         board.put(piece, 1, 1)