-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.py
More file actions
66 lines (57 loc) · 1.75 KB
/
Move.py
File metadata and controls
66 lines (57 loc) · 1.75 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
56
57
58
59
60
61
62
63
64
65
66
"""
This module has the Move Class which is the class which handles moves on the board.
We are following the javadoc docstring format which is:
@param tag describes the input parameters of the function
@return tag describes what the function returns
@raise tag describes the errors this function can raise
"""
class Move:
"""
This class is used to describe the moves being made on the board.
"""
def __init__(self,l):
"""
Initializes Move Object
@param l: a sequence of position that the checker pieces will take during the execution of this move
| |
--------
| X|
--------
| |
--------
| X|
________
O | |
In the example above, l should be [(0,0),(2,2),(0,4)]
"""
self.seq = list(l)
@classmethod
def from_str(cls,s:str):
"""
This class enables the move object to be made from a str
@param s: string that describes the class. Eg '(0,0)-(2,2)-(0,4)'
"""
if (s == '-1'):
return cls([])
else:
sequencelist = list(map(lambda x:eval(x),s.split('-')))
return cls(sequencelist)
"""
:return self.seq = [(0,0),(2,2),(0,4)] -> '(0,0)-(2,2)-(0,4)'
"""
def __str__(self):
result = ''
if len(self.seq) == 0:
return '-1'
for e in self.seq:
result += str(e)
result += '-'
return result[:-1].replace(" ","")
def __len__(self):
return len(self.seq)
def __repr__(self):
return str(self)
def __getitem__(self,i):
return self.seq[i]
def __setitem__(self, index, value):
self.seq[index] = value