Beispiel #1
0
    def test_find_flips_west(self):
        # Set up move validators for black and white
        board = Board(8)
        board.record_tile(Point(5, 4), 'black')
        board.record_tile(Point(6, 4), 'black')
        board.record_tile(Point(2, 5), 'white')
        board.record_tile(Point(0, 5), 'black')
        flips_w = flipFinder(board.size, board.positions, 'white')
        flips_b = flipFinder(board.size, board.positions, 'black')

        # Test good input (1+ tiles flipped)
        one_flip = flips_b.find_flips_west(Point(5, 3))
        three_flips = flips_w.find_flips_west(Point(7, 4))
        self.assertEqual(one_flip, [Point(4, 3)])
        self.assertEqual(three_flips, [Point(6, 4), Point(5, 4), Point(4, 4)])

        # Test bad input (moves with no valid flips):
        #   1. Hits friendly tile without finding opposing tiles, or
        #   2. Hits edge of board or empty square without finding friendly tile
        #   3. Move is outside the board
        friendly_tile = flips_w.find_flips_west(Point(5, 3))
        empty_space = flips_b.find_flips_west(Point(3, 5))
        edge = flips_w.find_flips_west(Point(1, 5))
        outside = flips_w.find_flips_west(Point(100, 100))
        self.assertEqual(friendly_tile, [])
        self.assertEqual(empty_space, [])
        self.assertEqual(edge, [])
        self.assertEqual(outside, [])
Beispiel #2
0
    def test_is_empty_square(self):
        # Set up a board with various tiles
        board = Board(4)
        board.record_tile(Point(3, 1), 'black')
        board.record_tile(Point(2, 2), 'white')
        board.record_tile(Point(2, 0), 'black')

        # Test for empty and non-empty sauares
        self.assertTrue(board.is_empty_square(Point(0, 2)))
        self.assertTrue(board.is_empty_square(Point(2, 3)))
        self.assertTrue(board.is_empty_square(Point(1, 3)))
        self.assertFalse(board.is_empty_square(Point(3, 1)))
        self.assertFalse(board.is_empty_square(Point(2, 2)))
        self.assertFalse(board.is_empty_square(Point(2, 0)))

        # Test for postions outside of board
        self.assertFalse(board.is_empty_square(Point(5, 0)))
        self.assertFalse(board.is_empty_square(Point(-1, 0)))
        self.assertFalse(board.is_empty_square(Point(0, 4)))
        self.assertFalse(board.is_empty_square(Point(0, -1)))
Beispiel #3
0
    def test_find_flips_all(self):
        # Set up a testable board
        board = Board(8)
        board.record_tile(Point(2, 2), 'white')
        board.record_tile(Point(5, 4), 'black')
        board.record_tile(Point(6, 5), 'black')
        board.record_tile(Point(7, 5), 'white')
        board.record_tile(Point(6, 6), 'white')
        board.record_tile(Point(5, 6), 'black')
        board.record_tile(Point(5, 7), 'black')
        board.record_tile(Point(4, 6), 'black')
        flips_b = flipFinder(board.size, board.positions, 'white')

        # Test good input (a move that results in a variety of flips or lack
        # thereof in each direction)
        test_move = flips_b.find_flips_all(Point(5, 5))
        expected_outcome = [Point(6, 5), Point(4, 4), Point(3, 3)]
        self.assertEqual(test_move, expected_outcome)

        # Test behavior for a move outside of the board
        outside_board_test = flips_b.find_flips_all(Point(100, 100))
        self.assertEqual(outside_board_test, [])
Beispiel #4
0
    def test_record_tile(self):
        board = Board(4)
        # Inputs that result in a tile placement
        board.record_tile(Point(1, 3), 'white')
        board.record_tile(Point(0, 2), 'black')
        board.record_tile(Point(1, 2), 'black')
        # Inputs that don't result in a tile placement
        board.record_tile(Point(4, 3), 'white')
        board.record_tile(Point(1, 1), 'black')
        board.record_tile(Point(-1, 3), 'black')
        board.record_tile(Point(0, 5), 'black')
        board.record_tile(Point(0, -1), 'white')
        board.record_tile(Point(1, 2), 'red')
        expected_output = [[0, 0, 'black', 0], [0, 'black', 'black', 'white'],
                           [0, 'white', 'black', 0], [0, 0, 0, 0]]
        self.assertEqual(board.positions, expected_output)
        self.assertEqual(board.black_tiles, 4)
        self.assertEqual(board.white_tiles, 2)

        board = Board(8)
        # Inputs that result in a tile placement
        board.record_tile(Point(6, 2), 'white')
        board.record_tile(Point(0, 7), 'black')
        board.record_tile(Point(3, 4), 'black')
        # Inputs that don't result in a tile placement
        board.record_tile(Point(3, 3), 'black')
        board.record_tile(Point(8, 3), 'white')
        board.record_tile(Point(-1, 3), 'black')
        board.record_tile(Point(0, 10), 'black')
        board.record_tile(Point(0, -1), 'white')
        board.record_tile(Point(2, 4), 'green')
        expected_output = [[0, 0, 0, 0, 0, 0, 0, 'black'],
                           [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                           [0, 0, 0, 'black', 'black', 0, 0, 0],
                           [0, 0, 0, 'white', 'black', 0, 0, 0],
                           [0, 0, 0, 0, 0, 0, 0, 0],
                           [0, 0, 'white', 0, 0, 0, 0, 0],
                           [0, 0, 0, 0, 0, 0, 0, 0]]
        self.assertEqual(board.positions, expected_output)
        self.assertEqual(board.black_tiles, 4)
        self.assertEqual(board.white_tiles, 2)