Add MoveList implementation
This commit is contained in:
parent
b5181317ef
commit
3299f09e1f
|
@ -24,6 +24,39 @@ type
|
||||||
targetSquare*: Square
|
targetSquare*: Square
|
||||||
flags*: uint16
|
flags*: uint16
|
||||||
|
|
||||||
|
MoveList* = object
|
||||||
|
## A list of moves
|
||||||
|
data: array[218, Move]
|
||||||
|
len: int8
|
||||||
|
|
||||||
|
|
||||||
|
iterator items*(self: MoveList): Move =
|
||||||
|
var i = 0
|
||||||
|
while self.len > i:
|
||||||
|
yield self.data[i]
|
||||||
|
inc(i)
|
||||||
|
|
||||||
|
|
||||||
|
iterator pairs*(self: MoveList): tuple[i: int, move: Move] =
|
||||||
|
var i = 0
|
||||||
|
for item in self:
|
||||||
|
yield (i, item)
|
||||||
|
|
||||||
|
|
||||||
|
func add*(self: var MoveList, move: Move) {.inline.} =
|
||||||
|
self.data[self.len] = move
|
||||||
|
inc(self.len)
|
||||||
|
|
||||||
|
|
||||||
|
func contains*(self: MoveList, move: Move): bool {.inline.} =
|
||||||
|
for item in self:
|
||||||
|
if move == item:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
func len*(self: MoveList): int {.inline.} = self.len
|
||||||
|
|
||||||
|
|
||||||
func createMove*(startSquare, targetSquare: string, flags: seq[MoveFlag] = @[]): Move =
|
func createMove*(startSquare, targetSquare: string, flags: seq[MoveFlag] = @[]): Move =
|
||||||
result = Move(startSquare: startSquare.algebraicToSquare(),
|
result = Move(startSquare: startSquare.algebraicToSquare(),
|
||||||
|
|
Loading…
Reference in New Issue