-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBase.py
37 lines (28 loc) · 1 KB
/
DataBase.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
from State import State
from Play_tools import Board, Vehicle
from utils import *
class DataBase:
def __init__(self):
self.Encoded_States = {}
def get_dict(self):
return self.Encoded_States
def add(self, _new_encoded):
self.Encoded_States[_new_encoded] = 0
def set_next(self, _state, _next):
e_state = encode_board(_state)
e_move = encode_move(_state, _next)
self.Encoded_States[e_state] = e_move
def get_next(self, _state):
# check if in dict
# if not -> add(_state) -> return 1 (expand)
# else get next
# if 0 -> return 0 (dead end)
# else decode next nove and make it relevant to _state -> return next
e_state = encode_board(_state)
if e_state not in self.Encoded_States:
self.add(e_state)
return 1
if self.Encoded_States[e_state] == 0:
return 0
d_move = decode_move(self.Encoded_States[e_state], _state.get_board())
return d_move