yes
This commit is contained in:
@@ -76,6 +76,12 @@ public class Board: CustomStringConvertible, EventDelegate {
|
|||||||
|
|
||||||
func notify(_ event: Event) {
|
func notify(_ event: Event) {
|
||||||
#warning("Not implemented")
|
#warning("Not implemented")
|
||||||
|
switch event {
|
||||||
|
case .kingInCheck(let piece, let king):
|
||||||
|
king.insertThreat(piece)
|
||||||
|
case .piecePinned(let p1, let p2):
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func addPieceToTarget(_ piece: Piece, target: Square.Position) {
|
internal func addPieceToTarget(_ piece: Piece, target: Square.Position) {
|
||||||
|
|||||||
@@ -29,13 +29,16 @@ final class Bishop: Piece, DiagonalMoves {
|
|||||||
if let king = piece as? King {
|
if let king = piece as? King {
|
||||||
delegate?.notify(.kingInCheck(self, on: king))
|
delegate?.notify(.kingInCheck(self, on: king))
|
||||||
legalPositions.removeLast()
|
legalPositions.removeLast()
|
||||||
|
last = position
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
delegate?.notify(
|
delegate?.notify(
|
||||||
.piecePinned(from: self, on: piece))
|
.piecePinned(from: self, on: piece))
|
||||||
|
last = position
|
||||||
}
|
}
|
||||||
last = position
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delegate?.addPieceToTarget(self, target: position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
final class King: Piece {
|
final class King: Piece {
|
||||||
typealias Threats = (Piece?, Piece?)
|
typealias Threats = (Piece?, Piece?)
|
||||||
var threats: Threats = (nil, nil)
|
internal private(set) var threats: Threats = (nil, nil)
|
||||||
|
|
||||||
|
func insertThreat(_ piece: Piece) {
|
||||||
|
if threats.0 == nil {
|
||||||
|
threats.0 = piece
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if threats.1 == nil {
|
||||||
|
threats.1 = piece
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override var unicodeRepresentation: String {
|
override var unicodeRepresentation: String {
|
||||||
return color == .Black ? "♚" : "♔"
|
return color == .Black ? "♚" : "♔"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,16 @@ final class Queen: Piece, LinearMoves, DiagonalMoves {
|
|||||||
if let king = piece as? King {
|
if let king = piece as? King {
|
||||||
delegate?.notify(.kingInCheck(self, on: king))
|
delegate?.notify(.kingInCheck(self, on: king))
|
||||||
legalPositions.removeLast()
|
legalPositions.removeLast()
|
||||||
|
last = position
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
delegate?.notify(
|
delegate?.notify(
|
||||||
.piecePinned(from: self, on: piece))
|
.piecePinned(from: self, on: piece))
|
||||||
|
last = position
|
||||||
}
|
}
|
||||||
last = position
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delegate?.addPieceToTarget(self, target: position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,16 @@ final class Rook: Piece, LinearMoves {
|
|||||||
if let king = piece as? King {
|
if let king = piece as? King {
|
||||||
delegate?.notify(.kingInCheck(self, on: king))
|
delegate?.notify(.kingInCheck(self, on: king))
|
||||||
legalPositions.removeLast()
|
legalPositions.removeLast()
|
||||||
|
last = position
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
delegate?.notify(
|
delegate?.notify(
|
||||||
.piecePinned(from: self, on: piece))
|
.piecePinned(from: self, on: piece))
|
||||||
|
last = position
|
||||||
}
|
}
|
||||||
last = position
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delegate?.addPieceToTarget(self, target: position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user