- CLI to access library functions:
- Calculate splits for a given height (with the
splits
subcommand)- As formatted text (default)
- As CSV (with the
--csv
flag or-c
short flag)
--version
and--help
flagsmake-rule-set
subcommand to create a JSON string describing a Nim game's rules- Use
--take-split-never
or-n
either followed by a number to specify a rule where a player may take a number of coins from a stack without splitting it in the process - Likewise,
--take-split-optional
or-o
followed by a number specifies a take rule where splitting is optional - The
--take-split-always
or-a
option followed by a number specifies a take rule where splitting is mandatory - Using
--allow-any-take
or-A
creates a rule allowing to take an arbitrary number of coins from a stack, followed by a choice fromnever
,optional
, oralways
to specify if splitting is forbidden, optional, or mandatory - The yet-to-be-implemented
--allow-place
or-p
option creates a rule which allows the player to place coins on a stack; this option is not yet implemented and does not take any arguments --pretty-print
or-P
prints the JSON string in a more readable format, with indentation and line breaks
- Use
- The
nimber
subcommand to- Calculate the nimber(s) for a (set of) stack(s) of given height(s) (using
--print stacks
or-p stacks
) - Calculate the nimber of a position of stacks (using
--print position
or-p position
) - Display them both (default, or by using
--print both
or-p both
) - Rules are taken with the required
--rules
or-r
flag in the form of a JSON string - The
--json
or-j
flag can be used to print the output as JSON instead of plain text - Likewise, the
--json-pretty
or-J
flag can be used to print the output as pretty-printed JSON
- Calculate the nimber(s) for a (set of) stack(s) of given height(s) (using
- Logging support with verbosity controls using
--verbose
or-v
(can be used multiple times), or--quiet
or-q
(can be used multiple times)
- Applied many
clippy
suggestions
- Improved readme and documentation
- Fix links: link to latest to help search engines find the latest version
- Add a description of the library to the readme
- Explain how Nim games work
- Module
moves
- Enum
MoveError
, a list of possible errors when applying or calculating moves check_move
is a function which checks if a move is legal for a given position- The function
calculate_legal_moves
which calculates all legal moves from a given position apply_move
is a function which applies a move to a position, changing the position- The unsafe version of which is
apply_move_unchecked
which does not check if the move is legal
- Enum
- Struct
Nimber
which represents a nimber and simply wraps au64
- Used to avoid confusion of heights and nimbers using the type system
- Enum
NimAction
which represents a move in a Nim game - Structs
TakeAction
andPlaceAction
which are used inNimAction
- Enum
NimSplit
, the result of a split: eitherYes
with two new stacks orNo
- Many unit tests for both the old code, and the new
- Renamed module
algo
tonimbers
- Function
calculate_nimber_for_height
innimbers
- Now returns a
Nimber
instead of au64
- Now takes a slice of
NimRule
instead of a hard-coded vector&Vec<NimRule>
- Moved internal code to
moves::calculate_legal_moves
(code deduplication)
- Now returns a
- Function
calculate_legal_moves
- Argument
stacks
was moved from&Vec<Stack>
to&[Stack]
, allowing for an optimization in thiscalculate_nimber_for_height
- Same goes for its
rules
argument, which was moved from&Vec<NimRule>
to&[NimRule]
- Argument
- Changed return type of
nimbers::calculate_splits
Vec<(u64, u64)>
from toVec<(Stack, Stack)>
- Removed
clear_nimber_cache
fromnimbers
(then namedalgo
)- The cache now supports multiple rule sets, so clearing the cache is no longer necessary when the rules change
- Maybe some kind of cache control will be added in the future to reduce memory usage on demand
- Fixed a bug in the way the cache was used, which resulted in incorrect nimbers being returned
- This was due to the fact that the same cache was used for every rule set
- Now, a new cache is created for every rule set
- This is the initial release of NimLib
- Version
0.0.0
was a placeholder release without any code - Version
0.0.1
is the first real release
- Version
- Module
algo
- The
calculate_nimber_for_height
function which calculates the nimber for a given height - The
calculate_splits
function which calculates all possible splits for a given height, accounting for symmetry - The module also contains the function
clear_nimber_cache
which has/had to be called every time the rules changed
- The
- Struct
NimStack
which represents a stack and simply wraps au64
- Struct
NimRule
representing a rule in a Nim game - Struct
NimGame
representing a Nim game, containing a list of rules and a list of stacks - Enum
Split
, used inNimRule
- Enum
TakeSize
which is used inNimRule