Skip to content

Commit

Permalink
Merge pull request #68 from gonmf/develop
Browse files Browse the repository at this point in the history
v1.21 Etiquette, refactoring, 3x3 pattern changes, time compensation changes, new opening books, bug fixes
  • Loading branch information
gonmf authored Oct 1, 2016
2 parents 1f814ec + d42d3be commit 2c982ae
Show file tree
Hide file tree
Showing 41 changed files with 6,446 additions and 4,148 deletions.
1 change: 1 addition & 0 deletions clop/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clop-gui
clop-console
*.dat
*.sgf
*.log
Expand Down
2 changes: 1 addition & 1 deletion clop/config.clop
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LinearParameter time_allot_factor 1.0 6.0
#IntegerParameter pl_skip_nakade 0 128
#IntegerParameter pl_skip_capture 0 128
#IntegerParameter pl_skip_pattern 0 128
#IntegerParameter pl_allow_satari 0 128
#IntegerParameter pl_ban_self_atari 0 128

#IntegerParameter expansion_delay 0 8

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

# program to be optimized
optimized_program = '/home/user/go/matilda/github/src/matilda -d /home/user/go/matilda/github/src/data/ -m gtp -l --time_system 10m+0x0/0'
optimized_program = '/home/user/go/matilda/github/src/matilda -d /home/user/go/matilda/github/src/data/ -m gtp -l --disable_opening_books'
# --disable_opening_books
# --playouts 1000

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


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

#print "command = ", command

Expand Down
4 changes: 3 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ learn_best_plays
learn_pat_weights
gen_zobrist_table
callgrind.out.*
matilda_*_*.log
*.log
*.sgf
*.ugi
*.ugf
output.*
7 changes: 4 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
DEPFILES := $(patsubst %.o,%.d,$(OBJFILES))

PROGRAMS := matilda test gen_opening_book learn_best_plays learn_pat_weights \
gen_zobrist_table gen_joseki_book
gen_zobrist_table
# gen_joseki_book

.PHONY: $(PROGRAMS) clean

Expand All @@ -55,8 +56,8 @@ learn_pat_weights: $(OBJFILES) pat_weights/*.c
gen_zobrist_table: $(OBJFILES) zobrist/*.c
@$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@

gen_joseki_book: $(OBJFILES) joseki/*.c
@$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
#gen_joseki_book: $(OBJFILES) joseki/*.c
# @$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@

%.o: %.c
@$(CC) -c -o $@ $< $(CFLAGS)
Expand Down
63 changes: 60 additions & 3 deletions src/alloc.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
Guard functions over standard malloc.
Guard functions over standard malloc. They are used for quickly and
inexpensively allocate a small buffer, with safety measures.
It is thread-safe, fast, and canary values are used (in debug mode) to ensure
memory is correctly freed and written to.
*/

#include "matilda.h"

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

Expand All @@ -14,6 +19,11 @@ typedef struct __mem_link_ {
struct __mem_link_ * next;
} mem_link;

#define HEAD_USED 251
#define HEAD_FREE 252
#define TAIL_USED 253
#define TAIL_FREE 254

static mem_link * queue = NULL;
static omp_lock_t queue_lock;
static bool queue_inited = false;
Expand All @@ -32,6 +42,8 @@ void alloc_init()

/*
Allocate a small block of memory; intended for string formatting and the like.
Canary protection is used in debug mode.
*/
void * alloc()
{
Expand All @@ -46,26 +58,71 @@ void * alloc()
omp_unset_lock(&queue_lock);

if(ret == NULL){
#if MATILDA_RELEASE_MODE
ret = malloc(MAX_PAGE_SIZ);
if(ret == NULL)
flog_crit("alloc", "out of memory exception");
{
fprintf(stderr, "alloc: out of memory exception\n");
exit(EXIT_FAILURE);
}
#else
u8 * buf = malloc(MAX_PAGE_SIZ + 2);
if(buf == NULL)
{
fprintf(stderr, "alloc: out of memory exception\n");
exit(EXIT_FAILURE);
}

/* canaries -- detection of out of bounds writes */
buf[0] = HEAD_FREE;
buf[MAX_PAGE_SIZ + 1] = TAIL_FREE;

ret = buf + 1;
#endif
}

/*
Ensure that if used for string concatenation then gibberish is never
returned.
*/
#if !MATILDA_RELEASE_MODE
if(((u8 *)ret)[-1] != HEAD_FREE || ((u8 *)ret)[MAX_PAGE_SIZ] != TAIL_FREE)
{
fprintf(stderr, "memory corruption detected; check for repeated release\
s, rolling block releasing or writes past bounds (1)\n");
exit(EXIT_FAILURE);
}
/* change the canary */
((u8 *)ret)[-1] = HEAD_USED;
((u8 *)ret)[MAX_PAGE_SIZ] = TAIL_USED;
#endif
((char *)ret)[0] = 0;

return ret;
}

/*
Releases a previously allocated block of memory.
Canary protection is used in debug mode.
*/
void release(void * ptr)
{
#if !MATILDA_RELEASE_MODE
/* canaries -- detection of out of bounds writes */
u8 * s = (u8 *)ptr;
if(s[-1] != HEAD_USED || s[MAX_PAGE_SIZ] != TAIL_USED)
{
fprintf(stderr, "memory corruption detected; check for repeated release\
s, rolling block releasing or writes past bounds (2)\n");
exit(EXIT_FAILURE);
}
s[-1] = HEAD_FREE;
s[MAX_PAGE_SIZ] = TAIL_FREE;
#endif

omp_set_lock(&queue_lock);
mem_link * l = (mem_link *)ptr;
l->next = queue;
queue = l;
omp_unset_lock(&queue_lock);
}
2 changes: 2 additions & 0 deletions src/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void print_sequence(
tt_play * p
){
tt_stats * stats = (tt_stats *)p->next_stats;
if(stats == NULL)
return; /* may be null if play is a pass */
tt_play * best_play = select_best(stats);

char * tmp = alloc();
Expand Down
3 changes: 3 additions & 0 deletions src/data/13x13_gnugo.ob
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This opening book was created by seeing the most common plays in GNU Go 3.8
# self-play. It is probably very poor.

13 E11 K11 C10 E4 G4 E3 | C7 # 14/14
13 C4 | D11 # 84/112
13 L6 C5 L4 J3 K3 | E4 # 7/10
Expand Down
Loading

0 comments on commit 2c982ae

Please sign in to comment.