-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSmartRandom.py
32 lines (24 loc) · 927 Bytes
/
SmartRandom.py
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
import numpy as np
class Player:
'''
Randomly drop the disc into any column on the board that is not full.
'''
def __init__(self, rows, cols, connect_number,
timeout_setup, timeout_move, max_invalid_moves,
cylinder):
self.rows = rows
self.cols = cols
self.connect_number = connect_number
self.timeout_setup = timeout_setup
self.timeout_move = timeout_move
self.max_invalid_moves = max_invalid_moves
self.cylinder = cylinder
def setup(self,piece_color):
self.piece_color=piece_color
self.moves=np.arange(self.cols)
def play(self, board: np.ndarray) -> int:
valid_moves = self.valid_moves(board)
i = np.random.randint(0, len(valid_moves))
return valid_moves[i]
def valid_moves(self, board: np.ndarray) -> np.ndarray:
return self.moves[board[0,:]==0]