Crates.io | nimlib |
lib.rs | nimlib |
version | 0.1.1 |
source | src |
created_at | 2023-01-25 17:01:38.831438 |
updated_at | 2023-02-11 01:20:17.358888 |
description | A Rust library for Nim games: calculate nimbers and possible moves |
homepage | https://github.com/Tanja-4732/nimlib#readme |
repository | https://github.com/Tanja-4732/nimlib |
max_upload_size | |
id | 767622 |
size | 42,731 |
A Rust library for Nim games: calculate nimbers and possible moves
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.
This library calculates the nimbers for stacks of a given height, and the possible moves for a given position.
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 nimlib::nimbers
module for functions for calculating 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.
The nimlib::moves
module provides functions for calculating the possible moves for a given position.
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.
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.