Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gomoku/agentmcts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ AgentMCTS::AgentMCTS() : pool(this) {
visitexpand = 1;
prunesymmetry = false;
gcsolved = 100000;
longestloss = false;

localreply = 0;
locality = 0;
Expand Down
2 changes: 2 additions & 0 deletions gomoku/agentmcts.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class AgentMCTS : public Agent{
uint visitexpand;//number of visits before expanding a node
bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
uint gcsolved; //garbage collect solved nodes or keep them in the tree, assuming they meet the required amount of work
bool longestloss;//tells us how to proceed if we have a proved lose, if true aim for the longest lose, if false try for hardest lose to solve


//knowledge
int localreply; //boost for a local reply, ie a move near the previous move
Expand Down
41 changes: 29 additions & 12 deletions gomoku/agentmctsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
return false;


uint8_t proofdepth = backup->proofdepth;
uint8_t proofdepth = backup->proofdepth+1;
if(backup->outcome != toplay){
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0;
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0,
depth = 0, bestdepth = 0;//depending on longestlose setting we care about either sims or depth

backup = NULL;

Node * child = node->children.begin(),
Expand Down Expand Up @@ -287,16 +289,31 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
assert(false && "How'd I get here? All outcomes should be tested above");
}

sims = child->exp.num();
if(best_outcome < outcome){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || bestsims > sims)){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
//longestloss tells us how to handle the case where we have a known loss
if(longestloss){
depth = child->proofdepth;
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestdepth = depth;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestdepth < depth) || (outcome != 0 && bestdepth > depth))){
//find long losses or easy wins/draws
bestdepth = depth;
backup = child;
}
}
else{
sims = child->exp.num();
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || (outcome != 0 && bestsims > sims))){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
}
}

if(best_outcome == 3) //no win, but found an unknown
Expand Down
8 changes: 6 additions & 2 deletions gomoku/gtpagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GTPResponse GTP::gtp_solve(vecstr args){

double use_time = (args.size() >= 1 ?
from_str<double>(args[0]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));

if(verbose)
logerr("time remain: " + to_str(time_control.remain, 1) + ", time: " + to_str(use_time, 3) + ", sims: " + to_str(time_control.max_sims) + "\n");
Expand All @@ -47,7 +47,7 @@ GTPResponse GTP::gtp_genmove(vecstr args){

double use_time = (args.size() >= 2 ?
from_str<double>(args[1]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));


if(verbose)
Expand Down Expand Up @@ -144,6 +144,8 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
" -x --visitexpand Number of visits before expanding a node [" + to_str(mcts->visitexpand) + "]\n" +
" -P --symmetry Prune symmetric moves, good for proof, not play [" + to_str(mcts->prunesymmetry) + "]\n" +
" --gcsolved Garbage collect solved nodes with fewer sims than [" + to_str(mcts->gcsolved) + "]\n" +
" -L --longestloss For known losses take longest over hardest solve [" + to_str(mcts->longestloss)+"]\n"+

"Node initialization knowledge, Give a bonus:\n" +
" -l --localreply based on the distance to the previous move [" + to_str(mcts->localreply) + "]\n" +
" -y --locality to stones near other stones of the same color [" + to_str(mcts->locality) + "]\n" +
Expand Down Expand Up @@ -190,6 +192,8 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
mcts->minimax = from_str<int>(args[++i]);
}else if((arg == "-P" || arg == "--symmetry") && i+1 < args.size()){
mcts->prunesymmetry = from_str<bool>(args[++i]);
}else if((arg == "-L" || arg == "--longestloss") && i+1 < args.size()){
mcts->longestloss = from_str<bool>(args[++i]);
}else if(( arg == "--gcsolved") && i+1 < args.size()){
mcts->gcsolved = from_str<uint>(args[++i]);
}else if((arg == "-r" || arg == "--userave") && i+1 < args.size()){
Expand Down
2 changes: 2 additions & 0 deletions havannah/agentmcts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ AgentMCTS::AgentMCTS() : pool(this) {
visitexpand = 1;
prunesymmetry = false;
gcsolved = 100000;
longestloss = false;


localreply = 0;
locality = 0;
Expand Down
2 changes: 2 additions & 0 deletions havannah/agentmcts.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class AgentMCTS : public Agent{
uint visitexpand;//number of visits before expanding a node
bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
uint gcsolved; //garbage collect solved nodes or keep them in the tree, assuming they meet the required amount of work
bool longestloss;//tells us how to proceed if we have a proved lose, if true aim for the longest lose, if false try for hardest lose to solve


//knowledge
int localreply; //boost for a local reply, ie a move near the previous move
Expand Down
41 changes: 29 additions & 12 deletions havannah/agentmctsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
return false;


uint8_t proofdepth = backup->proofdepth;
uint8_t proofdepth = backup->proofdepth+1;
if(backup->outcome != toplay){
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0;
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0,
depth = 0, bestdepth = 0;//depending on longestlose setting we care about either sims or depth

backup = NULL;

Node * child = node->children.begin(),
Expand Down Expand Up @@ -301,16 +303,31 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
assert(false && "How'd I get here? All outcomes should be tested above");
}

sims = child->exp.num();
if(best_outcome < outcome){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || bestsims > sims)){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
//longestloss tells us how to handle the case where we have a known loss
if(longestloss){
depth = child->proofdepth;
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestdepth = depth;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestdepth < depth) || (outcome != 0 && bestdepth > depth))){
//find long losses or easy wins/draws
bestdepth = depth;
backup = child;
}
}
else{
sims = child->exp.num();
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || (outcome != 0 && bestsims > sims))){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
}
}

if(best_outcome == 3) //no win, but found an unknown
Expand Down
8 changes: 6 additions & 2 deletions havannah/gtpagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GTPResponse GTP::gtp_solve(vecstr args){

double use_time = (args.size() >= 1 ?
from_str<double>(args[0]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));

if(verbose)
logerr("time remain: " + to_str(time_control.remain, 1) + ", time: " + to_str(use_time, 3) + ", sims: " + to_str(time_control.max_sims) + "\n");
Expand All @@ -47,7 +47,7 @@ GTPResponse GTP::gtp_genmove(vecstr args){

double use_time = (args.size() >= 2 ?
from_str<double>(args[1]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));


if(verbose)
Expand Down Expand Up @@ -145,6 +145,8 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
" -x --visitexpand Number of visits before expanding a node [" + to_str(mcts->visitexpand) + "]\n" +
" -P --symmetry Prune symmetric moves, good for proof, not play [" + to_str(mcts->prunesymmetry) + "]\n" +
" --gcsolved Garbage collect solved nodes with fewer sims than [" + to_str(mcts->gcsolved) + "]\n" +
" -L --longestloss For known losses take longest over hardest solve [" + to_str(mcts->longestloss)+"]\n"+

"Node initialization knowledge, Give a bonus:\n" +
" -l --localreply based on the distance to the previous move [" + to_str(mcts->localreply) + "]\n" +
" -y --locality to stones near other stones of the same color [" + to_str(mcts->locality) + "]\n" +
Expand Down Expand Up @@ -201,6 +203,8 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
mcts->detectdraw = from_str<bool>(args[++i]);
}else if((arg == "-P" || arg == "--symmetry") && i+1 < args.size()){
mcts->prunesymmetry = from_str<bool>(args[++i]);
}else if((arg == "-L" || arg == "--longestloss") && i+1 < args.size()){
mcts->longestloss = from_str<bool>(args[++i]);
}else if(( arg == "--gcsolved") && i+1 < args.size()){
mcts->gcsolved = from_str<uint>(args[++i]);
}else if((arg == "-r" || arg == "--userave") && i+1 < args.size()){
Expand Down
1 change: 1 addition & 0 deletions hex/agentmcts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ AgentMCTS::AgentMCTS() : pool(this) {
visitexpand = 1;
prunesymmetry = false;
gcsolved = 100000;
longestloss = false;

localreply = 5;
locality = 5;
Expand Down
1 change: 1 addition & 0 deletions hex/agentmcts.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class AgentMCTS : public Agent{
uint visitexpand;//number of visits before expanding a node
bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
uint gcsolved; //garbage collect solved nodes or keep them in the tree, assuming they meet the required amount of work
bool longestloss;//tells us how to proceed if we have a proved lose, if true aim for the longest lose, if false try for hardest lose to solve

//knowledge
int localreply; //boost for a local reply, ie a move near the previous move
Expand Down
40 changes: 28 additions & 12 deletions hex/agentmctsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
return false;


uint8_t proofdepth = backup->proofdepth;
uint8_t proofdepth = backup->proofdepth+1;
if(backup->outcome != toplay){
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0;
uint64_t sims = 0, bestsims = 0, outcome = 0, best_outcome = 0,
depth = 0, bestdepth = 0;//depending on longestlose setting we care about either sims or depth
backup = NULL;

Node * child = node->children.begin(),
Expand Down Expand Up @@ -290,16 +291,31 @@ bool AgentMCTS::do_backup(Node * node, Node * backup, Side toplay){
assert(false && "How'd I get here? All outcomes should be tested above");
}

sims = child->exp.num();
if(best_outcome < outcome){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || bestsims > sims)){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
//longestloss tells us how to handle the case where we have a known loss
if(longestloss){
depth = child->proofdepth;
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestdepth = depth;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestdepth < depth) || (outcome != 0 && bestdepth > depth))){
//find long losses or easy wins/draws
bestdepth = depth;
backup = child;
}
}
else{
sims = child->exp.num();
if(best_outcome < outcome || backup == NULL){ //better outcome is always preferable
best_outcome = outcome;
bestsims = sims;
backup = child;
}else if(best_outcome == outcome && ((outcome == 0 && bestsims < sims) || (outcome != 0 && bestsims > sims))){
//find long losses or easy wins/draws
bestsims = sims;
backup = child;
}
}
}

if(best_outcome == 3) //no win, but found an unknown
Expand Down
7 changes: 5 additions & 2 deletions hex/gtpagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GTPResponse GTP::gtp_solve(vecstr args){

double use_time = (args.size() >= 1 ?
from_str<double>(args[0]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));

if(verbose)
logerr("time remain: " + to_str(time_control.remain, 1) + ", time: " + to_str(use_time, 3) + ", sims: " + to_str(time_control.max_sims) + "\n");
Expand All @@ -47,7 +47,7 @@ GTPResponse GTP::gtp_genmove(vecstr args){

double use_time = (args.size() >= 2 ?
from_str<double>(args[1]) :
time_control.get_time(hist.len(), hist->movesremain(), agent->gamelen()));
time_control.get_time(hist->movesremain(), agent->gamelen()));


if(verbose)
Expand Down Expand Up @@ -144,6 +144,7 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
" -x --visitexpand Number of visits before expanding a node [" + to_str(mcts->visitexpand) + "]\n" +
" -P --symmetry Prune symmetric moves, good for proof, not play [" + to_str(mcts->prunesymmetry) + "]\n" +
" --gcsolved Garbage collect solved nodes with fewer sims than [" + to_str(mcts->gcsolved) + "]\n" +
" -L --longestloss For known losses take longest over hardest solve [" + to_str(mcts->longestloss)+"]\n"+
"Node initialization knowledge, Give a bonus:\n" +
" -l --localreply based on the distance to the previous move [" + to_str(mcts->localreply) + "]\n" +
" -y --locality to stones near other stones of the same color [" + to_str(mcts->locality) + "]\n" +
Expand Down Expand Up @@ -196,6 +197,8 @@ GTPResponse GTP::gtp_mcts_params(vecstr args){
mcts->minimax = from_str<int>(args[++i]);
}else if((arg == "-P" || arg == "--symmetry") && i+1 < args.size()){
mcts->prunesymmetry = from_str<bool>(args[++i]);
}else if((arg == "-L" || arg == "--longestloss") && i+1 < args.size()){
mcts->longestloss = from_str<bool>(args[++i]);
}else if(( arg == "--gcsolved") && i+1 < args.size()){
mcts->gcsolved = from_str<uint>(args[++i]);
}else if((arg == "-r" || arg == "--userave") && i+1 < args.size()){
Expand Down
6 changes: 3 additions & 3 deletions lib/timecontrol.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once

#include <algorithm>
Expand Down Expand Up @@ -39,7 +39,7 @@ struct TimeControl {
remain = game;
}

double get_time(int moves_made, int moves_max, int moves_remain_estimate) {
double get_time(int max_moves_remaining, int moves_remain_estimate) {
double ret = 0;

switch(method){
Expand All @@ -52,7 +52,7 @@ struct TimeControl {
break;
}//fall back to even
case EVEN:
ret += 2.0 * param * remain / (moves_max - moves_made);
ret += 2.0 * param * remain / max_moves_remaining;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions pentago/gtpagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GTPResponse GTP::gtp_solve(vecstr args){

double use_time = (args.size() >= 1 ?
from_str<double>(args[0]) :
time_control.get_time(hist.len(), hist->moves_remain(), agent->gamelen()));
time_control.get_time(hist->moves_remain(), agent->gamelen()));

if(verbose)
logerr("time remain: " + to_str(time_control.remain, 1) + ", time: " + to_str(use_time, 3) + ", sims: " + to_str(time_control.max_sims) + "\n");
Expand All @@ -47,7 +47,7 @@ GTPResponse GTP::gtp_genmove(vecstr args){

double use_time = (args.size() >= 2 ?
from_str<double>(args[1]) :
time_control.get_time(hist.len(), hist->moves_remain(), agent->gamelen()));
time_control.get_time(hist->moves_remain(), agent->gamelen()));


if(verbose)
Expand Down
1 change: 1 addition & 0 deletions rex/agentmcts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ AgentMCTS::AgentMCTS() : pool(this) {
visitexpand = 1;
prunesymmetry = false;
gcsolved = 100000;
longestloss = false;

localreply = 5;
locality = 5;
Expand Down
1 change: 1 addition & 0 deletions rex/agentmcts.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class AgentMCTS : public Agent{
uint visitexpand;//number of visits before expanding a node
bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
uint gcsolved; //garbage collect solved nodes or keep them in the tree, assuming they meet the required amount of work
bool longestloss;//tells us how to proceed if we have a proved lose, if true aim for the longest lose, if false try for hardest lose to solve

//knowledge
int localreply; //boost for a local reply, ie a move near the previous move
Expand Down
Loading