Skip to content

Commit

Permalink
add daemon mode for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiang Chen committed Nov 9, 2024
1 parent 21292b5 commit 55b1f18
Show file tree
Hide file tree
Showing 89 changed files with 96 additions and 11 deletions.
20 changes: 13 additions & 7 deletions gomoku/script/divided_solution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ def hash(self, board_str):
def board_str_hash(board_str):
return board_str # z.hash(board_str)

def key_exists(db, key):
try:
db.Get(key)
return True
except KeyError:
return False

def find_next_steps_from_board_str_db(step_str, db):
"""
Expand All @@ -609,27 +615,27 @@ def find_next_steps_from_board_str_db(step_str, db):
possible_moves = []
for steps, tran in zip(new_format_steps, trans):
board_str = steps2board_str(steps)
action = db.get(str.encode(board_str))
if action is not None:
if key_exists(db, str.encode(board_str)):
action = db.Get(str.encode(board_str))
before_trans = action.decode()
next_move = apply_transformation(before_trans, tran, reverse=True)
possible_moves.append(next_move)
return possible_moves


def find_next_steps_from_board_str_hash2action(step_str, board_str_hash2action):
def find_next_steps_from_db(step_str, db):
"""
:param step_str: h8_i8
:param board_str_hash2action: result from get_all_step_str2action
:param : result from get_all_step_str2action
:return:
"""
new_format_steps, trans = apply_all_transformation_for_steps_str(step_str)
possible_moves = []
for steps, tran in zip(new_format_steps, trans):
norm_steps = board_str_hash(steps2board_str(steps))
if norm_steps in board_str_hash2action:
before_trans = board_str_hash2action[norm_steps]
norm_steps = normalize_steps_str(steps)
if key_exists(db, norm_steps.encode('utf-8')):
before_trans = db.Get(norm_steps.encode('utf-8')).decode()
next_move = apply_transformation(before_trans, tran, reverse=True)
possible_moves.append(next_move)
return possible_moves
Expand Down
Loading

0 comments on commit 55b1f18

Please sign in to comment.