Some refactor and tests
This commit is contained in:
@@ -10,17 +10,16 @@ final class Knight: Piece {
|
||||
var position: Square.Position
|
||||
|
||||
var pseudoLegalPositions: [Square.Position] {
|
||||
let directions: [Square.Position] = [
|
||||
.init(rank: position.rank + 2, file: position.file + 1),
|
||||
.init(rank: position.rank + 2, file: position.file - 1),
|
||||
.init(rank: position.rank - 2, file: position.file + 1),
|
||||
.init(rank: position.rank - 2, file: position.file - 1),
|
||||
.init(rank: position.rank + 1, file: position.file + 2),
|
||||
.init(rank: position.rank + 1, file: position.file - 2),
|
||||
.init(rank: position.rank - 1, file: position.file + 2),
|
||||
.init(rank: position.rank - 1, file: position.file - 2)
|
||||
]
|
||||
return directions.filter { $0.index != nil }
|
||||
[
|
||||
position + (2, 1),
|
||||
position + (2, -1),
|
||||
position + (-2, 1),
|
||||
position + (-2, -1),
|
||||
position + (1, 2),
|
||||
position + (1, -2),
|
||||
position + (-1, 2),
|
||||
position + (-1, -2)
|
||||
].filter { $0.index != nil }
|
||||
}
|
||||
|
||||
var legalPositions: [Square.Position] {
|
||||
|
||||
Reference in New Issue
Block a user