---
name: "nim"
section: "3"
platform: "linux"
package: "libggtl2-dev"
version: "2.1.4-2"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/nim/3"
---

# nim(3)

GGTL extension for a simple Nim variant

## NAME

GGTL-Nim - GGTL extension for a simple Nim variant

## SYNOPSIS

```
  #include <ggtl/nim.h>

  GGTL *g = ggtl_new_nim();
  struct nim_state *s = ...;
  nim_init(g, s);
```

## DESCRIPTION

This is a minimal GGTL extension used mainly in GGTL's test suite.

## FUNCTIONS

- GGTL \*nim\_init(GGTL \*g, void \*state)

  Initialises a `"GGTL"`'s vtable with functions for playing Nim, and set the provided state to be the starting state of the game.

- struct nim\_state \*nim\_state\_new( int player, int val )

  Return a new state with player and value set to the given arguments, or NULL on error.

- nim\_move\_new( int val )

  Return a new nim move, or NULL on error.

## CALLBACK FUNCTIONS

- int nim\_eval( void \*state, GGTL \*g )

  Returns the fitness of a gamestate from the view of the current player. A non-ending state has a fitness of 0, a finishing state has a fitness of 1. It is a winning state for that player, as the previous player was forced to take the last piece.

- void \*nim\_move( void \*state, void \*move, GGTL \*g )

  Returns the state resulting from applying `"move"` to `"state"`, or NULL on failure.

- void \*nim\_unmove( void \*state, void \*move, GGTL \*g )

  Returns the state resulting from reversing `"move"` on `"state"`, or NULL on failure.

- GGTL\_MOVE \*nim\_get\_moves( void \*state, GGTL \*g )

  Returns a list of the available moves at the given position, or NULL if no moves could be found.

## SEE ALSO

[*ggtl*(3)](/ggtl/3.md), [*reversi*(3)](/reversi/3.md)

## AUTHOR

Stig Brautaset \<stig@brautaset.org\>

## COPYRIGHT

Copyright (C) 2005-2006 Stig Brautaset

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