Some bug fixes
This commit is contained in:
@@ -2,12 +2,14 @@ enum Event {
|
||||
case kingInCheck(_ by: Piece, on: King)
|
||||
case piecePinned(from: Piece, on: Piece)
|
||||
}
|
||||
|
||||
protocol EventDelegate {
|
||||
func notify(_ event: Event)
|
||||
func movePiece(_ piece: Piece, to dst: Square.Position) throws
|
||||
func addPieceToTarget(_ piece: Piece, target: Square.Position)
|
||||
func getSquareInfo(on pos: Square.Position) -> Square?
|
||||
}
|
||||
|
||||
public class Board: CustomStringConvertible, EventDelegate {
|
||||
public typealias Grid = [[Square]]
|
||||
|
||||
@@ -77,10 +79,10 @@ public class Board: CustomStringConvertible, EventDelegate {
|
||||
}
|
||||
|
||||
internal func addPieceToTarget(_ piece: Piece, target: Square.Position) {
|
||||
guard var square = self[target] else {
|
||||
guard self[target] != nil else {
|
||||
return
|
||||
}
|
||||
square.targetted.insert(piece)
|
||||
squares[target.index!].targetted.insert(piece)
|
||||
}
|
||||
|
||||
public private(set) var halfMoveClock: UInt8 = 0
|
||||
@@ -189,7 +191,10 @@ public class Board: CustomStringConvertible, EventDelegate {
|
||||
}
|
||||
|
||||
try piece.move(to: dst)
|
||||
#warning("May need to clear threatenedSquares before hand.")
|
||||
threatenedSquares = [
|
||||
.White: [],
|
||||
.Black: [],
|
||||
]
|
||||
for square in squares where square.piece != nil {
|
||||
let p = square.piece!
|
||||
p.getLegalPosition()
|
||||
@@ -320,13 +325,11 @@ public class Board: CustomStringConvertible, EventDelegate {
|
||||
boardString += String(_rank) + " \(UnicodeBar.VerticalBar)"
|
||||
rank.forEach { square in
|
||||
let p = square.piece?.unicodeRepresentation ?? " "
|
||||
h1 = def
|
||||
if let c = colors {
|
||||
for (color, s) in c {
|
||||
h1 = def
|
||||
if (s.contains { $0 == square.position }) {
|
||||
h1 = color
|
||||
break
|
||||
}
|
||||
for (color, s) in c
|
||||
where (s.contains { $0 == square.position }) {
|
||||
h1 = color
|
||||
}
|
||||
}
|
||||
boardString +=
|
||||
|
||||
Reference in New Issue
Block a user