From 80d2ed7cd7503de881893fccba9e30e98106bf2a Mon Sep 17 00:00:00 2001 From: Ofek Shochat Date: Mon, 8 Feb 2021 12:24:50 +0200 Subject: [PATCH 1/4] real fuging pv --- search/uct.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/search/uct.py b/search/uct.py index 34d7db8..d5406ab 100644 --- a/search/uct.py +++ b/search/uct.py @@ -67,10 +67,23 @@ def get_best_move(root): score = int(round(cp(node.Q()),0)) return bestmove, node, score +def getBest(node): + bestmove, node = max(node.children.items(), key=lambda item: (item[1].number_visits, item[1].Q())) + return bestmove, node + def send_info(send, bestmove, count, delta, score): if send != None: send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) +def pv(root): + pv = "" + current = root + while current.is_expanded: + bestmove, node = getBest(current) + pv += bestmove + " " + current = node + return pv + def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, tree=None, send=None): if max_time == None: # search for a maximum of an hour @@ -93,7 +106,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if (delta - delta_last > 5): delta_last = delta bestmove, node, score = get_best_move(root) - send_info(send, bestmove, count, delta, score) + send_info(send, pv(root), count, delta, score) if (time != None) and (delta > max_time): break @@ -102,7 +115,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if send != None: for nd in sorted(root.children.items(), key= lambda item: item[1].number_visits): send("info string {} {} \t(P: {}%) \t(Q: {})".format(nd[1].move, nd[1].number_visits, round(nd[1].prior*100,2), round(nd[1].Q(), 5))) - send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) + send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), pv(root))) # if we have a bad score, go for a draw return bestmove, score From 4c477f9fd22069449fe839df4080a4fa0ed0e925 Mon Sep 17 00:00:00 2001 From: Ofek Shochat Date: Mon, 8 Feb 2021 12:39:11 +0200 Subject: [PATCH 2/4] Update uct.py --- search/uct.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/search/uct.py b/search/uct.py index d5406ab..34d7db8 100644 --- a/search/uct.py +++ b/search/uct.py @@ -67,23 +67,10 @@ def get_best_move(root): score = int(round(cp(node.Q()),0)) return bestmove, node, score -def getBest(node): - bestmove, node = max(node.children.items(), key=lambda item: (item[1].number_visits, item[1].Q())) - return bestmove, node - def send_info(send, bestmove, count, delta, score): if send != None: send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) -def pv(root): - pv = "" - current = root - while current.is_expanded: - bestmove, node = getBest(current) - pv += bestmove + " " - current = node - return pv - def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, tree=None, send=None): if max_time == None: # search for a maximum of an hour @@ -106,7 +93,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if (delta - delta_last > 5): delta_last = delta bestmove, node, score = get_best_move(root) - send_info(send, pv(root), count, delta, score) + send_info(send, bestmove, count, delta, score) if (time != None) and (delta > max_time): break @@ -115,7 +102,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if send != None: for nd in sorted(root.children.items(), key= lambda item: item[1].number_visits): send("info string {} {} \t(P: {}%) \t(Q: {})".format(nd[1].move, nd[1].number_visits, round(nd[1].prior*100,2), round(nd[1].Q(), 5))) - send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), pv(root))) + send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) # if we have a bad score, go for a draw return bestmove, score From 44de574cb6e37c9273c5c8bc03b34213f9859f71 Mon Sep 17 00:00:00 2001 From: Ofek Shochat Date: Mon, 8 Feb 2021 12:42:21 +0200 Subject: [PATCH 3/4] Update uct.py --- search/uct.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/search/uct.py b/search/uct.py index 34d7db8..d5406ab 100644 --- a/search/uct.py +++ b/search/uct.py @@ -67,10 +67,23 @@ def get_best_move(root): score = int(round(cp(node.Q()),0)) return bestmove, node, score +def getBest(node): + bestmove, node = max(node.children.items(), key=lambda item: (item[1].number_visits, item[1].Q())) + return bestmove, node + def send_info(send, bestmove, count, delta, score): if send != None: send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) +def pv(root): + pv = "" + current = root + while current.is_expanded: + bestmove, node = getBest(current) + pv += bestmove + " " + current = node + return pv + def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, tree=None, send=None): if max_time == None: # search for a maximum of an hour @@ -93,7 +106,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if (delta - delta_last > 5): delta_last = delta bestmove, node, score = get_best_move(root) - send_info(send, bestmove, count, delta, score) + send_info(send, pv(root), count, delta, score) if (time != None) and (delta > max_time): break @@ -102,7 +115,7 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if send != None: for nd in sorted(root.children.items(), key= lambda item: item[1].number_visits): send("info string {} {} \t(P: {}%) \t(Q: {})".format(nd[1].move, nd[1].number_visits, round(nd[1].prior*100,2), round(nd[1].Q(), 5))) - send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) + send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), pv(root))) # if we have a bad score, go for a draw return bestmove, score From c2c92d977db8ee4c3c45950528ca71dea6fa0c55 Mon Sep 17 00:00:00 2001 From: Ofek Shochat Date: Mon, 8 Feb 2021 12:47:18 +0200 Subject: [PATCH 4/4] Update uct.py --- search/uct.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/search/uct.py b/search/uct.py index d5406ab..08f3699 100644 --- a/search/uct.py +++ b/search/uct.py @@ -73,16 +73,18 @@ def getBest(node): def send_info(send, bestmove, count, delta, score): if send != None: - send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), bestmove)) + send("info depth {} seldepth 1 score cp {} nodes {} nps {} pv {}".format(bestmove[1], score, count, int(round(count/delta, 0)), bestmove[0])) def pv(root): + d = 0 pv = "" current = root while current.is_expanded: + d += 1 bestmove, node = getBest(current) pv += bestmove + " " current = node - return pv + return pv, d def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, tree=None, send=None): if max_time == None: @@ -115,7 +117,8 @@ def UCT_search(board, num_reads, net=None, C=1.0, verbose=False, max_time=None, if send != None: for nd in sorted(root.children.items(), key= lambda item: item[1].number_visits): send("info string {} {} \t(P: {}%) \t(Q: {})".format(nd[1].move, nd[1].number_visits, round(nd[1].prior*100,2), round(nd[1].Q(), 5))) - send("info depth 1 seldepth 1 score cp {} nodes {} nps {} pv {}".format(score, count, int(round(count/delta, 0)), pv(root))) + pa, d = pv(root) + send("info depth {} seldepth 1 score cp {} nodes {} nps {} pv {}".format(d, score, count, int(round(count/delta, 0)), pa[0])) # if we have a bad score, go for a draw return bestmove, score