-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
42 lines (29 loc) · 914 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
import math
import random
class Player:
def __int__(self, letter):
self.letter = letter
def get_move(self, game):
pass
class RandomComputerPlayer(Player):
def __init__(self, letter):
super().__init__(letter)
def get_move(self, game):
square = random.choice(game.availableSpaces())
return square
class HumanPlayer(Player):
def __int__(self, letter):
super().__init__(letter)
def get_move(self, game):
valid_square = False
val = None
while not valid_square:
sqaure = input(self.letter + '\' s turn.Input move (0-9):')
try:
val = int(sqaure)
if val not in game.availableSpaces():
raise ValueError
valid_square = True
except ValueError:
print("Invalid move.Try again.")
return val