def test_move_with_imitator_capture(self): test1 = bcs.BC_state(BOARD_I_CAPTURE1, 0) goal1 = bcs.BC_state(BOARD_I_CAPTURE2, 1) self.assertTrue(pm.can_move((3, 4), (3, 0), test1, 2)) self.assertFalse(pm.can_move((3, 4), (4, 4), test1, 2)) result_state = pm.move((3, 4), (3, 0), test1, 2) self.assertTrue(result_state == goal1) #print(result_state) print("Move with imitator capture passed.")
def test_move_with_withdrawer_capture(self): test1 = bcs.BC_state(BOARD_W_CAPTURE1, 1) goal1 = bcs.BC_state(BOARD_W_CAPTURE2, 0) self.assertFalse(pm.can_move((4, 4), (2, 0), test1, 5)) self.assertTrue(pm.can_move((4, 4), (3, 5), test1, 5)) result_state = pm.move((4, 4), (3, 5), test1, 5) #print(result_state) self.assertTrue(result_state == goal1) print("Move with withdrawer_capture passed")
def test_moves_with_leaper_capture(self): test1 = bcs.BC_state(BOARD_L_CAPTURE1, 0) goal1 = bcs.BC_state(BOARD_L_CAPTURE2, 1) self.assertFalse(pm.can_move((2, 6), (6, 2), test1, 6)) self.assertTrue(pm.can_move((2, 6), (5, 3), test1, 6)) result_state = pm.move((2, 6), (5, 3), test1, 6) #print(result_state) self.assertTrue(result_state == goal1) print("Moves with leaper capture passed")
def mobility(board, side): enemy = 1 - side moves = 0 #copy = BC.BC_state(board, side) #print(copy) for r in range(8): for c in range(8): piece = board[r][c] if PIECES[piece] != '-' and piece % 2 == side: limit = 8 if PIECES[piece] in ['p', 'P']: limit = 4 for i in range(limit): dest = PM.get_next_space((r, c), i) while dest is not None: dest_piece = board[dest[0]][dest[1]] if PIECES[dest_piece] != '-': if dest_piece % 2 == side: break if PIECES[piece] not in [ 'i', 'I', 'l', 'L', 'k', 'K' ]: if dest_piece % 2 == enemy: break if PM.can_move((r, c), dest, board, i): moves += 1 if PIECES[piece] in ['k', 'K']: break dest = PM.get_next_space(dest, i) #print("\n") #print(moves) #print(copy) return moves
def get_moves(location, state, dir, whoseMove, successors): dest = PM.get_next_space(location, dir) piece = state.board[location[0]][location[1]] enemy = 1 - whoseMove while dest is not None: dest_piece = state.board[dest[0]][dest[1]] if dest_piece != 0 and dest_piece % 2 == whoseMove: break if PIECES[piece] not in ['i', 'I', 'l', 'L', 'k', 'K']: if dest_piece != 0 and dest_piece % 2 == enemy: break if PM.can_move(location, dest, state.board, dir): move = (location, dest, dir) successors.append(move) if piece in ['k', 'K']: break dest = PM.get_next_space(dest, dir) return successors
def get_moves(location, state, dir, whoseMove): successors = [] dest = PM.get_next_space(location, dir) piece = state.board[location[0]][location[1]] enemy = 1 - whoseMove while dest is not None: dest_piece = state.board[[dest[0]]][dest[1]] if dest_piece != 0 and dest_piece % 2 == whoseMove: break if PIECES[piece] not in ['i', 'I', 'l', 'L', 'k','K']: if dest_piece != 0 and dest_piece % 2 == enemy: break if PM.can_move(location, dest, state, dir): #print(location) #print(dest) #print("\n") new_state = PM.move(location, dest, state, dir) successors.append(new_state) dest = PM.get_next_space(dest, dir) if piece in ['k','K']: break #print(dest) #print("\n") return successors