Skip to content

Commit

Permalink
Merge pull request #130 from lemonsqueeze/my
Browse files Browse the repository at this point in the history
2020 fixes
  • Loading branch information
lemonsqueeze authored Apr 8, 2020
2 parents 02c4d33 + 8fdc36d commit 0c30135
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 106 deletions.
1 change: 1 addition & 0 deletions board.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ FB_ONLY(int moveno)[BOARD_MAX_COORDS]; /* Move number for each coord */
#endif

#define board_stride(b) (board_rsize(b) + 2)
#define board_rsize2(b) (board_rsize(b) * board_rsize(b))


/* This is a shortcut for taking different action on smaller and large boards
Expand Down
85 changes: 50 additions & 35 deletions distributed/distributed.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,46 +454,61 @@ distributed_dead_groups(engine_t *e, board_t *b, move_queue_t *mq)
protocol_unlock();
}

#define NEED_RESET ENGINE_SETOPTION_NEED_RESET
#define option_error engine_setoption_error

static bool
distributed_setoption(engine_t *e, board_t *b, const char *optname, char *optval,
char **err, bool setup, bool *reset)
{
static_strbuf(ebuf, 256);
distributed_t *dist = (distributed_t*)e->data;

if (!strcasecmp(optname, "slave_port") && optval) { NEED_RESET
dist->slave_port = strdup(optval);
}
else if (!strcasecmp(optname, "proxy_port") && optval) { NEED_RESET
dist->proxy_port = strdup(optval);
}
else if (!strcasecmp(optname, "max_slaves") && optval) { NEED_RESET
dist->max_slaves = atoi(optval);
}
else if (!strcasecmp(optname, "shared_nodes") && optval) { NEED_RESET
/* Share at most shared_nodes between master and slave at each genmoves.
* Must use the same value in master and slaves. */
dist->shared_nodes = atoi(optval);
}
else if (!strcasecmp(optname, "stats_hbits") && optval) { NEED_RESET
/* Set hash table size to 2^stats_hbits for the shared stats. */
dist->stats_hbits = atoi(optval);
}
else if (!strcasecmp(optname, "slaves_quit")) { NEED_RESET
dist->slaves_quit = !optval || atoi(optval);
}
else
option_error("Distributed: Invalid engine argument %s or missing value\n", optname);

return true; /* successful */
}


static distributed_t *
distributed_state_init(char *arg, board_t *b)
distributed_state_init(engine_t *e, board_t *b)
{
options_t *options = &e->options;
distributed_t *dist = calloc2(1, distributed_t);
e->data = dist;

dist->stats_hbits = DEFAULT_STATS_HBITS;
dist->max_slaves = DEFAULT_MAX_SLAVES;
dist->shared_nodes = DEFAULT_SHARED_NODES;
if (arg) {
char *optspec, *next = arg;
while (*next) {
optspec = next;
next += strcspn(next, ",");
if (*next) { *next++ = 0; } else { *next = 0; }

char *optname = optspec;
char *optval = strchr(optspec, '=');
if (optval) *optval++ = 0;

if (!strcasecmp(optname, "slave_port") && optval) {
dist->slave_port = strdup(optval);
} else if (!strcasecmp(optname, "proxy_port") && optval) {
dist->proxy_port = strdup(optval);
} else if (!strcasecmp(optname, "max_slaves") && optval) {
dist->max_slaves = atoi(optval);
} else if (!strcasecmp(optname, "shared_nodes") && optval) {
/* Share at most shared_nodes between master and slave at each genmoves.
* Must use the same value in master and slaves. */
dist->shared_nodes = atoi(optval);
} else if (!strcasecmp(optname, "stats_hbits") && optval) {
/* Set hash table size to 2^stats_hbits for the shared stats. */
dist->stats_hbits = atoi(optval);
} else if (!strcasecmp(optname, "slaves_quit")) {
dist->slaves_quit = !optval || atoi(optval);
} else {
fprintf(stderr, "distributed: Invalid engine argument %s or missing value\n", optname);
}
}
}

/* Process engine options. */
char *err;
for (int i = 0; i < options->n; i++)
if (!engine_setoption(e, b, &options->o[i], &err, true, NULL))
die("%s", err);

gtp_replies = calloc2(dist->max_slaves, char *);

if (!dist->slave_port)
Expand All @@ -506,9 +521,8 @@ distributed_state_init(char *arg, board_t *b)
}

void
engine_distributed_init(engine_t *e, char *arg, board_t *b)
engine_distributed_init(engine_t *e, board_t *b)
{
distributed_t *dist = distributed_state_init(arg, b);
e->name = "Distributed";
e->comment = "If you believe you have won but I am still playing, "
"please help me understand by capturing all dead stones. "
Expand All @@ -517,7 +531,8 @@ engine_distributed_init(engine_t *e, char *arg, board_t *b)
e->genmove = distributed_genmove;
e->dead_groups = distributed_dead_groups;
e->chat = distributed_chat;
e->data = dist;
// Keep the threads and the open socket connections:
e->keep_on_clear = true;
e->setoption = distributed_setoption;
distributed_state_init(e, b);
}
2 changes: 1 addition & 1 deletion distributed/distributed.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ typedef struct {
#define reply_disabled(id) ((id) < DIST_GAMELEN)

char *path2sstr(path_t path, board_t *b);
void engine_distributed_init(engine_t *e, char *arg, board_t *b);
void engine_distributed_init(engine_t *e, board_t *b);

#endif
8 changes: 6 additions & 2 deletions gtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,17 @@ cmd_undo(board_t *b, engine_t *e, time_info_t *ti, gtp_t *gtp)
}

static void
undo_reload_engine(gtp_t *gtp, board_t *b, engine_t *e)
undo_reload_engine(gtp_t *gtp, board_t *b, engine_t *e, time_info_t *ti)
{
if (DEBUGL(3)) fprintf(stderr, "reloading engine after undo(s).\n");

gtp->undo_pending = false;

engine_reset(e, b);

/* Reset timer */
ti[S_BLACK].len.t.timer_start = 0;
ti[S_WHITE].len.t.timer_start = 0;

/* Reset board */
int handicap = b->handicap;
Expand Down Expand Up @@ -1087,7 +1091,7 @@ gtp_parse(gtp_t *gtp, board_t *b, engine_t *e, time_info_t *ti, char *buf)

/* Undo: reload engine after first non-undo command. */
if (gtp->undo_pending && strcasecmp(gtp->cmd, "undo"))
undo_reload_engine(gtp, b, e);
undo_reload_engine(gtp, b, e, ti);

if (e->notify && gtp_is_valid(e, gtp->cmd)) {
char *reply;
Expand Down
2 changes: 1 addition & 1 deletion kgs/kgsgtp-pachi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# -t =5000 for fixed number of playouts etc.
#

engine=./pachi --kgs -t =5000:15000 resign_threshold=0.25,banner=%s.+Have+a+nice+game!
engine=./pachi --kgs -t =5000:15000 -o pachi.log resign_threshold=0.25,banner=%s.+Have+a+nice+game!
name=KGSNAME
password=PASSWORD
room=Computer Go
Expand Down
4 changes: 2 additions & 2 deletions ownermap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ printhook(board_t *board, coord_t c, strbuf_t *buf, void *data)

if (c == pass) { /* Stuff to display in header */
if (!ownermap || !ownermap->playouts) return;
sbprintf(buf, "Score Est: %s\n", ownermap_score_est_str(board, ownermap));
sbprintf(buf, "Score Est: %s", ownermap_score_est_str(board, ownermap));
return;
}

Expand All @@ -39,7 +39,7 @@ printhook(board_t *board, coord_t c, strbuf_t *buf, void *data)
void
board_print_ownermap(board_t *b, FILE *f, ownermap_t *ownermap)
{
board_print_custom(b, stderr, printhook, ownermap);
board_print_custom(b, f, printhook, ownermap);
}

void
Expand Down
2 changes: 1 addition & 1 deletion ownermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool board_position_final_full(board_t *b, ownermap_t *ownermap,

/* Don't allow passing earlier than that:
* 19x19: 120 15x15: 56 13x13: 33 9x9: 16 */
#define board_earliest_pass(b) (board_max_coords(b) / (7 - 2 * board_rsize(b) / 9))
#define board_earliest_pass(b) (board_rsize2(b) / (7 - 2 * board_rsize(b) / 9))


#endif
12 changes: 9 additions & 3 deletions pachi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int debug_level = 3;
bool debug_boardprint = true;
long verbose_logs = 0;
char *forced_ruleset = NULL;
bool nopassfirst = false;

static char *gtp_port = NULL;
static bool nopassfirst = false;
static int accurate_scoring_wanted = 0;

static void
Expand All @@ -58,6 +58,12 @@ network_init()
#endif
}

bool
pachi_nopassfirst(board_t *b)
{
return (nopassfirst && b->rules == RULES_CHINESE);
}

bool
pachi_set_rules(gtp_t *gtp, board_t *b, const char *name)
{
Expand Down Expand Up @@ -141,7 +147,7 @@ usage()
" --accurate-scoring use GnuGo to compute dead stones at the end. otherwise expect \n"
" ~5%% games to be scored incorrectly. recommended for online play \n"
" -c, --chatfile FILE set kgs chatfile \n"
" --nopassfirst don't pass first \n"
" --nopassfirst don't pass first when playing chinese \n"
" --kgs use this when playing on kgs, \n"
" enables --nopassfirst, and --accurate-scoring if gnugo is found \n"
"Logs / IO: \n"
Expand Down Expand Up @@ -172,7 +178,7 @@ usage()
" -t, --time TIME_SETTINGS force basic time settings (override kgs/gtp time settings) \n"
" --fuseki-time TIME_SETTINGS specific time settings to use during fuseki \n"
" --fuseki MOVES set fuseki length for --fuseki-time \n"
" default: 19x19: 20 15x15: 10 13x13: 7 9x9: 4 \n"
" default: 19x19: 10 15x15: 7 9x9: 4 \n"
" \n"
" TIME_SETTINGS: \n"
" =SIMS fixed number of Monte-Carlo simulations per move \n"
Expand Down
5 changes: 3 additions & 2 deletions pachi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extern char *pachi_exe;
/* Ruleset from cmdline, if present. */
extern char *forced_ruleset;

/* Don't pass first ? Needed on kgs or cleanup phase can be abused. */
extern bool nopassfirst;
/* Don't pass first ? Needed when playing chinese rules on kgs or cleanup phase can be abused. */
bool pachi_nopassfirst(struct board *b);


#endif
2 changes: 1 addition & 1 deletion patternprob.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ print_pattern_best_moves(board_t *b, coord_t *best_c, float *best_r, int nbest)
}

void
get_pattern_best_moves(board_t *b, float *probs, coord_t *best_c, float *best_r, int nbest)
get_pattern_best_moves(board_t *b, floating_t *probs, coord_t *best_c, float *best_r, int nbest)
{
for (int i = 0; i < nbest; i++) {
best_c[i] = pass; best_r[i] = 0;
Expand Down
2 changes: 1 addition & 1 deletion patternprob.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool pattern_matching_locally(pattern_config_t *pc,
ownermap_t *ownermap);

void print_pattern_best_moves(board_t *b, coord_t *best_c, float *best_r, int nbest);
void get_pattern_best_moves(board_t *b, float *probs, coord_t *best_c, float *best_r, int nbest);
void get_pattern_best_moves(board_t *b, floating_t *probs, coord_t *best_c, float *best_r, int nbest);

/* Debugging */
void dump_gammas(strbuf_t *buf, pattern_config_t *pc, pattern_t *p);
Expand Down
1 change: 1 addition & 0 deletions random.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/********************************************************************************************/
#ifdef _WIN32
#include <windows.h>

/* Use TlsGetValue() / TlsSetValue() for thread-local storage,
* mingw-w64's __thread is painfully slow. */
Expand Down
28 changes: 25 additions & 3 deletions t-unit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ show_title_if_needed(int passed)


static bool
test_sar(board_t *b, char *arg)
test_selfatari(board_t *b, char *arg)
{
next_arg(arg);
enum stone color = str2stone(arg);
Expand All @@ -200,7 +200,7 @@ test_sar(board_t *b, char *arg)
int eres = atoi(arg);
args_end();

PRINT_TEST(b, "sar %s %s %d...\t", stone2str(color), coord2sstr(c), eres);
PRINT_TEST(b, "selfatari %s %s %d...\t", stone2str(color), coord2sstr(c), eres);

assert(board_at(b, c) == S_NONE);
int rres = is_bad_selfatari(b, color, c);
Expand All @@ -209,6 +209,26 @@ test_sar(board_t *b, char *arg)
return (rres == eres);
}

static bool
test_selfatari_really_bad(board_t *b, char *arg)
{
next_arg(arg);
enum stone color = str2stone(arg);
next_arg(arg);
coord_t c = str2coord(arg);
next_arg(arg);
int eres = atoi(arg);
args_end();

PRINT_TEST(b, "selfatari_really_bad %s %s %d...\t", stone2str(color), coord2sstr(c), eres);

assert(board_at(b, c) == S_NONE);
int rres = is_really_bad_selfatari(b, color, c);

PRINT_RES(rres == eres);
return (rres == eres);
}

static bool
test_corner_seki(board_t *b, char *arg)
{
Expand Down Expand Up @@ -570,7 +590,9 @@ typedef struct {
} t_unit_cmd;

static t_unit_cmd commands[] = {
{ "sar", test_sar, 1 },
{ "selfatari", test_selfatari, 1 },
{ "sar", test_selfatari, 1 }, /* alias */
{ "selfatari_really_bad", test_selfatari_really_bad, 1 },
{ "ladder", test_ladder, 1 },
{ "ladder_any", test_ladder_any, 1 },
{ "wouldbe_ladder", test_wouldbe_ladder, 1 },
Expand Down
4 changes: 2 additions & 2 deletions tactics/seki.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef PACHI_TACTICS_SEKI_H
#define PACHI_TACTICS_SEKI_H

#define MOGGY_MIDDLEGAME (board_rsize(b) * board_rsize(b) * 10 / 25) /* 19x19: 144 */
#define MOGGY_ENDGAME (board_rsize(b) * board_rsize(b) * 100 / 164) /* 19x19: 220 */
#define MOGGY_MIDDLEGAME (board_rsize2(b) * 10 / 25) /* 19x19: 144 */
#define MOGGY_ENDGAME (board_rsize2(b) * 100 / 164) /* 19x19: 220 */

#define check_special_sekis(b, m) \
(b->moves > MOGGY_MIDDLEGAME && !immediate_liberty_count(b, m->coord))
Expand Down
11 changes: 7 additions & 4 deletions timeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "ownermap.h"
#include "timeinfo.h"

#ifdef _WIN32
#include <windows.h>
#endif

/* Max net lag in seconds. TODO: estimate dynamically. */
#define MAX_NET_LAG 2.0
/* Minimal thinking time; in case reserved time gets smaller than MAX_NET_LAG,
Expand Down Expand Up @@ -478,10 +482,9 @@ fuseki_moves(board_t *b)
if (opt_fuseki_moves)
return opt_fuseki_moves;

int moves = 20;
if (board_rsize(b) <= 15) moves = 10;
if (board_rsize(b) <= 13) moves = 7;
if (board_small(b)) moves = 4;
int moves = 10;
if (board_rsize(b) <= 15) moves = 7;
if (board_small(b)) moves = 4;
return moves;
}

Expand Down
1 change: 1 addition & 0 deletions uct/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ typedef struct uct {

/* Used within frame of single genmove. */
ownermap_t ownermap;
bool allow_pass; /* allow pass in uct descent */

/* Used for coordination among slaves of the distributed engine. */
int stats_hbits;
Expand Down
Loading

0 comments on commit 0c30135

Please sign in to comment.