Added commands to execute interactively

This commit is contained in:
cdricms
2024-06-29 20:32:40 +02:00
parent 90f2988a14
commit 533322c5dd
4 changed files with 167 additions and 34 deletions

View File

@@ -55,7 +55,6 @@ public enum Kind: String, CaseIterable {
public class Piece: Hashable {
#warning("TODO: To be removed, handle everything through the delegate")
internal weak var board: Board?
public internal(set) var color: Color
public internal(set) var halfMoveCount: UInt8 = 0
public var unicodeRepresentation: String {
@@ -73,7 +72,7 @@ public class Piece: Hashable {
internal var delegate: EventDelegate?
internal func move(to dst: Square.Position) throws {
if !(legalPositions.contains { $0 == dst }) {
guard (legalPositions.contains { $0 == dst }) else {
throw Board.MoveFailure.destinationIsIllegal(pos: dst)
}
@@ -83,7 +82,7 @@ public class Piece: Hashable {
#warning("This method should be better thought out.")
internal func isLegal(on pos: Square.Position) -> Bool {
if let board = board, let s = board[pos] {
if let s = delegate?.getSquareInfo(on: pos) {
if let p = s.piece {
if p.color == color { return false }
if let king = p as? King {