Exemplo n.º 1
0
 def test_move_black(self):
     b = Board()
     b.set_board(",,....o")
     b.color = checkers.BLACK
     self.assertEqual(
         "[[Move<o,f(4, 2),t(3, 3)>], [Move<o,f(4, 2),t(5, 3)>]]",
         str(b.legal_moves()))
Exemplo n.º 2
0
 def test2(self):
     b = Board()
     b.set_board(",.o........,,.o........,,,,,........x.,")
     b.color = False
     moves = str(b.legal_moves())
     self.assertEqual(
         moves, "[[Move<o,f(1, 1),t(0, 2)>], [Move<o,f(1, 1),t(2, 2)>], "
         "[Move<o,f(1, 3),t(0, 4)>], [Move<o,f(1, 3),t(2, 4)>]]")
Exemplo n.º 3
0
 def test_move_king_black_blocked(self):
     b = Board()
     b.set_board(",,.....O....,,...o......,........o.")
     b.color = checkers.BLACK
     self.assertEqual(
         "[[Move<O,f(5, 2),t(4, 1)>], [Move<O,f(5, 2),t(3, 0)>], [Move<O,f(5, 2),t(6, 1)>], "
         "[Move<O,f(5, 2),t(7, 0)>], [Move<O,f(5, 2),t(4, 3)>], [Move<O,f(5, 2),t(6, 3)>], "
         "[Move<O,f(5, 2),t(7, 4)>], [Move<o,f(3, 4),t(2, 5)>], [Move<o,f(3, 4),t(4, 5)>], "
         "[Move<o,f(8, 5),t(7, 6)>], [Move<o,f(8, 5),t(9, 6)>]]",
         str(b.legal_moves()))
Exemplo n.º 4
0
 def test_push_jump_chain_end_on_jumped(self):
     b = Board()
     b.set_board(
         ",,,,,....x.x...,.x.x......,......x.x.,.x........,..O.......")
     b.color = BLACK
     print(b.legal_moves()[0])
     b.push(b.legal_moves()[0])
     self.assertEqual(",,,,,,...O......,,,", b.get_board())
     b.pop()
     self.assertEqual(
         ",,,,,....x.x...,.x.x......,......x.x.,.x........,..O.......",
         b.get_board())
Exemplo n.º 5
0
    def test_push_simple(self):
        b = Board()
        b.set_board(",,,,,,.x........,,,")
        b.push(b.legal_moves()[0])
        self.assertEqual(",,,,,x.........,,,,", b.get_board())
        b.pop()
        self.assertEqual(",,,,,,.x........,,,", b.get_board())

        b = Board()
        b.set_board(",,....o.....,,,,,,,")
        b.color = checkers.BLACK
        b.push(b.legal_moves()[0])
        self.assertEqual(",,,...o......,,,,,,", b.get_board())
        b.pop()
        self.assertEqual(",,....o.....,,,,,,,", b.get_board())
        pass
Exemplo n.º 6
0
 def test_move_king_black_corner(self):
     b = Board()
     b.set_board(",,,,,,,,,.........O")
     b.color = BLACK
     bc = Checker(BLACK, True)
     self.assertCountEqual([
         [Move(bc, (9, 9), (8, 8))],
         [Move(bc, (9, 9), (7, 7))],
         [Move(bc, (9, 9), (6, 6))],
         [Move(bc, (9, 9), (5, 5))],
         [Move(bc, (9, 9), (4, 4))],
         [Move(bc, (9, 9), (3, 3))],
         [Move(bc, (9, 9), (2, 2))],
         [Move(bc, (9, 9), (1, 1))],
         [Move(bc, (9, 9), (0, 0))],
     ], b.legal_moves())
Exemplo n.º 7
0
    def test_push_crowning(self):
        b = Board()
        b.set_board(",.x")
        b.push(b.legal_moves()[1])
        self.assertEqual("..X.......,,,,,,,,,", b.get_board())
        self.assertTrue(b.checker_at(2, 0).crowned)

        b = Board()
        b.set_board(",,,,,,,,....o,")
        b.color = False
        b.push(b.legal_moves()[0])
        self.assertEqual(",,,,,,,,,...O......", b.get_board())
        self.assertTrue(b.checker_at(3, 9).crowned)
        b.pop()
        self.assertEqual(",,,,,,,,....o.....,", b.get_board())
        self.assertFalse(b.checker_at(4, 8).crowned)
        pass
Exemplo n.º 8
0
    def test_push_jump(self):
        b = Board()
        b.set_board(",,....o,...x")
        b.push(b.legal_moves()[0])
        self.assertIsNone(b.checker_at(4, 2))
        self.assertEqual(",.....x....,,,,,,,,", b.get_board())
        b.pop()
        self.assertIsNotNone(b.checker_at(4, 2))
        self.assertEqual(",,....o.....,...x......,,,,,,", b.get_board())

        b = Board()
        b.set_board(",,,,......x...,.....o....,,,,")
        b.color = checkers.BLACK
        b.push(b.legal_moves()[0])
        self.assertIsNone(b.checker_at(6, 4))
        self.assertEqual(",,,.......o..,,,,,,", b.get_board())
        b.pop()
        self.assertIsNotNone(b.checker_at(6, 4))
        self.assertEqual(",,,,......x...,.....o....,,,,", b.get_board())
        pass
Exemplo n.º 9
0
 def test_jump_black(self):
     b = Board()
     b.set_board(",,,,......x,.....o")
     b.color = checkers.BLACK
     self.assertEqual("[[Move<o,f(5, 5),t(7, 3)>]]", str(b.legal_moves()))
     self.assertIsNotNone(b.checker_at(6, 4))