Lots of changes

This commit is contained in:
cdricms
2024-06-28 00:02:48 +02:00
parent 8556380dba
commit 1d7f1095d5
11 changed files with 175 additions and 139 deletions

View File

@@ -1,15 +1,10 @@
final class King: Piece {
weak var board: Board?
var kind: Kind = .King
var unicodeRepresentation: String {
override var unicodeRepresentation: String {
return color == .Black ? "" : ""
}
var color: Color
var position: Square.Position
var pseudoLegalPositions: [Square.Position] {
override var pseudoLegalPositions: [Square.Position] {
[
position + (1, 0),
position + (1, 1),
@@ -18,19 +13,18 @@ final class King: Piece {
position + (-1, 0),
position + (-1, -1),
position + (0, -1),
position + (1, -1)
].filter {$0.index != nil}
position + (1, -1),
].filter { $0.index != nil }
}
var legalPositions: [Square.Position] {
override var legalPositions: [Square.Position] {
return pseudoLegalPositions.filter { isLegal(on: $0) }
}
func move(to dst: Square.Position) -> Bool {
return false
override func move(to dst: Square.Position) {
}
func isLegal(on pos: Square.Position) -> Bool {
override 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 }
@@ -44,9 +38,8 @@ final class King: Piece {
return true
}
init(color: Color, on position: Square.Position) {
self.color = color
self.position = position
init(with color: Color, on position: Square.Position) {
super.init(kind: .King, on: position, with: color)
}
}