From 429f8614bced2420c367a20756bda3400e9e1163 Mon Sep 17 00:00:00 2001 From: lemonsqueeze Date: Wed, 13 Jul 2016 12:30:34 +0200 Subject: [PATCH] t-unit: two_eyes test suite --- Makefile | 2 +- t-unit/test.c | 34 ++++++++- t-unit/two_eyes.t | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 t-unit/two_eyes.t diff --git a/Makefile b/Makefile index bc4cea1..b9361d8 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ SUBDIRS=random replay patternscan patternplay joseki montecarlo uct uct/policy p all: all-recursive pachi -LOCALLIBS=random/random.a replay/replay.a patternscan/patternscan.a patternplay/patternplay.a joseki/joseki.a montecarlo/montecarlo.a uct/uct.a uct/policy/uctpolicy.a playout/playout.a tactics/tactics.a t-unit/test.a distributed/distributed.a +LOCALLIBS=random/random.a replay/replay.a patternscan/patternscan.a patternplay/patternplay.a joseki/joseki.a montecarlo/montecarlo.a uct/uct.a uct/policy/uctpolicy.a playout/playout.a t-unit/test.a tactics/tactics.a distributed/distributed.a $(LOCALLIBS): all-recursive @ pachi: $(OBJS) pachi.o $(LOCALLIBS) diff --git a/t-unit/test.c b/t-unit/test.c index aeac55b..6363786 100644 --- a/t-unit/test.c +++ b/t-unit/test.c @@ -8,6 +8,7 @@ #include "board.h" #include "debug.h" #include "tactics/selfatari.h" +#include "tactics/dragon.h" #include "tactics/ladder.h" #include "random.h" #include "playout.h" @@ -95,7 +96,6 @@ set_ko(struct board *b, char *arg) } - static bool test_sar(struct board *b, char *arg) { @@ -126,6 +126,7 @@ test_sar(struct board *b, char *arg) return rres == eres; } + static bool test_ladder(struct board *b, char *arg) { @@ -161,6 +162,35 @@ test_ladder(struct board *b, char *arg) static bool +test_two_eyes(struct board *b, char *arg) +{ + coord_t c = str2scoord(arg, board_size(b)); + arg += strcspn(arg, " ") + 1; + int eres = atoi(arg); + + board_print_test(2, b); + if (DEBUGL(1)) + printf("two_eyes %s %d...\t", coord2sstr(c, b), eres); + + enum stone color = board_at(b, c); + assert(color == S_BLACK || color == S_WHITE); + int rres = dragon_is_safe(b, group_at(b, c), color); + + if (rres == eres) { + if (DEBUGL(1)) + printf("OK\n"); + } else { + if (debug_level <= 2) { + board_print_test(0, b); + printf("two_eyes %s %d...\t", coord2sstr(c, b), eres); + } + printf("FAILED (%d)\n", rres); + } + return rres == eres; +} + + +static bool test_moggy_moves(struct board *b, char *arg) { int runs = 1000; @@ -357,6 +387,8 @@ unittest(char *filename) passed += test_sar(b, line + 4); else if (!strncmp(line, "ladder ", 7)) passed += test_ladder(b, line + 7); + else if (!strncmp(line, "two_eyes ", 9)) + passed += test_two_eyes(b, line + 9); else if (!strncmp(line, "moggy moves ", 12)) passed += test_moggy_moves(b, line + 12); else if (!strncmp(line, "moggy status ", 13)) diff --git a/t-unit/two_eyes.t b/t-unit/two_eyes.t new file mode 100644 index 0000000..bcb6b42 --- /dev/null +++ b/t-unit/two_eyes.t @@ -0,0 +1,223 @@ + +% 2 eyes, one group +boardsize 5 +. . . . . +X X . . . +. X . . . +X X . . . +. X . . . + +two_eyes b1 1 + + +% 2pt eye with prisoner +boardsize 5 +. . . . . +X X X . . +X O X . . +X . X . . +. X X . . + +two_eyes b1 1 + + +% 2pt eye with prisoner +boardsize 5 +. . . . . +X X X . . +X . X . . +X O X . . +. X X . . + +!two_eyes b1 1 # FIXME + + +% Diag connection +boardsize 7 +. . . . . . . +. . O O O O . +. O O X X O . +. O X . X O . +. . X X X O . +X X . O O . . +. X . . . . . + +two_eyes b1 1 + + +% Bamboo joint +boardsize 7 +. . . . . . . +. . O O O O O +. O . . X X X +. O X . X O . +. . X . X X X +X X . O O O O +. X . O . O . + +two_eyes b1 1 + + +% Hanging connection +boardsize 7 +. . . . . . . +. . O O O O O +. O . O X X X +. O X . X O . +. X . X X X X +X X . O O O O +. X . O . O . + +two_eyes b1 1 + + +% False eye +boardsize 5 +. . . . . +O O O O O +O X X . O +X . X . O +. X O O . + +two_eyes b1 0 + + +% Open +boardsize 5 +. . . . . +X X . . . +. X . . . +. X . . . +. X . . . + +two_eyes b1 0 + + +% Open +boardsize 5 +. . . . . +. X . . . +X X . . . +. X . . . +. X . . . + +two_eyes b1 0 + + +% 2pt eye +boardsize 5 +X X . . . +. X . . . +. X . . . +X X . . . +. X . . . + +two_eyes b1 1 + + +% 2pt eye +boardsize 5 +X X . . . +. X . . . +O X . . . +X X . . . +. X . . . + +two_eyes b1 1 + + +% False eye +boardsize 5 +X O O . . +. X O . . +X X . O . +. X . O . +. X . . . + +two_eyes b1 0 + + +% Ok +boardsize 5 +X . X . . +. X . . . +X X . . . +. X . . . +. X . . . + +two_eyes b1 1 + + +% Ok too +boardsize 5 +X . . . . +. X . . . +X X . . . +. X . . . +. X . . . + +two_eyes b1 1 + + +% Not ok +boardsize 5 +X . O . . +. X . O . +X X . O . +. X . O . +. X . O . + +two_eyes b1 0 + + +% Big eye +boardsize 5 +X X . X . +. X X X . +O X . . . +O X . . . +. X . . . + +two_eyes b1 1 + + +% No big eye area (yet) +boardsize 7 +. . O O O O O +O O X X X X O +. X O X . X O +. X O . X X O +. X O . X . O +. O X X . O . +. O O O O . . + +two_eyes c2 0 +two_eyes c1 0 # 2pt eye not real yet + + +% Open +boardsize 5 +X X . X . +. X X X . +O X . . . +O X . . . +. . . . . + +two_eyes b2 0 + + +% Big eye +boardsize 7 +. . O O O O . +. . O X X . . +. . O X . X X +. . O X . X . +. . O X . X X +. . O X X . . +. . O O O O . + +two_eyes d2 1 + + + + -- 2.11.4.GIT