Lots of changes
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
final class Knight: Piece {
|
||||
weak var board: Board?
|
||||
var kind: Kind = .Knight
|
||||
|
||||
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 + (2, 1),
|
||||
position + (2, -1),
|
||||
@@ -18,24 +12,24 @@ final class Knight: Piece {
|
||||
position + (1, 2),
|
||||
position + (1, -2),
|
||||
position + (-1, 2),
|
||||
position + (-1, -2)
|
||||
position + (-1, -2),
|
||||
].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 }
|
||||
if p.kind == .King {
|
||||
// TODO: Notify board of check
|
||||
delegate?.notify(.kingInCheck(self))
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -44,9 +38,8 @@ final class Knight: 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: .Knight, on: position, with: color)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user