forked from 905t/Python-Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
45 lines (42 loc) · 1.23 KB
/
player.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
class Player:
"""
represents a player in the chess game
"""
def __init__(self, name):
"""
initializes the chess player, with a given name,
sets colour to white by default, set_colour method is used to change the
players colour. players initialized as a human player.
"""
self.name = name
self.colour = "W"
#type is for later use when implementing player vs. ai, set to human for now
self.type = "human"
def get_name(self) -> str:
"""
return the name of the chess player.
>>> player1 = Player("Bob")
>>> player1.get_name()
"Bob"
"""
return self.name
def get_colour(self) -> str:
"""
return the colour of the chess player.
>>> player1 = Player("Rob")
>>> player1.get_colour()
"W"
"""
return self.colour
def set_colour(self, colour) -> None:
"""
sets the colour of the chess player, either "W" for white
or "B" for black.
>>> player1 = Player("John")
>>> player1.get_colour()
"W"
>>> player1.set_colour("B")
>>> player1.get_colour()
"B"
"""
self.colour = colour