JS Sandbox: Write a Custom Game

Use the GameConvert API to write custom rules, for example NIM. Your script must return a Game instance.

// Example: NIM with one heap
class Nim extends GameConvert {
    constructor() { super(); }

    // rawGame is the initial heap size, position is the current component state
    numMoves(rawGame, position) { return position; }
    
    // Both sides can remove the same number of tokens
    canLeftMove(rawGame, position, move) { return (position - (move + 1) >= 0); }
    canRightMove(rawGame, position, move) { return this.canLeftMove(rawGame, position, move); }
    
    // move is the move index. Removed tokens = move + 1.
    doMoveLeft(rawGame, position, move) { return position - (move + 1); }
    doMoveRight(rawGame, position, move) { return this.doMoveLeft(rawGame, position, move); }
    
    hashRawGamePosition(rawGame, position, move) { return (position << 8) ^ move; }
}

const nim = new Nim();
// Convert a heap of size 5. The expected value is *5.
return nim.convert(null, 5);


The result will appear here...