Linear + Diagonal moves

This commit is contained in:
cdricms
2024-06-27 18:09:01 +02:00
parent bc145da022
commit 8b5c2a592e
11 changed files with 179 additions and 108 deletions

View File

@@ -60,17 +60,17 @@ public class Board: CustomStringConvertible {
let piece: Piece =
switch k {
case .Pawn:
Pawn(color: c, on: .init(file: file, rank: rank))
Pawn(color: c, on: .init(rank: rank, file: file))
case .Knight:
Knight(color: c, on: .init(file: file, rank: rank))
Knight(color: c, on: .init(rank: rank, file: file))
case .Bishop:
Bishop(color: c, on: .init(file: file, rank: rank))
Bishop(color: c, on: .init(rank: rank, file: file))
case .Rook:
Rook(color: c, on: .init(file: file, rank: rank))
Rook(color: c, on: .init(rank: rank, file: file))
case .Queen:
Queen(color: c, on: .init(file: file, rank: rank))
Queen(color: c, on: .init(rank: rank, file: file))
case .King:
King(color: c, on: .init(file: file, rank: rank))
King(color: c, on: .init(rank: rank, file: file))
}
b[8*r+Int(file)-1].piece = piece
case .none:
@@ -96,7 +96,7 @@ public class Board: CustomStringConvertible {
for i in 0...63 {
let index = Int8(i)
let square = Square(
position: .init(file: (index % 8) + 1, rank: rank),
position: .init(rank: rank, file: (index % 8) + 1),
index: i,
color: index % 2 != rank % 2 ? .Black : .White)
squares.append(square)
@@ -135,7 +135,9 @@ public class Board: CustomStringConvertible {
}
public subscript(pos: Square.Position) -> Square? {
let i = pos.index
guard let i = pos.index else {
return nil
}
if i > squares.count {
return nil
}