def test_king_in_check(self): test1 = bcs.BC_state(BOARD1K, 0) result = pm.is_king_in_check(test1.board, (0, 4), 0) self.assertTrue(result == True) test2 = bcs.BC_state(BOARD2K, 0) result = pm.is_king_in_check(test2.board, (1, 3), 0) self.assertTrue(result == True) test3 = bcs.BC_state(BOARD3K, 0) result = pm.is_king_in_check(test3.board, (2, 4), 0) self.assertTrue(result == True) test4 = bcs.BC_state(BOARD1P, 0) result = pm.is_king_in_check(test4.board, (0, 4), 0) self.assertTrue(result == False) print("Test king is in check passed.")
def king_safety(board, side): score = 0 king = 12 if side == 1: king = 13 enemy = 1 - side king_location = PM.get_piece_location(king, board) if PM.is_frozen(king_location, board, side): score -= 50 if PM.is_king_in_check(board, king_location, side): return score - 500 else: enemy_coordinator = 5 if side == 1: enemy_coordinator = 4 coordinator_location = PM.get_piece_location(enemy_coordinator, board) enemy_king = 13 if side == 1: enemy_king = 12 enemy_king_location = PM.get_piece_location(enemy_king, board) if coordinator_location is not None: if coordinator_location[0] == king_location[0]: if abs(enemy_king_location[1] - king_location[1]) == 1: score -= 100 else: score -= 50 elif coordinator_location[1] == king_location[1]: score -= 10 return score
def king_safety(board, side): score = 0 king = 12 if side == 1: king = 13 enemy = 1 - side king_location = PM.get_piece_location(king, board) if PM.is_king_in_check(board, king_location, side): return 100 else: for i in range(8): next = PM.get_next_space(king_location, i) if next == None: continue if board[next[0]][next[1]] == 0: score -= 2 elif board[next[0]][next[1]] % 2 == enemy: score -= 10 else: score += 2 return score