-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.py
More file actions
52 lines (40 loc) · 1.57 KB
/
Player.py
File metadata and controls
52 lines (40 loc) · 1.57 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
class Player(object):
"""Abstract Method to define rules for Players are Humman or Computer inherent"""
def __init__(self, game, player):
self.game = game
self.player = player
def play(self):
raise NotImplementedError("Inheritator forgot to implement this")
#class Humman inherent from abstract class Player
class Humman(Player):
def __init__(self, game, player):
#child inherent from parent
super(Humman, self).__init__(game, player)
#overrite function play
def play(self):
print("Player "+ self.player + " turn to play!")
possible_moves = self.game.get_possible_moves()
print("Possible moves: " + str(possible_moves))
if len(possible_moves) == 0:
print("No moves possible!")
return 1
col = int(input("Select column"))
row = int(input("Select row"))
print("Player: ", self.player, " Playing: col = "+ str(col) + " row = "+ str(row))
self.game.play(col, row)
return 0
class Computer(Player):
def __init__(self, game, player, AI):
super(Computer, self).__init__(game, player)
self.AI = AI
def play(self):
possible_moves = self.game.get_possible_moves()
if len(possible_moves) == 0:
print("No moves possible!")
return 1
move = self.AI.get_next_move()
col = move[0]
row = move[1]
print("Computer: "+ self.player," Playing: col = "+ str(col) + " row = "+ str(row) )
self.game.play(col, row)
return 0