-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBasicPlayers.py
33 lines (28 loc) · 988 Bytes
/
BasicPlayers.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
########################################
# CS63: Artificial Intelligence, Final Project
# Spring 2018, Swarthmore College
########################################
from random import choice
from sys import stdin
class HumanPlayer:
"""Player that gets moves from command line input."""
def __init__(self, *args):
self.name = "Human"
def getMove(self, game):
move = None
while move not in game.availableMoves:
print("select a row and column")
try:
line = stdin.readline().split()
move = (int(line[0]), int(line[1]))
except ValueError:
print("invalid move")
if move not in game.availableMoves:
print("invalid move")
return move
class RandomPlayer:
"""Player that selects a random legal move."""
def __init__(self, *args):
self.name = "Random"
def getMove(self, game):
return choice(game.availableMoves)