Skip to content

Commit

Permalink
Merge pull request #94 from gonmf/develop
Browse files Browse the repository at this point in the history
1.22 to 1.23
  • Loading branch information
gonmf authored Oct 23, 2016
2 parents 2e362e0 + 0835f0e commit 25e7869
Show file tree
Hide file tree
Showing 37 changed files with 353 additions and 320 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Matilda is a competitive computer Go playing engine and accompanying software. G

Implementation-wise Matilda is a MCTS Mogo-like program. It is aimed at 64 bit computers in shared memory, playing with Chinese rules via the Go Text Protocol. It is versatile and optimized for speed in a lot of areas, though some changes require a recompilation.

The relative strength of Matilda can be seen from playing on the [CGOS](http://www.yss-aya.com/cgos/9x9/standings.html). It is currently much stronger in smaller boards than in larger ones.
The relative strength of Matilda can be seen from playing on the [CGOS](http://www.yss-aya.com/cgos/9x9/bayes.html). It is currently much stronger in smaller boards than in larger ones.

**System Requirements**

Expand Down
54 changes: 27 additions & 27 deletions clop/config.clop
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ Script ./goguiscript.py
# For GammaParameter, quadratic regression is performed on log(x)
# Warning: 123 and not 123.0 should be used for IntegerParameter

#LinearParameter prior_stone_scale_factor 1.0 1.6
#IntegerParameter prior_even 5 20
#IntegerParameter prior_nakade 36 108
#IntegerParameter prior_self_atari 1 32
#IntegerParameter prior_attack 20 63
#IntegerParameter prior_defend 5 20
#IntegerParameter prior_pat3 10 30
#IntegerParameter prior_near_last 1 15
#IntegerParameter prior_line2 29 88
#IntegerParameter prior_line3 30 90
#IntegerParameter prior_empty 22 57
#IntegerParameter prior_line1x 0 10
#IntegerParameter prior_line2x 0 10
#IntegerParameter prior_line3x 0 10
#IntegerParameter prior_corner 16 50
#IntegerParameter prior_bad_play 40 130
#IntegerParameter prior_pass 40 130

LinearParameter time_allot_factor 1.0 6.0

LinearParameter rave_equiv 1.0 4000.0
LinearParameter prior_stone_scale_factor 1.0 1.6
IntegerParameter prior_even 5 60
IntegerParameter prior_nakade 36 120
IntegerParameter prior_self_atari 1 62
IntegerParameter prior_attack 10 73
IntegerParameter prior_defend 2 40
IntegerParameter prior_pat3 4 50
IntegerParameter prior_near_last 1 30
IntegerParameter prior_line2 19 88
IntegerParameter prior_line3 10 90
IntegerParameter prior_empty 12 67
IntegerParameter prior_line1x 0 30
IntegerParameter prior_line2x 0 30
IntegerParameter prior_line3x 0 30
IntegerParameter prior_corner 6 70
IntegerParameter prior_bad_play 20 180
IntegerParameter prior_pass 20 200

# LinearParameter time_allot_factor 1.0 6.0

LinearParameter rave_equiv 1.0 5000.0

# Probabilities of skipping playout checks are 1:128 instead of percentage
# (1:100)
#IntegerParameter pl_skip_saving 0 128
#IntegerParameter pl_skip_nakade 0 128
#IntegerParameter pl_skip_capture 0 128
#IntegerParameter pl_skip_pattern 0 128
#IntegerParameter pl_ban_self_atari 0 128
IntegerParameter pl_skip_saving 0 128
# IntegerParameter pl_skip_nakade 0 128
IntegerParameter pl_skip_capture 0 128
IntegerParameter pl_skip_pattern 0 128
IntegerParameter pl_ban_self_atari 0 128

#IntegerParameter expansion_delay 0 8
IntegerParameter expansion_delay 0 8

#IntegerParameter dummy 0 100

Expand Down
8 changes: 4 additions & 4 deletions clop/goguiscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
#

# program to be optimized
optimized_program = '/home/user/Documents/go/matilda/github/src/matilda -d /home/user/Documents/go/matilda/github/src/data/ -m gtp -l'
optimized_program = '/home/user/Documents/go/matilda/branch-develop/src/matilda -d /home/user/Documents/go/matilda/branch-develop/src/data/ -m gtp -l --disable_opening_books --playouts 10000'
# --disable_opening_books
# --playouts 1000

# (fixed) opponent program
opponent_program = 'gnugo --mode gtp --chinese-rules --positional-superko --level 10'
#opponent_program = '/home/user/Documents/go/matilda/github/src/matilda -d /home/user/Documents/go/matilda/github/src/data/ -m gtp -l --disable_opening_books'
#opponent_program = 'gnugo --mode gtp --chinese-rules --positional-superko --level 10'
opponent_program = '/home/user/Documents/go/matilda/branch-develop/src/matilda -d /home/user/Documents/go/matilda/branch-develop/src/data/ -m gtp -l --disable_opening_books --playouts 10000'


i = 4
Expand All @@ -64,7 +64,7 @@
#
# Run one game with gogui-twogtp
#
command = 'gogui-twogtp -size 9 -komi 7.5 -white ' + optimized_program + ' -black ' + opponent_program + ' -sgffile twogtp.sgf -games 1 -auto -time 5s' # -time 2s'
command = 'gogui-twogtp -size 9 -komi 4.5 -white ' + optimized_program + ' -black ' + opponent_program + ' -sgffile twogtp.sgf -games 1 -auto' # -time 2s'

#print "command = ", command

Expand Down
43 changes: 33 additions & 10 deletions src/alloc.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
Guard functions over standard malloc. They are used for quickly and
inexpensively allocate a small buffer, with safety measures.
Fast memory allocation layer above standard malloc.
It is thread-safe, fast, and canary values are used (in debug mode) to ensure
These are meant to inexpensively allocate buffers for string operations.
They are thread-safe, fast, with canary values used (in debug mode) to ensure
memory is correctly freed and written to.
If you are need to perform recursive operations then use malloc/free. Releasing
these buffers does not actually free the underlying memory to be used by other
programs.
*/

#include "matilda.h"
Expand All @@ -28,8 +33,14 @@ static mem_link * queue = NULL;
static omp_lock_t queue_lock;
static bool queue_inited = false;

#if !MATILDA_RELEASE_MODE
static u16 concurrent_allocs = 0;
#define WARN_CONCURRENT_ALLOCS 16
#endif


/*
Initiate the safe allocation.
Initiate the safe allocation functions.
*/
void alloc_init()
{
Expand All @@ -41,15 +52,24 @@ void alloc_init()
}

/*
Allocate a small block of memory; intended for string formatting and the like.
Canary protection is used in debug mode.
Allocate a block of exactly MAX_PAGE_SIZ.
Thread-safe.
*/
void * alloc()
{
void * ret = NULL;

omp_set_lock(&queue_lock);

#if !MATILDA_RELEASE_MODE
concurrent_allocs++;
if(concurrent_allocs >= WARN_CONCURRENT_ALLOCS)
{
fprintf(stderr, "alloc: suspicious memory allocations number (%u)\n",
concurrent_allocs);
}
#endif

if(queue != NULL)
{
ret = queue;
Expand Down Expand Up @@ -101,9 +121,9 @@ s, rolling block releasing or writes past bounds (1)\n");
}

/*
Releases a previously allocated block of memory.
Canary protection is used in debug mode.
Releases a previously allocated block of memory, to be used again in later
calls. Does not free the memory.
Thread-safe.
*/
void release(void * ptr)
{
Expand All @@ -124,5 +144,8 @@ s, rolling block releasing or writes past bounds (2)\n");
mem_link * l = (mem_link *)ptr;
l->next = queue;
queue = l;
#if !MATILDA_RELEASE_MODE
--concurrent_allocs;
#endif
omp_unset_lock(&queue_lock);
}
4 changes: 2 additions & 2 deletions src/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ void request_opinion(
bool is_black,
u64 milliseconds
){
transpositions_table_init();
tt_init();

u64 zobrist_hash = zobrist_new_hash(b);
out_board ignored;

u64 curr_time = current_time_in_millis();
u64 stop_time = curr_time + milliseconds;
mcts_start_timed(&ignored, b, is_black, stop_time, stop_time);
tt_stats * stats = transpositions_lookup_create(b, is_black, zobrist_hash);
tt_stats * stats = tt_lookup_create(b, is_black, zobrist_hash);
omp_unset_lock(&stats->lock);
if(stats->expansion_delay != -1)
return;
Expand Down
47 changes: 24 additions & 23 deletions src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ maintenance if needed.
#include "game_record.h"
#include "mcts.h"
#include "opening_book.h"
#include "stringm.h"
#include "transpositions.h"
#include "types.h"
#include "version.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ Obtains the current data folder path. It may be absolute or relative and ends
with a path separator.
RETURNS folder path
*/
const char * get_data_folder()
const char * data_folder()
{
return _data_folder;
}
Expand Down Expand Up @@ -151,6 +152,23 @@ void evaluate_in_background(
tt_requires_maintenance = true;
}

static void freed_mem_message(
u32 states
){
if(states == 0)
return;

char * s = alloc();
char * s2 = alloc();

format_mem_size(s2, states * sizeof(tt_stats));
snprintf(s, MAX_PAGE_SIZ, "freed %u states (%s)", states, s2);
flog_info("mcts", s);

release(s2);
release(s);
}

/*
Inform that we are currently between matches and proceed with the maintenance
that is suitable at the moment.
Expand All @@ -159,16 +177,7 @@ void new_match_maintenance()
{
u32 freed = tt_clean_all();
tt_requires_maintenance = false;

if(freed > 0)
{
char * s = alloc();
snprintf(s, MAX_PAGE_SIZ,
"freed all %u states between matches (%lu MiB)", freed,
(freed * sizeof(tt_stats)) / 1048576);
flog_info("mcts", s);
release(s);
}
freed_mem_message(freed);
}

/*
Expand All @@ -182,17 +191,9 @@ void opt_turn_maintenance(
){
if(tt_requires_maintenance)
{
u32 freed = tt_clean_outside_tree(b, is_black);
u32 freed = tt_clean_unreachable(b, is_black);
tt_requires_maintenance = false;

if(freed > 0)
{
char * s = alloc();
snprintf(s, MAX_PAGE_SIZ, "freed %u states (%lu MiB)\n", freed,
(freed * sizeof(tt_stats)) / 1048576);
flog_info("mcts", s);
release(s);
}
freed_mem_message(freed);
}
}

Expand All @@ -202,12 +203,12 @@ doesn't.
*/
void assert_data_folder_exists()
{
DIR * dir = opendir(get_data_folder());
DIR * dir = opendir(data_folder());
if(dir == NULL)
{
char * s = alloc();
snprintf(s, MAX_PAGE_SIZ, "data folder %s does not exist or is unavaila\
ble\n", get_data_folder());
ble\n", data_folder());
flog_crit("data", s);
release(s);
}else
Expand Down
10 changes: 7 additions & 3 deletions src/flog.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ crashes, but it is impossible to guarantee this in all cases.
#include "amaf_rave.h"
#include "engine.h"
#include "flog.h"
#include "game_record.h"
#include "mcts.h"
#include "pat3.h"
#include "playout.h"
#include "scoring.h"
#include "stringm.h"
#include "time_ctrl.h"
#include "timem.h"
#include "types.h"
#include "version.h"

static int log_file = -1;
Expand Down Expand Up @@ -258,7 +259,7 @@ void build_info(
idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx, "Version: %s\n",
MATILDA_VERSION);
idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx, "Data folder: %s\n",
get_data_folder());
data_folder());

idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx, "Board size: %ux%u\n",
BOARD_SIZ, BOARD_SIZ);
Expand Down Expand Up @@ -288,8 +289,11 @@ void build_info(

idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx, "Winrate for passing always: %.2f\n", JUST_PASS_WINRATE);

char * s = alloc();
format_mem_size(s, max_size_in_mbs * 1048576);
idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx,
"Transpositions table memory: %" PRIu64 " MiB\n", max_size_in_mbs);
"Transpositions table memory: %s\n", s);
release(s);

if(pl_skip_saving)
idx += snprintf(dst + idx, MAX_PAGE_SIZ - idx,
Expand Down
20 changes: 16 additions & 4 deletions src/inc/alloc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/*
Guard functions over standard malloc.
Fast memory allocation layer above standard malloc.
These are meant to inexpensively allocate buffers for string operations.
They are thread-safe, fast, with canary values used (in debug mode) to ensure
memory is correctly freed and written to.
If you are need to perform recursive operations then use malloc/free. Releasing
these buffers does not actually free the underlying memory to be used by other
programs.
*/

#ifndef MATILDA_ALLOC_H
Expand All @@ -8,17 +17,20 @@ Guard functions over standard malloc.
#include "matilda.h"

/*
Initiate the safe allocation.
Initiate the safe allocation functions.
*/
void alloc_init();

/*
Allocate a small block of memory; intended for string formatting and the like.
Allocate a block of exactly MAX_PAGE_SIZ.
Thread-safe.
*/
void * alloc();

/*
Releases a previously allocated block of memory.
Releases a previously allocated block of memory, to be used again in later
calls. Does not free the memory.
Thread-safe.
*/
void release(void * ptr);

Expand Down
4 changes: 2 additions & 2 deletions src/inc/amaf_rave.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ action estimation in computer Go' by Sylvain Gelly and David Silver
*/
#if BOARD_SIZ < 12
/*
Tuned with CLOP in 9x9 with 1k playouts/turn vs GNU Go 3.8 lvl 1. 37k games.
Tuned with CLOP in 9x9 with 10k playouts/turn in self-play for 34k games.
*/
#define RAVE_MSE_EQUIV 2003
#define RAVE_MSE_EQUIV 719
#else
#define RAVE_MSE_EQUIV 2003
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/inc/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Obtains the current data folder path. It may be absolute or relative and ends
with a path separator.
RETURNS folder path
*/
const char * get_data_folder();
const char * data_folder();

/*
Sets the new data folder path. If the path is too long, short, or otherwise
Expand Down
Loading

0 comments on commit 25e7869

Please sign in to comment.