-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
39 lines (34 loc) · 1.01 KB
/
player.py
File metadata and controls
39 lines (34 loc) · 1.01 KB
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
#
# A Connect-Four Player class
#
class Player:
""" a data type for a Connect Four player
"""
def __init__(self, checker):
""" initializes attributes """
assert(checker == 'X' or checker == 'O')
self.checker = checker
self.num_moves = 0
def __repr__(self):
""" returns a string that represents a Player object
"""
return 'Player ' + self.checker
def opponent_checker(self):
""" returns a string that represents the
checker of the Player object's opponent
"""
if self.checker == 'X':
return 'O'
else:
return 'X'
def next_move(self, b):
""" get a next move for this player
that is valid for the board b
"""
self.num_moves += 1
while True:
col = int(input('Enter a column: '))
if b.can_add_to(col) == True:
return col
else:
print('Try again!')