Skip to content

Commit

Permalink
Update to version 3.3. and to engine folder aarch64
Browse files Browse the repository at this point in the history
Thanks to Randy!
  • Loading branch information
tosca07 authored May 2, 2024
1 parent bce3dc3 commit 83905de
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions picotutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class PicoTutor:
def __init__(
self,
i_engine_path="/opt/picochess/engines/armv7l/a-stockf",
i_engine_path="/opt/picochess/engines/aarch64/a-stockf",
i_player_color=chess.WHITE,
i_fen="",
i_comment_file="",
Expand Down Expand Up @@ -78,7 +78,11 @@ def __init__(

try:
with open("chess-eco_pos.txt") as fp:
self.book_data = list(csv.DictReader(filter(lambda row: row[0] != "#", fp.readlines()), delimiter="|"))
self.book_data = list(
csv.DictReader(
filter(lambda row: row[0] != "#", fp.readlines()), delimiter="|"
)
)
except EnvironmentError:
self.book_data = []

Expand All @@ -104,7 +108,9 @@ def _setup_comments(self, i_lang, i_comment_file):
self.comment_no = len(self.comments)

try:
general_comment_file = "/opt/picochess/engines/armv7l/general_game_comments_" + i_lang + ".txt"
general_comment_file = (
"/opt/picochess/engines/aarch64/general_game_comments_" + i_lang + ".txt"
)
with open(general_comment_file) as fp:
self.comments_all = fp.readlines()
except Exception:
Expand Down Expand Up @@ -308,6 +314,7 @@ def reset(self):
self.expl_start_position = True

def set_user_color(self, i_user_color):

self.pause()
self.history = []
self.history2 = []
Expand Down Expand Up @@ -535,28 +542,25 @@ def _eval_pv_list(pv_list, info_handler, legal_moves):
best_score = -999

for pv_key, pv_list in pv_list.items():
try:
if info_handler.info["score"][pv_key]:
score_val = info_handler.info["score"][pv_key]
move = chess.Move.null()

score = 0
mate = 0
if score_val.cp:
score = score_val.cp / 100
if pv_list[0]:
move = pv_list[0]
if score_val.mate:
mate = int(score_val.mate)
if mate < 0:
score = -999
elif mate > 0:
score = 999
legal_moves.append((pv_key, move, score, mate))
if score >= best_score:
best_score = score
except Exception:
best_score = -999
if info_handler.info["score"][pv_key]:
score_val = info_handler.info["score"][pv_key]
move = chess.Move.null()

score = 0
mate = 0
if score_val.cp:
score = score_val.cp / 100
if pv_list[0]:
move = pv_list[0]
if score_val.mate:
mate = int(score_val.mate)
if mate < 0:
score = -999
elif mate > 0:
score = 999
legal_moves.append((pv_key, move, score, mate))
if score >= best_score:
best_score = score

return best_score

Expand All @@ -573,7 +577,7 @@ def eval_legal_moves(self):

# collect possible good alternative moves
self.legal_moves.sort(key=self.sort_score, reverse=True)
for pv_key, move, score, mate in self.legal_moves:
for (pv_key, move, score, mate) in self.legal_moves:
if move:
diff = abs(best_score - score)
if diff <= 0.2:
Expand Down Expand Up @@ -627,12 +631,16 @@ def get_user_move_eval(self):

# best deep engine score/move
if self.legal_moves:
best_pv, best_move, best_score, best_mate = self.legal_moves[0] # tupel (pv,move,score,mate)
best_pv, best_move, best_score, best_mate = self.legal_moves[
0
] # tupel (pv,move,score,mate)

# calculate diffs based on low depth search for obvious moves
if len(self.history2) > 0:
try:
low_pv, low_move, low_score, low_mate = self.history2[-1] # last evaluation = for current user move
low_pv, low_move, low_score, low_mate = self.history2[
-1
] # last evaluation = for current user move
except IndexError:
low_score = 0.0
eval_string = ""
Expand Down Expand Up @@ -665,7 +673,11 @@ def get_user_move_eval(self):
eval_string = "?"

# Dubious
elif best_deep_diff > c.DUBIOUS_TH and abs(deep_low_diff) > c.UNCLEAR_DIFF and score_hist_diff > c.POS_INCREASE:
elif (
best_deep_diff > c.DUBIOUS_TH
and abs(deep_low_diff) > c.UNCLEAR_DIFF
and score_hist_diff > c.POS_INCREASE
):
eval_string = "?!"

###############################################################
Expand All @@ -681,7 +693,9 @@ def get_user_move_eval(self):
eval_string2 = "!!"

# good move
elif best_deep_diff <= c.GOOD_MOVE_TH and deep_low_diff > c.GOOD_IMPROVE_TH and legal_no > 1:
elif (
best_deep_diff <= c.GOOD_MOVE_TH and deep_low_diff > c.GOOD_IMPROVE_TH and legal_no > 1
):
eval_string2 = "!"

# interesting move
Expand Down

0 comments on commit 83905de

Please sign in to comment.