一种使用 Swift 解析和编写通用国际象棋界面 (UCI) 命令的简洁方式。
自 Swift 5.9 起可用。
let idCommand = Command(string: "id author alexsteinh")
idCommand == Command.id(.author("alexsteinh"))) // true
let infoCommand = Command(string: "info depth 34 seldepth 40 multipv 1 score cp 30 lowerbound")
infoCommand == Command.info([.depth(34), .seldepth(40), .multipv(1), .score([.cp(30), .lowerbound])]) // true
let normalizedCommand = Command(string: "\tid name \t\t\tImaginery\tChess Engine ")
normalizedCommand == Command.id(.name("Imaginery Chess Engine") // true
let invalidCommand = Command(string: "bogus")
invalidCommand == nil // true
let command = Command.id(.author("alexsteinh")))
print(command) // prints "id author alexsteinh"