superttt

A Python module implemented in Rust.

1from .superttt import *
2
3__doc__ = superttt.__doc__
4if hasattr(superttt, "__all__"):
5    __all__ = superttt.__all__
class Game:

Game class

Methods:

  • get_available_moves() - Returns a vector containing the cells that are valid in the current state.
  • make_move(input, player_id_authentication)
def get_available_moves(self, /):
def make_move(self, /, input, player_id_authentication):

Make a move. This does nothing else.

Args

  • input - the cell that the current player makes a move in.
  • player_id_authentication - the id of the player that is making the move. This should be one of: {1, 2}
def get_winner(self, /):

Returns the id of the winner of the game.

If it is equal to 0, then the game ended in a draw.

def make_checkpoint(self, /):

Create a checkpoint. This can be saved somewhere and loaded in at a later point in time.

def load_checkpoint(self, /, checkpoint):

Load in a checkpoint from a PyCheckpoint object.

Args

  • checkpoint - checkpoint to load in.
def make_state(self, /):

Create a PyState-object. This object is a simple representation of the current game.

class Player:
def make_move(self, /, game):

Make a move with the current player. The default implementation is naive (makes a random move).

Override this method to have your custom heuristic.

def increment_wins(self, /):

Increment the number of wins for a player by one.

def get_wins(self, /):

Get the total number of wins for a player.

class Checkpoint:
def get_odds(self, /):
class State:

Represent a Pythonlike state. The current board, next player, and all possible moves. Uses Numpy arrays when possible.

Important note:

  • board - this attribute is a 1D-array. The first 9 elements represent the first field (upper left), the next 9 the second field (upper center) and so on
Layout:
 0  1  2        9  10  11       18  19  20
 3  4  5       12  13  14       21  22  23
 6  7  8       15  16  17       24  25  26

27  28  29     36  37  38       45  46  47
30  31  32     39  40  41       48  49  50
33  34  35     42  43  44       51  52  53

54  55  56     63  64  65       72  73  74
57  58  59     66  67  68       75  76  77
60  61  62     69  70  71       78  79  80
def to_checkpoint(self, /):

Coerces a pystate into a checkpoint.

This can be used to load in a checkpoint. Method is rather expensive.

Note: The reason why checkpoints and states are not the same is a design choice. We wanted the state to be as minimal as possible.

board
player_id
possible_moves
def play_game(player1, player2, game):

Play one game between two player objects. Delegates to overridden make_move method if it exists.

Todo: add caching for speeding up perhaps?

def play_multiple_games(player1, player2, number_of_games):

Play multiple games in a single-threaded environment