### 4 releases

0.1.1 | Feb 11, 2023 |
---|---|

0.1.0 | Feb 10, 2023 |

0.0.1 | Jan 25, 2023 |

0.0.0 | Jan 25, 2023 |

#**877** in Game dev

**LGPL-3.0-or-later**

36KB

427 lines

# NimLib

A Rust library for Nim games: calculate nimbers and possible moves

## A game called Nim

*Nim* refers to a set of (mathematical/strategy) games where two players take turns in removing coins from stacks of coins.
The player who makes the last legal move wins.

Every Nim game consists of a set of rules, which define how many coins may be removed from a stack in a single move. Each move affects exactly one stack of coins, possibly requiring the stack to be split into two non-empty stacks.

A version of Nim called *Poker-Nim* is played with the addition of coin-pools, where removed coins are kept in the player's pool,
to be placed in future moves, if allowed by the rules, and desired by the player.

## About the library

This library calculates the nimbers for stacks of a given height, and the possible moves for a given position.

### Nimbers

The *nimber* of a stack can be thought of as some kind of score or evaluation of how good this position is for the player who is to move.

See the

module for functions for calculating nimbers.`nimlib ::`nimbers

A nimber of 0 means that the player who is to move has no winning strategy, and will lose the game, no matter what move they make, given their opponent plays optimally.

Conversely, a nimber greater than 0 means that the player who is to move has a winning strategy, and will win the game, no matter what move their opponent makes, given the player to move plays optimally.

### Moves

The

module provides functions for calculating the possible moves for a given position.`nimlib ::`moves

A position simply refers to a list/set of stacks, the nimber of a position is the XOR-sum of the nimbers of the stacks in the position, the rules regarding winning conditions for the entire position are the same as for the individual stacks.

## License

Copyright (C) 2023 @Tanja-4732

NimLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

NimLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with NimLib. If not, see https://www.gnu.org/licenses/, specifically https://www.gnu.org/licenses/lgpl-3.0.html.

#### Dependencies

~0.4–1MB

~23K SLoC