66 lines
1.4 KiB
Nim
66 lines
1.4 KiB
Nim
|
import os, strutils
|
||
|
import game
|
||
|
|
||
|
|
||
|
const help =
|
||
|
"""cup - Probability calculator for the board game CamelUp
|
||
|
|
||
|
Usage:
|
||
|
cup [-i] SPACE:STACK [...SPACE:STACK] [DICE]
|
||
|
|
||
|
SPACE refers to a numbered board space (1-16).
|
||
|
STACK refers to a stack of camel colors from bottom to top, e.g.
|
||
|
YBR (Yellow, Blue, Red, with Red on top).
|
||
|
DICE refers to the set of dice that have already been rolled,
|
||
|
e.g. GPR (Green, Purple, Red)
|
||
|
|
||
|
Options:
|
||
|
-i Interactive mode (currently unimplemented)
|
||
|
-h Show this message and exit
|
||
|
"""
|
||
|
|
||
|
type
|
||
|
CmdConfig* = object
|
||
|
state*: seq[tuple[c: Color, p: int]]
|
||
|
interactive*: bool
|
||
|
diceRolled*: array[Color, bool]
|
||
|
|
||
|
|
||
|
proc parseColor(c: char): Color =
|
||
|
case c:
|
||
|
of 'R', 'r':
|
||
|
return cRed
|
||
|
of 'G', 'g':
|
||
|
return cGreen
|
||
|
of 'B', 'b':
|
||
|
return cBlue
|
||
|
of 'Y', 'y':
|
||
|
return cYellow
|
||
|
of 'P', 'p':
|
||
|
return cPurple
|
||
|
else:
|
||
|
raise newException(ValueError, "Invalid camel color specified.")
|
||
|
|
||
|
|
||
|
proc parseArgs*(): CmdConfig =
|
||
|
for p in os.commandLineParams():
|
||
|
if p == "-h":
|
||
|
echo help
|
||
|
quit 0
|
||
|
elif p == "-i":
|
||
|
result.interactive = true
|
||
|
elif result.state.len < 5:
|
||
|
let splat = p.split(':')
|
||
|
|
||
|
let sq = splat[0]
|
||
|
let square = sq.parseInt
|
||
|
|
||
|
let colors = splat[1]
|
||
|
for c in colors:
|
||
|
let color = parseColor(c)
|
||
|
result.state.add((color, square))
|
||
|
else:
|
||
|
for c in p:
|
||
|
let color = parseColor(c)
|
||
|
result.diceRolled[color] = true
|