Coverage for pystrat2048/random_strategy.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-05-11 08:05 +0200

1""" 

2Implements a random strategy for the game 2048. 

3""" 

4import random 

5 

6 

7def random_strategy(game, state=None, moves=None): 

8 """ 

9 Returns a random direction. 

10 

11 :param game: matrix usually 4x4 but could anything else 

12 :param state: keeps here anything you need, it will be 

13 here at the next call to the function 

14 :param moves: list of previous moves (unused) 

15 :return: a direction in `{0, 1, 2, 3}` 

16 """ 

17 return random.randint(0, 3) 

18 

19 

20def random_strategy_all_but_one(game, state=None, moves=None): 

21 """ 

22 Returns a random direction among three. 

23 

24 :param game: matrix usually 4x4 but could anything else 

25 :param state: keeps here anything you need, it will be 

26 here at the next call to the function 

27 :param moves: list of previous moves (unused) 

28 :return: a direction in `{0, 1, 2}` 

29 """ 

30 return random.randint(0, 2)