-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection.nim
36 lines (31 loc) · 1.03 KB
/
selection.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from model.move import Move
from enhanced import Group
from analyze import WorldState
type
SelectionStatus* {.pure.} = enum
alreadyDone
done
needMoreTicks
proc select*(self: Group, ws: WorldState, m: var Move): SelectionStatus
from tables import `[]`, contains
from fastset import `==`, card
from groupcounter import GroupCounter
from model.action_type import ActionType
from utils import debug
from vehicles import resolve, toGroup
proc isSelected(self: Group, ws: WorldState): bool =
if self in ws.vehicles.byGroup:
ws.vehicles.selected == ws.vehicles.byGroup[self]
else: false
proc select(self: Group, ws: WorldState, m: var Move): SelectionStatus =
debug("Selecting group " & $self)
if self.isSelected(ws):
debug("Group " & $self & " is already selected!")
debug("Group " & $self & " contains " &
$ws.vehicles.byGroup[self].card)
SelectionStatus.alreadyDone
else:
debug("Selection by group " & $self)
m.action = ActionType.CLEAR_AND_SELECT
m.group = self.int32
SelectionStatus.done