-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps10pr2.py
45 lines (31 loc) · 1.06 KB
/
ps10pr2.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
34
35
36
37
38
39
40
41
42
43
44
45
#
# ps10pr2.py (Problem Set 10, Problem 2)
#
# A Connect Four Player class
#
from ps10pr1 import Board
# Write your class below.
class Player:
""" Represent a player of the Connect Four game. """
def __init__(self, checker):
assert(checker == 'X' or checker == 'O')
self.checker = checker
self.num_moves = 0
def __repr__(self):
""" returns a string representing a Player object. """
a = 'Player ' + str(self.checker)
return a
def opponent_checker(self):
if self.checker == 'X':
return 'O'
else:
return 'X'
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. """
col = int(input(""" enter a column: """))
while col < 0 or col >= board.width:
print('Try Again!')
col = int(input(""" enter a column: """))
self.num_moves += 1
return col