From 2e1036d798c2938539d04bad714e85301b8441e3 Mon Sep 17 00:00:00 2001 From: Dscee <48890034+Dscee@users.noreply.github.com> Date: Thu, 23 May 2024 11:42:27 +0300 Subject: [PATCH] Check iOS version.swift --- Sources/ChessKitEngine/EngineType.swift | 52 +++++++++++++++++-------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/Sources/ChessKitEngine/EngineType.swift b/Sources/ChessKitEngine/EngineType.swift index e3979b5..41306c3 100644 --- a/Sources/ChessKitEngine/EngineType.swift +++ b/Sources/ChessKitEngine/EngineType.swift @@ -38,25 +38,43 @@ public enum EngineType: Int { /// Engine-specific options to configure at initialization. var setupCommands: [EngineCommand] { switch self { - case .stockfish: - let fileOptions = [ - "EvalFile": "nn-b1a57edbea57", - "EvalFileSmall": "nn-baff1ede1f90" - ].compactMapValues { - Bundle.main.url(forResource: $0, withExtension: "nnue")?.path() + case .stockfish: + if #available(iOS 16.0, *) { + let fileOptions = [ + "EvalFile": "nn-b1a57edbea57", + "EvalFileSmall": "nn-baff1ede1f90" + ].compactMapValues { + Bundle.main.url(forResource: $0, withExtension: "nnue")?.path(percentEncoded: false) + } + return fileOptions.map(EngineCommand.setoption) + } else { + let fileOptions = [ + "EvalFile": "nn-b1a57edbea57", + "EvalFileSmall": "nn-baff1ede1f90" + ].compactMapValues { + Bundle.main.url(forResource: $0, withExtension: "nnue")?.path + } + return fileOptions.map(EngineCommand.setoption) + } + case .lc0: + if #available(iOS 16.0, *) { + let fileOptions = [ + "WeightsFile": "192x15_network" + ].compactMapValues { + Bundle.main.url(forResource: $0, withExtension: nil)?.path(percentEncoded: false) + } + return fileOptions.map(EngineCommand.setoption) + } else { + let fileOptions = [ + "WeightsFile": "192x15_network" + ].compactMapValues { + Bundle.main.url(forResource: $0, withExtension: nil)?.path + } + return fileOptions.map(EngineCommand.setoption) } - - return fileOptions.map(EngineCommand.setoption) - case .lc0: - let fileOptions = [ - "WeightsFile": "192x15_network" - ].compactMapValues { - Bundle.main.url(forResource: $0, withExtension: nil)?.path() - } - - return fileOptions.map(EngineCommand.setoption) - } } +} + }