player module

Implement and use AI players in matches.

Custom AI players may subclass Player and implement Player.get_attack_areas() to offer a consistent interface to game engines.

class dicewars.player.Player

Base class for AI players.

get_attack_areas(grid, match_state, *args, **kwargs)

Choose (valid) areas for a Match attack.

Override this method in subclasses. It is provided with full Grid and match State information (and optional user data). If there is an attack possible and wanted, return a pair of attacking/attacked areas.

Parameters
  • grid (Grid) – Grid instance of the match (Match.game.grid)

  • match_state (State) – current match State (Match.state)

  • args – user arguments (optional)

  • kwargs – user keyword arguments (optional)

Returns

indices of attacking and attacked areas, None to not attack

Return type

tuple(int, int) or None

class dicewars.player.DefaultPlayer

A (more or less) clever AI player.

get_attack_areas(grid, match_state, *args, **kwargs)

Collect reasonable attack area pairs and return a random one of them.

class dicewars.player.PassivePlayer

A lazy AI player that never attacks (for testing).

get_attack_areas(grid, match_state, *args, **kwargs)
Returns

None