-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess.py
More file actions
33 lines (21 loc) · 816 Bytes
/
chess.py
File metadata and controls
33 lines (21 loc) · 816 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
31
32
33
from typing import Dict, Tuple, List
coord = Tuple[int, int]
class Figure:
def __init__(self, start_pos: coord) -> None:
self._position = start_pos
def step(self, new_position: coord) -> None:
self._position = new_position
def possible_step(self):
raise NotImplementedError
class Pawn(Figure):
def __init__(self, start_pos: coord) -> None:
super().__init__(start_pos)
def possible_step(self) -> List[coord]:
x, y = self._position
return [(x, y + i) for i in range(1, 3) if x < 8 and y < 8]
class ChessDesk:
def __init__(self, size: Tuple[int, int]=(8, 8)) -> None:
self._figures = []
self._figures.append(Pawn((0, 0)))
self._figures.append(Pawn((1, 0)))
self._figures.append(Pawn((2, 0)))