Can now move pieces
This commit is contained in:
@@ -69,8 +69,28 @@ public class Piece {
|
||||
return []
|
||||
}
|
||||
internal var delegate: EventDelegate?
|
||||
internal func move(to dst: Square.Position) {}
|
||||
internal func isLegal(on pos: Square.Position) -> Bool { false }
|
||||
internal func move(to dst: Square.Position) throws {
|
||||
if !(legalPositions.contains { $0 == dst }) {
|
||||
throw Board.MoveFailure.destinationIsIllegal(pos: dst)
|
||||
}
|
||||
|
||||
try delegate?.movePiece(self, to: dst)
|
||||
}
|
||||
internal func isLegal(on pos: Square.Position) -> Bool {
|
||||
|
||||
if let board = board, let s = board[pos] {
|
||||
if let p = s.piece {
|
||||
if p.color == color { return false }
|
||||
if p.kind == .King {
|
||||
// TODO: Notify board of check
|
||||
delegate?.notify(.kingInCheck(self))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
internal init(kind: Kind, on pos: Square.Position, with col: Color) {
|
||||
self.kind = kind
|
||||
|
||||
Reference in New Issue
Block a user