-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
33 lines (27 loc) · 955 Bytes
/
player.py
File metadata and controls
33 lines (27 loc) · 955 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
25
26
27
28
29
30
31
32
33
#
# A Connect-Four Player class
#
from board import Board
class Player:
def __init__(self, checker):
"""constructs new player with checker attribute and num of moves"""
assert(checker == 'X' or checker == 'O')
self.checker = checker
self.num_moves = 0
def __repr__(self):
"""returns string representing a player object"""
return 'Player ' + self.checker
def opponent_checker(self):
"""returns one-charcter stirng representing checker of opponent"""
if self.checker == 'X':
return 'O'
else:
return 'X'
def next_move(self, board):
"""accepts Board object and returns column where player wants to make move"""
col = int(input('Enter a column: '))
self.num_moves += 1
while board.can_add_to(col) == False:
print("Try again!")
col = int(input('Enter a column: '))
return col