-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_player.py
More file actions
35 lines (27 loc) · 830 Bytes
/
random_player.py
File metadata and controls
35 lines (27 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from random import randint, choice
from game import Game, Move, Player
class RandomPlayer(Player):
"""
Class representing a player which plays randomly.
"""
def __init__(self) -> None:
"""
Constructor of the Random player.
Args:
None.
Returns:
None.
"""
super().__init__()
def make_move(self, game: 'Game') -> tuple[tuple[int, int], Move]:
"""
Select a random move to play.
Args:
game: the current game state.
Return:
A random move is returned.
"""
board = game.get_board()
from_pos = (randint(0, board.shape[1] - 1), randint(0, board.shape[0] - 1))
move = choice([Move.TOP, Move.BOTTOM, Move.LEFT, Move.RIGHT])
return from_pos, move