Changed visibility from package to interal

This commit is contained in:
cdricms
2024-06-26 22:46:58 +02:00
parent 78a4737015
commit bc145da022
12 changed files with 208 additions and 110 deletions

View File

@@ -29,19 +29,19 @@ public class Board: CustomStringConvertible {
public private(set) var fen: Fen
public func setBoard() throws {
var file: UInt8 = 1
var rank: UInt8 = 8
var index: UInt8 = 0
var file: Int8 = 1
var rank: Int8 = 8
var index: Int8 = 0
var b: [Square] = squares
for c in fen.placement {
let r = (8 - Int(rank)) % 8
let r = 8 - Int(rank)
if c == "/" {
if file != 9 {
throw Fen.FenError.NotAppropriateLength(n: file, column: index)
}
rank -= 1
file = 0
} else if c.isWholeNumber, let n = UInt8(String(c)) {
} else if c.isWholeNumber, let n = Int8(String(c)) {
if n < 1 {
throw Fen.FenError.NumberTooSmall(n: n, column: index)
} else if n > 8 {
@@ -82,20 +82,22 @@ public class Board: CustomStringConvertible {
file += 1
index += 1
}
print(b)
#if DEBUG
print(b)
#endif
squares = b
}
public required init(fen: Fen =
.init(fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
) {
var rank: UInt8 = 8
var rank: Int8 = 8
self.fen = fen
for i in 0...63 {
let index = UInt8(i)
let index = Int8(i)
let square = Square(
position: .init(file: (index % 8) + 1, rank: rank),
index: index,
index: i,
color: index % 2 != rank % 2 ? .Black : .White)
squares.append(square)
if (index + 1) % 8 == 0 {