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))
def test_push_jump_chain(self): b = Board() b.set_board( ",...,.o.o,.....,.o...o,.......,...o...o,....x....,.o.o,...") b.push(b.legal_moves()[0]) self.assertEqual(",,,,,,,........x.,.o.o......,", b.get_board()) b.pop() self.assertEqual( ",,.o.o......,,.o...o....,,...o...o..,....x.....,.o.o......,", b.get_board()) pass
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())
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
def test_middle(self): # This is correct becuase implementation doesn't actually check if all checkers are on black fields only # (as it's per rules of checkers). bstr = ",,,,...xoxo...,...oxox...,,,," b = Board() b.set_board(bstr) self.assertEqual(bstr, b.get_board())
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
def get_state(move: Move, board: Board): board.push(move) n_our_un_crwn_pices = board.get_board().count(our_pics) n_their_un_crwn_pices = board.get_board().count(their_pics) n_our_king = board.get_board().count(our_kings) n_their_king = board.get_board().count(their_kings) n_pcs_on_edge = get_pics_on_edge(our_pics, our_kings, board) own_center_of_mass = 0 their_center_of_mass = 0 board.pop() return State(n_our_un_crwn_pices, n_their_un_crwn_pices, n_our_king, n_their_king, n_pcs_on_edge, own_center_of_mass, their_center_of_mass)
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
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
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
def test_trimmed1(self): # Notation input can be trimmed from right, however output is not. bstr = ".x.x," b = Board() b.set_board(bstr) self.assertEqual(".x.x......,,,,,,,,,", b.get_board())
def test_default(self): bstr = ".o.o.o.o.o,o.o.o.o.o.,.o.o.o.o.o,o.o.o.o.o.,,,.x.x.x.x.x,x.x.x.x.x.,.x.x.x.x.x,x.x.x.x.x." b = Board() self.assertEqual(bstr, b.get_board())
def test_clear(self): bstr = ".x.x,,,,,,,,,o.o." b = Board() b.set_board(bstr) b.clear_board() self.assertEqual(",,,,,,,,,", b.get_board())
def test_empty(self): bstr = ",,,,,,,,," b = Board() b.set_board(bstr) self.assertEqual(bstr, b.get_board())
def test_trimmed2(self): bstr = ",,,,...x.x.o,o.o.x" b = Board() b.set_board(bstr) self.assertEqual(",,,,...x.x.o..,o.o.x.....,,,,", b.get_board())
def test_simple(self): bstr = ".x.x.x.x.x,x.x.x.x.x.,,,,,,,.o.o.o.o.o,o.o.o.o.o." b = Board() b.set_board(bstr) self.assertEqual(bstr, b.get_board())
def have_we_won(board: Board): board_str = board.get_board() n_we = board_str.count(our_pics) + board_str.count(our_kings) n_they = board_str.count(their_pics) + board_str.count(their_kings) return n_we >= n_they