-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemento.py
39 lines (31 loc) · 993 Bytes
/
memento.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
from copy import deepcopy
class State:
def __init__(self, board, black_left, white_left, black_kings, white_kings, turn, first_turn):
""""
save as arguments all turn information
"""
self.board = deepcopy(board)
self.black_left = black_left
self.white_left = white_left
self.black_kings = black_kings
self.white_kings = white_kings
self.turn = turn
self.first_turn = first_turn
class Memento:
def __init__(self):
""""
init stack to save states
"""
self.states = []
def push(self, board, black_left, white_left, black_kings, white_kings, turn, first_turn):
""""
push state to stack
"""
self.states.append(State(board, black_left, white_left, black_kings, white_kings, turn, first_turn))
def undo(self):
""""
return last state
"""
if self.states:
return self.states.pop()
pass