API

pystrat2048.evaluate.evaluate_strategy(fct_strategy, ntries=10)[source]

Applies method best_move until gameover starting from the current position. Repeats ntries times and the maximum number in every try.

Parameters:

fct_strategy – a function which returns the best move (see below)

Returns:

enumerator on scores

One example to show how to test a strategy:

import random
from pystrat2048 import evaluate_strategy

def random_strategy(game, state, moves):
    return random.randint(0, 3)

scores = list(evaluate_strategy(random_strategy))
print(scores)
pystrat2048.random_strategy.random_strategy(game, state=None, moves=None)[source]

Returns a random direction.

Parameters:
  • game – matrix usually 4x4 but could anything else

  • state – keeps here anything you need, it will be here at the next call to the function

  • moves – list of previous moves (unused)

Returns:

a direction in {0, 1, 2, 3}

class pystrat2048.cp2048.Game2048(game=None)[source]

Implements the logic of the game 2048.