-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhuman.py
More file actions
24 lines (19 loc) · 746 Bytes
/
Copy pathhuman.py
File metadata and controls
24 lines (19 loc) · 746 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
import chess
import player
class Human(player.Player):
def __init__(self, description = "Human chess player."):
self.type = "Human"
self.description = description
def move(self, board):
legalMoves = list(board.legal_moves)
userMove = 0
while (not userMove):
try:
userInput = input('Please enter a valid move! ')
userMove = chess.Move.from_uci(userInput)
except ValueError as ve:
print('That was not a chess move;', ve)
while (not userMove in legalMoves):
userInput = input("That move won't work on this board. Try again. ")
userMove = chess.Move.from_uci(userInput)
return userMove