-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathps10pr2.py
More file actions
55 lines (48 loc) · 1.5 KB
/
ps10pr2.py
File metadata and controls
55 lines (48 loc) · 1.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
# ps10pr2.py (Problem Set 10, Problem 2)
#
# A Connect-Four Player class
#
from ps10pr1 import Board
class Player:
def __init__(self, checker, width):
""" Constructor
"""
assert(checker == 'X' or checker == 'O')
self.num_moves = 0
self.checker = checker
self.width = width
def __repr__(self):
""" returns a string representing a Player object. The string returned
should indicate which checker the Player object is using.
"""
s = ''
if self.checker == 'O':
s = 'Player O'
else:
s = 'Player X'
return s
def opponent_checker(self):
""" returns a one-character string representing the checker of the Player
object’s opponent. The method may assume that the calling Player object
has a checker attribute that is either 'X' or 'O'.
"""
s = ''
if self.checker == 'O':
s = 'X'
else:
s = 'O'
return s
def next_move(self, board):
""" accepts a Board object as a parameter and returns the column where the player
wants to make the next move.
"""
self.num_moves += 0
while True:
col = int(input('Enter a column: '))
function = board.can_add_to(col)
if function == True:
self.num_moves += 1
return col
else:
print('Try Again!')