-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.py
46 lines (26 loc) · 853 Bytes
/
player.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
33
34
35
36
37
38
39
40
41
42
43
44
45
import random
class Player(object):
def name(self):
return self.__class__.__name__
def do_move(self, board):
raise ValueError('Player is an abstract class')
@staticmethod
def get_free_cells(board):
free_cells = []
for i in range(0, 9):
if board[i] == 0:
free_cells.append(i)
return free_cells
class RandomPlayer(Player):
def do_move(self, board):
free_cells = self.get_free_cells(board)
return random.choice(free_cells)
class HumanPlayer(Player):
def do_move(self, board):
free_cells = self.get_free_cells(board)
cell = input("Your move 0-8: ")
return int(cell)
class SequentialPlayer(Player):
def do_move(self, board):
free_cells = self.get_free_cells(board)
return free_cells[0]