Rock-paper-scissors: Difference between revisions

Content added Content deleted
m (Changed "Successors" to "Successor".)
Line 3,533: Line 3,533:
History = tuple[total: int; counts: CountTable[Choice]]
History = tuple[total: int; counts: CountTable[Choice]]


const Successors: array[Choice, Choice] = [Paper, Scissors, Rock]
const Successor: array[Choice, Choice] = [Paper, Scissors, Rock]


func `>`(a, b: Choice): bool =
func `>`(a, b: Choice): bool =
## By construction, only the successor is greater than the choice.
## By construction, only the successor is greater than the choice.
a == Successors[b]
a == Successor[b]


proc choose(history: History): Choice =
proc choose(history: History): Choice =
Line 3,545: Line 3,545:
for choice, count in history.counts.pairs:
for choice, count in history.counts.pairs:
if value <= count:
if value <= count:
return Successors[choice]
return Successor[choice]
dec value, count
dec value, count