Linear + Diagonal moves

This commit is contained in:
cdricms
2024-06-27 18:09:01 +02:00
parent bc145da022
commit 8b5c2a592e
11 changed files with 179 additions and 108 deletions

View File

@@ -1,19 +1,35 @@
internal protocol DiagonalMoves {
protocol DiagonalMoves {
func getDiagonalMoves(from pos: Square.Position) -> [Square.Position]
}
extension DiagonalMoves {
func getDiagonalMoves(from pos: Square.Position) -> [Square.Position] {
return []
var squares = [Square.Position]()
for i: (Int8, Int8) in [(1, -1), (1, 1), (-1, 1), (-1, -1)] {
var currentSquare = pos + i
while currentSquare.index != nil {
squares.append(currentSquare)
currentSquare += i
}
}
return squares
}
}
internal protocol LinearMoves {
protocol LinearMoves {
func getLinearMoves(from pos: Square.Position) -> [Square.Position]
}
extension LinearMoves {
func getLinearMoves(from pos: Square.Position) -> [Square.Position] {
return []
var squares = [Square.Position]()
for i: (Int8, Int8) in [(1, 0), (0, 1), (-1, 0), (0, -1)] {
var currentSquare = pos + i
while currentSquare.index != nil {
squares.append(currentSquare)
currentSquare += i
}
}
return squares
}
}