Some refactor and tests
This commit is contained in:
@@ -5,15 +5,12 @@ final class Pawn: Piece {
|
||||
var position: Square.Position
|
||||
var pseudoLegalPositions: [Square.Position] {
|
||||
let sign: Int8 = color == .Black ? -1 : 1
|
||||
let rank = Int8(position.rank)
|
||||
let directions: [Square.Position] = [
|
||||
.init(rank: rank + 1 * sign, file: position.file),
|
||||
.init(rank: rank + 2 * sign, file: position.file),
|
||||
.init(rank: rank + 1 * sign, file: position.file + 1),
|
||||
.init(rank: rank + 1 * sign, file: position.file - 1)
|
||||
]
|
||||
// TODO: Handle en passant
|
||||
return directions.filter { $0.index != nil }
|
||||
return [
|
||||
position + (1 * sign, 0),
|
||||
position + (2 * sign, 0),
|
||||
position + (1 * sign, 1),
|
||||
position + (1 * sign, -1)
|
||||
].filter { $0.index != nil }
|
||||
}
|
||||
var legalPositions: [Square.Position] {
|
||||
pseudoLegalPositions.filter { isLegal(on: $0) }
|
||||
|
||||
Reference in New Issue
Block a user