Can now initialize board with FEN
This commit is contained in:
33
Sources/Engine/Pieces/Bishop.swift
Normal file
33
Sources/Engine/Pieces/Bishop.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
package class Bishop: Piece {
|
||||
package weak var board: Board?
|
||||
package var kind: Kind = .Bishop
|
||||
|
||||
package var unicodeRepresentation: String {
|
||||
return color == .Black ? "♝" : "♗"
|
||||
}
|
||||
package var color: Color
|
||||
|
||||
package var position: Square.Position
|
||||
|
||||
package var pseudoLegalPositions: [Square.Position] {
|
||||
return []
|
||||
}
|
||||
|
||||
package var legalPositions: [Square.Position] {
|
||||
return pseudoLegalPositions.filter { isLegal(pos: $0) }
|
||||
}
|
||||
|
||||
package func move(dst: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package func isLegal(pos: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package init(color: Color, on position: Square.Position) {
|
||||
self.color = color
|
||||
self.position = position
|
||||
}
|
||||
|
||||
}
|
||||
33
Sources/Engine/Pieces/King.swift
Normal file
33
Sources/Engine/Pieces/King.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
package class King: Piece {
|
||||
package weak var board: Board?
|
||||
package var kind: Kind = .King
|
||||
|
||||
package var unicodeRepresentation: String {
|
||||
return color == .Black ? "♛" : "♕"
|
||||
}
|
||||
package var color: Color
|
||||
|
||||
package var position: Square.Position
|
||||
|
||||
package var pseudoLegalPositions: [Square.Position] {
|
||||
return []
|
||||
}
|
||||
|
||||
package var legalPositions: [Square.Position] {
|
||||
return pseudoLegalPositions.filter { isLegal(pos: $0) }
|
||||
}
|
||||
|
||||
package func move(dst: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package func isLegal(pos: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package init(color: Color, on position: Square.Position) {
|
||||
self.color = color
|
||||
self.position = position
|
||||
}
|
||||
|
||||
}
|
||||
33
Sources/Engine/Pieces/Knight.swift
Normal file
33
Sources/Engine/Pieces/Knight.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
package class Knight: Piece {
|
||||
package weak var board: Board?
|
||||
package var kind: Kind = .Knight
|
||||
|
||||
package var unicodeRepresentation: String {
|
||||
return color == .Black ? "♞" : "♘"
|
||||
}
|
||||
package var color: Color
|
||||
|
||||
package var position: Square.Position
|
||||
|
||||
package var pseudoLegalPositions: [Square.Position] {
|
||||
return []
|
||||
}
|
||||
|
||||
package var legalPositions: [Square.Position] {
|
||||
return pseudoLegalPositions.filter { isLegal(pos: $0) }
|
||||
}
|
||||
|
||||
package func move(dst: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package func isLegal(pos: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package init(color: Color, on position: Square.Position) {
|
||||
self.color = color
|
||||
self.position = position
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,15 +12,18 @@ public enum Kind: String, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static subscript(_ c: Character) -> (Self, Color)? {
|
||||
let v = c.uppercased()
|
||||
|
||||
guard v == "N" || (Self.allCases.contains { String($0.rawValue.first!) == v}) else {
|
||||
guard
|
||||
v == "N"
|
||||
|| (Self.allCases.contains { String($0.rawValue.first!) == v })
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let kind: Self = switch v {
|
||||
let kind: Self =
|
||||
switch v {
|
||||
case "P": .Pawn
|
||||
case "N": .Knight
|
||||
case "B": .Bishop
|
||||
@@ -28,7 +31,7 @@ public enum Kind: String, CaseIterable {
|
||||
case "Q": .Queen
|
||||
case "K": .King
|
||||
default: .Pawn
|
||||
}
|
||||
}
|
||||
|
||||
let color: Color = c.isUppercase ? .White : .Black
|
||||
|
||||
@@ -37,6 +40,7 @@ public enum Kind: String, CaseIterable {
|
||||
}
|
||||
|
||||
public protocol Piece {
|
||||
var board: Board? { get }
|
||||
var color: Color { get }
|
||||
var unicodeRepresentation: String { get }
|
||||
var kind: Kind { get }
|
||||
|
||||
33
Sources/Engine/Pieces/Queen.swift
Normal file
33
Sources/Engine/Pieces/Queen.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
package class Queen: Piece {
|
||||
package weak var board: Board?
|
||||
package var kind: Kind = .Queen
|
||||
|
||||
package var unicodeRepresentation: String {
|
||||
return color == .Black ? "♛" : "♕"
|
||||
}
|
||||
package var color: Color
|
||||
|
||||
package var position: Square.Position
|
||||
|
||||
package var pseudoLegalPositions: [Square.Position] {
|
||||
return []
|
||||
}
|
||||
|
||||
package var legalPositions: [Square.Position] {
|
||||
return pseudoLegalPositions.filter { isLegal(pos: $0) }
|
||||
}
|
||||
|
||||
package func move(dst: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package func isLegal(pos: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package init(color: Color, on position: Square.Position) {
|
||||
self.color = color
|
||||
self.position = position
|
||||
}
|
||||
|
||||
}
|
||||
33
Sources/Engine/Pieces/Rook.swift
Normal file
33
Sources/Engine/Pieces/Rook.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
package class Rook: Piece {
|
||||
package weak var board: Board?
|
||||
package var kind: Kind = .Rook
|
||||
|
||||
package var unicodeRepresentation: String {
|
||||
return color == .Black ? "♜" : "♖"
|
||||
}
|
||||
package var color: Color
|
||||
|
||||
package var position: Square.Position
|
||||
|
||||
package var pseudoLegalPositions: [Square.Position] {
|
||||
return []
|
||||
}
|
||||
|
||||
package var legalPositions: [Square.Position] {
|
||||
return pseudoLegalPositions.filter { isLegal(pos: $0) }
|
||||
}
|
||||
|
||||
package func move(dst: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package func isLegal(pos: Square.Position) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
package init(color: Color, on position: Square.Position) {
|
||||
self.color = color
|
||||
self.position = position
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user