From 6a8e91836755ce865bb6a8fdfbcc8afa2c01512a Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 22 Sep 2008 02:50:02 +0200 Subject: [PATCH] Symmetry: Remove symmetry.free and symmetry.d<0 bogosity --- board.c | 58 +++++++++++----------------------------------------------- board.h | 5 +---- uct/tree.c | 4 ++-- 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/board.c b/board.c index 42c6bb0..d2493c5 100644 --- a/board.c +++ b/board.c @@ -134,11 +134,10 @@ board_clear(struct board *board) board_resize(board, size - 2 /* S_OFFBOARD margin */); /* Setup initial symmetry */ - board->symmetry.d = -1; + board->symmetry.d = 1; board->symmetry.x1 = board->symmetry.y1 = board->size / 2; board->symmetry.x2 = board->symmetry.y2 = board->size - 1; board->symmetry.type = SYM_FULL; - board->symmetry.free = true; /* Draw the offboard margin */ int top_row = board_size2(board) - board_size(board); @@ -270,9 +269,9 @@ board_symmetry_update(struct board *b, struct board_symmetry *symmetry, coord_t int x = coord_x(c, b), y = coord_y(c, b), t = board_size(b) / 2; int dx = board_size(b) - 1 - x; /* for SYM_DOWN */ if (DEBUGL(6)) { - fprintf(stderr, "SYMMETRY [%d,%d,%d,%d|%d=%d+%d] update for %d,%d\n", + fprintf(stderr, "SYMMETRY [%d,%d,%d,%d|%d=%d] update for %d,%d\n", symmetry->x1, symmetry->y1, symmetry->x2, symmetry->y2, - symmetry->d, symmetry->type, symmetry->free, x, y); + symmetry->d, symmetry->type, x, y); } switch (symmetry->type) { @@ -313,63 +312,28 @@ break_symmetry: case SYM_DIAG_UP: if (x == y) return; - if (symmetry->d > 0 ? x < y : x > y) { - /* Good side of symmetry. Just froze it. */ - symmetry->free = false; - } else if (symmetry->free) { - /* Flip symmetry. */ - symmetry->d = - symmetry->d; - symmetry->free = false; - } else { - /* Break symmetry. */ - goto break_symmetry; - } - break; + goto break_symmetry; case SYM_DIAG_DOWN: if (dx == y) return; - if (symmetry->d > 0 ? dx < y : dx > y) { - symmetry->free = false; - } else if (symmetry->free) { - symmetry->d = - symmetry->d; - symmetry->free = false; - } else { - goto break_symmetry; - } - break; + goto break_symmetry; case SYM_HORIZ: if (x == t) return; - if (symmetry->x1 <= x && x <= symmetry->x2) { - symmetry->free = false; - } else if (symmetry->free) { - symmetry->x1 = t; - symmetry->x2 = board_size(b) - 1; - symmetry->free = false; - } else { - goto break_symmetry; - } - break; + goto break_symmetry; case SYM_VERT: - if (symmetry->y1 <= y && y <= symmetry->y2) { - symmetry->free = false; - } else if (symmetry->free) { - symmetry->y1 = t; - symmetry->y2 = board_size(b) - 1; - symmetry->free = false; - } else { - goto break_symmetry; - } - break; + if (y == t) + return; + goto break_symmetry; case SYM_NONE: assert(0); break; } if (DEBUGL(6)) { - fprintf(stderr, "NEW SYMMETRY [%d,%d,%d,%d|%d=%d+%d]\n", + fprintf(stderr, "NEW SYMMETRY [%d,%d,%d,%d|%d=%d]\n", symmetry->x1, symmetry->y1, symmetry->x2, symmetry->y2, - symmetry->d, symmetry->type, symmetry->free); + symmetry->d, symmetry->type); } /* Whew. */ } diff --git a/board.h b/board.h index 56c953c..b86ed58 100644 --- a/board.h +++ b/board.h @@ -28,8 +28,7 @@ struct board_symmetry { /* Playground is in this rectangle. */ int x1, x2, y1, y2; /* d == 0: Full rectangle - * d == -1: x <= y rectangle - * d == 1: x >= y rectangle */ + * d == 1: Top triangle */ int d; /* General symmetry type. */ enum { @@ -40,8 +39,6 @@ struct board_symmetry { SYM_VERT, SYM_NONE } type; - /* Can we flip symmetry if necessary? */ - bool free; }; diff --git a/uct/tree.c b/uct/tree.c index 024667e..d09b9a8 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -197,7 +197,7 @@ tree_expand_node(struct tree *t, struct tree_node *node, struct board *b, enum s for (int j = b->symmetry.y1; j <= b->symmetry.y2; j++) { if (b->symmetry.d) { int x = b->symmetry.type == SYM_DIAG_DOWN ? board_size(b) - 1 - i : i; - if (b->symmetry.d < 0 ? x < j : x > j) { + if (x > j) { if (UDEBUGL(7)) fprintf(stderr, "drop %d,%d\n", i, j); continue; @@ -262,7 +262,7 @@ tree_fix_symmetry(struct tree *tree, struct board *b, coord_t c) if (s->d) { bool dir = (s->type == SYM_DIAG_DOWN) ^ flip_horiz ^ flip_vert; int x = dir ? board_size(b) - 1 - cx : cx; - if (s->d < 0 ? x < cy : x > cy) { + if (x > cy) { flip_diag = 1 + dir; } } -- 2.11.4.GIT