-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathposition.py
More file actions
30 lines (24 loc) · 754 Bytes
/
position.py
File metadata and controls
30 lines (24 loc) · 754 Bytes
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
class Position:
def __init__(self, field, x, y=None):
pos = x
if y is not None:
pos = (x, y)
self.field = field
self.pos = pos
def __eq__(self, other):
if not isinstance(other, Position):
raise TypeError()
return self.field == other.field and \
self.pos == other.pos
def __add__(self, other):
if not isinstance(other, tuple):
raise TypeError()
return Position(self.field,
self.pos[0] + other[0],
self.pos[1] + other[1])
def x(self):
return self.pos[0]
def y(self):
return self.pos[1]
def __str__(self):
return str((self.field,) + self.pos)