Пример #1
0
 def test_jump_crowning(self):
     b = Board()
     b.set_board("...,...o,....x")
     b.push(b.legal_moves()[0])
     self.assertEqual("..X.......,,,,,,,,,", b.get_board())
     self.assertEqual(Checker(WHITE, True), b.checker_at(2, 0))
     b.pop()
     self.assertEqual(",...o......,....x.....,,,,,,,", b.get_board())
     self.assertEqual(Checker(WHITE, False), b.checker_at(4, 2))
Пример #2
0
 def test_two_double_jumps(self):
     b = Board()
     b.set_board(",...o.o,,...o,..x")
     self.assertEqual(
         "[[Move<x,f(2, 4),t(4, 2)>, Move<x,f(4, 2),t(2, 0)>], "
         "[Move<x,f(2, 4),t(4, 2)>, Move<x,f(4, 2),t(6, 0)>]]",
         str(b.legal_moves()))
     self.assertIsNotNone(b.checker_at(3, 3))
     self.assertIsNotNone(b.checker_at(3, 1))
     self.assertIsNotNone(b.checker_at(5, 1))
Пример #3
0
 def test_push_chain_no_crowning(self):
     b = Board()
     b.set_board(",......o.o.,,....o.....,...x......")
     b.push(b.legal_moves()[0])
     self.assertIsNotNone(b.checker_at(9, 2))
     self.assertFalse(b.checker_at(9, 2).crowned)
     b.pop()
     self.assertEqual(",......o.o.,,....o.....,...x......,,,,,",
                      b.get_board())
     self.assertIsNone(b.checker_at(9, 2))
     self.assertFalse(b.checker_at(3, 4).crowned)
     pass
Пример #4
0
 def test_promotion_pop(self):
     b = Board()
     b.set_board(",x")
     b.push(b.legal_moves()[0])
     chk = Checker(WHITE, True)
     self.assertTrue(b.move_stack[-1][-1].is_promotion)
     self.assertEqual(b.checker_at(1, 0), chk)
     b.push([Move(chk, (1, 0), (5, 4))])
     self.assertEqual(b.checker_at(5, 4), chk)
     b.pop()
     self.assertEqual(b.checker_at(1, 0), Checker(WHITE, True))
     b.pop()
     self.assertEqual(b.checker_at(0, 1), Checker(WHITE, False))
Пример #5
0
 def test_push_chain_crowning(self):
     # crowning can only happen if chain ended at the proper place (crowning can't happen in the middle of the chain)
     b = Board()
     b.set_board(",......o...,,....o.....,...x......")
     b.push(b.legal_moves()[0])
     self.assertIsNotNone(b.checker_at(7, 0))
     self.assertTrue(b.checker_at(7, 0).crowned)
     b.pop()
     self.assertEqual(",......o...,,....o.....,...x......,,,,,",
                      b.get_board())
     self.assertIsNone(b.checker_at(7, 0))
     self.assertFalse(b.checker_at(3, 4).crowned)
     pass
Пример #6
0
    def test_complicated_circle_chain(self):
        b = Board()
        b.set_board(",.o.o.o....,,.o.o......,..x")

        ch1 = "[Move<x,f(2, 4),t(0, 2)>, Move<x,f(0, 2),t(2, 0)>, Move<x,f(2, 0),t(4, 2)>, Move<x,f(4, 2),t(2, 4)>]"
        ch2 = "[Move<x,f(2, 4),t(0, 2)>, Move<x,f(0, 2),t(2, 0)>, Move<x,f(2, 0),t(4, 2)>, Move<x,f(4, 2),t(6, 0)>]"
        ch3 = "[Move<x,f(2, 4),t(4, 2)>, Move<x,f(4, 2),t(2, 0)>, Move<x,f(2, 0),t(0, 2)>, Move<x,f(0, 2),t(2, 4)>]"

        self.assertEqual("[" + ch1 + ", " + ch2 + ", " + ch3 + "]",
                         str(b.legal_moves()))
        self.assertIsNotNone(b.checker_at(1, 3))
        self.assertIsNotNone(b.checker_at(3, 3))
        self.assertIsNotNone(b.checker_at(1, 1))
        self.assertIsNotNone(b.checker_at(3, 1))
        self.assertIsNotNone(b.checker_at(5, 1))
Пример #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
Пример #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
Пример #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))
Пример #10
0
 def test_jump_white(self):
     b = Board()
     b.set_board(",,....o,...x")
     self.assertEqual("[[Move<x,f(3, 3),t(5, 1)>]]", str(b.legal_moves()))
     self.assertIsNotNone(b.checker_at(4, 2))