npm install @luchsamapparat/nim
Install dependcies first via npm install. Then...
npm run buildClean thedistdirectory, run TSLint and build the librarynpm run watchClean thedistdirectory, build and test the library in parallel and repeat on file changenpm testRun tests
For this to work, git must be installed on the machine.
npm run releasebuilds the library, commits the changes todist, creates a new version and pushes it to the repository
import { GameState, Player, playRound, remainderStrategy, startGame } from '@luchsamapparat/nim';
const gameState: GameState = startGame({
heapSize: 13,
minTokensToRemove: 1,
maxTokensToRemove: 3,
startingPlayer: Player.Human,
strategy: remainderStrategy()
});
// game = {
// playNextRound: (tokensToRemove: number) => Game
// state: {
// config: {
// heapSize: 13,
// minTokensToRemove: 1,
// maxTokensToRemove: 3,
// startingPlayer: Player.Human,
// strategy: {
// getNextTurn: (gameState: GameState) => number
// }
// },
// heapSize: 13,
// minTokensAllowedToRemove: 1,
// maxTokensAllowedToRemove: 3,
// turns: [],
// winner: null
// }
// }
const updatedGameState: GameState = playRound(2)(gameState);
// game = {
// playNextRound: (tokensToRemove: number) => Game
// state: {
// config: {
// heapSize: 13,
// minTokensToRemove: 1,
// maxTokensToRemove: 3,
// startingPlayer: Player.Human,
// strategy: {
// getNextTurn: (gameState: GameState) => number
// }
// },
// heapSize: 8,
// minTokensAllowedToRemove: 1,
// maxTokensAllowedToRemove: 3,
// turns: [
// { player: 'Human', tokensRemoved: 2 },
// { player: 'Machine', tokensRemoved: 3 }
// ],
// winner: null
// }
// }import { NimGame, Player, remainderStrategy } from '@luchsamapparat/nim';
const gameConfig = {
heapSize: 13,
minTokensToRemove: 1,
maxTokensToRemove: 3,
startingPlayer: Player.Human,
};
// the computer always removes the minimum allowed number of tokens
startGame({
...gameConfig,
strategy: alwaysMinStrategy()
});
// the computer always removes the same number of tokens as the opponent did
startGame({
...gameConfig,
strategy: mimicHumanStrategy()
});
// the computer removes randomly removes tokens according to the minimum and maximun allowed number of tokens
startGame({
...gameConfig,
strategy: randomStrategy()
});
// the computer tries to leave the minimum allowed number of tokens to the opponent in the last round
startGame({
...gameConfig,
strategy: remainderStrategy()
});