Can now initialize board with FEN

This commit is contained in:
cdricms
2024-06-26 00:18:22 +02:00
parent c36319d4d7
commit 0ea0ec1bc6
8 changed files with 221 additions and 36 deletions

View File

@@ -12,15 +12,18 @@ public enum Kind: String, CaseIterable {
}
}
public static subscript(_ c: Character) -> (Self, Color)? {
let v = c.uppercased()
guard v == "N" || (Self.allCases.contains { String($0.rawValue.first!) == v}) else {
guard
v == "N"
|| (Self.allCases.contains { String($0.rawValue.first!) == v })
else {
return nil
}
let kind: Self = switch v {
let kind: Self =
switch v {
case "P": .Pawn
case "N": .Knight
case "B": .Bishop
@@ -28,7 +31,7 @@ public enum Kind: String, CaseIterable {
case "Q": .Queen
case "K": .King
default: .Pawn
}
}
let color: Color = c.isUppercase ? .White : .Black
@@ -37,6 +40,7 @@ public enum Kind: String, CaseIterable {
}
public protocol Piece {
var board: Board? { get }
var color: Color { get }
var unicodeRepresentation: String { get }
var kind: Kind { get }