Lots of changes

This commit is contained in:
cdricms
2024-06-28 00:02:48 +02:00
parent 8556380dba
commit 1d7f1095d5
11 changed files with 175 additions and 139 deletions

View File

@@ -8,7 +8,34 @@ public struct Square: Equatable {
guard (rank > 0 && rank < 9) && (file > 0 && file < 9) else {
return nil
}
return Int(8*(8-rank)+file-1)
return Int(8 * (8 - rank) + file - 1)
}
public init(rank r: Int8, file f: Int8) {
rank = r
file = f
}
public enum File: String, CustomStringConvertible {
case a, b, c, d, e, f, g, h
public static subscript(_ f: Int8) -> Self? {
return switch f {
case 1: Self.a
case 2: Self.b
case 3: Self.c
case 4: Self.d
case 5: Self.e
case 6: Self.f
case 7: Self.g
case 8: Self.h
default: nil
}
}
public var description: String {
self.rawValue.uppercased()
}
}
public static func == (lhs: Position, rhs: Position) -> Bool {
@@ -34,7 +61,7 @@ public struct Square: Equatable {
public let position: Position
public let index: Int
var piece: Piece? = nil
public internal(set) var piece: Piece? = nil
public let color: Color
public static func == (lhs: Square, rhs: Square) -> Bool {