Ticket #148: matchpat.diff

File matchpat.diff, 21.8 kB (added by draqo, 18 months ago)

matchpat.c cleanup patch (includes also minimal change in attack.db and defense.db) - apply after worm2 patch

  • engine/matchpat.c

    diff -N -r -u -X .ignore gnugo-copy/engine/matchpat.c gnugo/engine/matchpat.c
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    135135 
    136136/* Forward declarations. */ 
    137137 
    138 static void fixup_patterns_for_board_size(struct pattern *pattern); 
     138static void fixup_patterns_for_board_size(struct pattern_db *pdb); 
    139139static void prepare_for_match(int color); 
    140140static void do_matchpat(int anchor, matchpat_callback_fn_ptr callback, 
    141141                        int color, struct pattern *database, 
     
    214214 */ 
    215215 
    216216static void 
    217 fixup_patterns_for_board_size(struct pattern *pattern) 
     217fixup_patterns_for_board_size(struct pattern_db *pdb) 
    218218{ 
     219  struct pattern *pattern = pdb->patterns; 
     220  int undo = pdb->fixed_for_size != -1; 
     221 
    219222  for (; pattern->patn; ++pattern) 
    220223    if (pattern->edge_constraints != 0) { 
    221224 
     
    225228       * called, this step is effectively a no-op. 
    226229       */ 
    227230       
    228       if (pattern->edge_constraints & NORTH_EDGE) 
    229         pattern->maxi = pattern->mini + pattern->height; 
     231      if (undo) { 
     232        if (pattern->edge_constraints & NORTH_EDGE) 
     233          pattern->maxi = pattern->mini + pattern->height; 
    230234         
    231       if (pattern->edge_constraints & SOUTH_EDGE) 
    232         pattern->mini = pattern->maxi - pattern->height; 
     235        if (pattern->edge_constraints & SOUTH_EDGE) 
     236          pattern->mini = pattern->maxi - pattern->height; 
    233237         
    234       if (pattern->edge_constraints & WEST_EDGE) 
    235         pattern->maxj = pattern->minj + pattern->width; 
     238        if (pattern->edge_constraints & WEST_EDGE) 
     239          pattern->maxj = pattern->minj + pattern->width; 
    236240       
    237       if (pattern->edge_constraints & EAST_EDGE) 
    238         pattern->minj = pattern->maxj - pattern->width; 
     241        if (pattern->edge_constraints & EAST_EDGE) 
     242          pattern->minj = pattern->maxj - pattern->width; 
     243      } 
    239244       
    240245      /* we extend the pattern in the direction opposite the constraint, 
    241246       * such that maxi (+ve) - mini (-ve) = board_size-1 
     
    342347    { 
    343348      int end_transformation; 
    344349      int ll;   /* Iterate over transformations (rotations or reflections)  */ 
    345       int k;    /* Iterate over elements of pattern */ 
     350      struct patval *elpat, *elend;    /* Iterate over elements of pattern */ 
    346351      int found_goal; 
    347352   
    348353      /* We can check the color of the anchor stone now. 
     
    365370      if (anchor_test != pattern->anchored_at_X) 
    366371        continue;  /* does not match the anchor */ 
    367372 
    368       ll = 0;  /* first transformation number */ 
    369       end_transformation = pattern->trfno; 
    370  
    371373      /* Ugly trick for dealing with 'O' symmetry. */ 
    372374      if (pattern->trfno == 5) { 
    373375        ll = 2; 
    374376        end_transformation = 6; 
    375377      } 
     378      else { 
     379        ll = 0;  /* first transformation number */ 
     380        end_transformation = pattern->trfno; 
     381      } 
    376382       
    377383      /* try each orientation transformation. Assume at least 1 */ 
    378384 
     
    425431        } 
    426432 
    427433        /* Now iterate over the elements of the pattern. */ 
    428         found_goal = 0; 
    429         for (k = 0; k < pattern->patlen; ++k) { /* match each point */ 
     434        found_goal = (goal == NULL); 
     435 
     436        elpat = pattern->patn; 
     437        elend = elpat + pattern->patlen; 
     438        for (; elpat < elend; ++elpat) { /* match each point */ 
    430439          int pos; /* absolute coords of (transformed) pattern element */ 
    431           int att = pattern->patn[k].att;  /* what we are looking for */ 
     440          int att = elpat->att;  /* what we are looking for */ 
    432441 
    433442          /* Work out the position on the board of this pattern element. */ 
    434443 
    435444          /* transform pattern real coordinate... */ 
    436           pos = AFFINE_TRANSFORM(pattern->patn[k].offset, ll, anchor); 
     445          pos = AFFINE_TRANSFORM(elpat->offset, ll, anchor); 
    437446 
    438447          ASSERT_ON_BOARD1(pos); 
    439448 
     
    441450          if ((board[pos] & and_mask[color-1][att]) != val_mask[color-1][att]) 
    442451            goto match_failed; 
    443452 
    444           if (goal != NULL && board[pos] != EMPTY && goal[pos]) 
     453          if (!found_goal && board[pos] && goal[pos]) 
    445454            found_goal = 1; 
    446455           
    447456          /* Check out the class_X, class_O, class_x, class_o 
     
    463472 
    464473 
    465474        /* Make it here ==> We have matched all the elements to the board. */ 
    466         if ((goal != NULL) && !found_goal) 
     475        if (!found_goal) 
    467476          goto match_failed; 
    468477 
    469478#if PROFILE_PATTERNS 
     
    485494              pattern->name, ll, anchor); 
    486495          
    487496      } while (++ll < end_transformation); /* ll loop over symmetries */ 
    488     } /* if not rejected by maxwt */ 
     497    } 
    489498  } while ((++pattern)->patn);  /* loop over patterns */ 
    490499} 
    491500 
     
    493502/* 
    494503 * Scan the board to get patterns anchored by anchor from color 
    495504 * point of view. 
    496  * the board must be prepared by dfa_prepare_for_match(color) ! 
     505 * the board must be prepared by prepare_for_match(color) ! 
    497506 */ 
    498507static void 
    499508matchpat_loop(matchpat_callback_fn_ptr callback, int color, int anchor, 
     
    503512  int pos; 
    504513   
    505514  for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    506     if (board[pos] == anchor && (!anchor_in_goal || goal[pos] != 0)) 
     515    if (board[pos] == anchor && (!anchor_in_goal || goal[pos])) 
    507516      do_matchpat(pos, callback, color, pdb->patterns, 
    508517                  callback_data, goal); 
    509518  } 
     
    537546static void do_dfa_matchpat(dfa_rt_t *pdfa, 
    538547                            int anchor, matchpat_callback_fn_ptr callback, 
    539548                            int color, struct pattern *database, 
    540                             void *callback_data, signed char goal[BOARDMAX], 
    541                             int anchor_in_goal); 
     549                            void *callback_data, signed char goal[BOARDMAX]); 
    542550static void check_pattern_light(int anchor,  
    543551                                matchpat_callback_fn_ptr callback, 
    544552                                int color, struct pattern *pattern, int ll, 
    545553                                void *callback_data, 
    546                                 signed char goal[BOARDMAX], 
    547                                 int anchor_in_goal); 
     554                                signed char goal[BOARDMAX]); 
    548555static void dfa_matchpat_loop(matchpat_callback_fn_ptr callback, 
    549556                              int color, int anchor, 
    550557                              struct pattern_db *pdb, void *callback_data, 
     
    643650scan_for_patterns(dfa_rt_t *pdfa, int l, int *dfa_pos, int *pat_list) 
    644651{ 
    645652  int delta; 
    646   int state = 1; /* initial state */ 
     653  const state_rt_t *state = pdfa->states + 1; /* initial state */ 
    647654  int row = 0; /* initial row */ 
    648655  int id = 0; /* position in id_list */ 
    649656 
    650   do { 
     657  for (;;) { 
    651658    /* collect patterns indexes */ 
    652     int att = pdfa->states[state].att; 
     659    int att = state->att; 
    653660    while (att != 0) { 
    654       pat_list[id] = pdfa->indexes[att].val; 
    655       id++; 
     661      pat_list[id++] = pdfa->indexes[att].val; 
    656662      att = pdfa->indexes[att].next; 
    657663    } 
    658664 
    659665    /* go to next state */ 
    660     delta = pdfa->states[state].next[dfa_pos[spiral[row][l]]]; 
    661     state += delta; 
    662     row++; 
    663   } while (delta != 0); /* while not on error state */ 
     666    delta = state->next[*(dfa_pos + spiral[row++][l])]; 
     667    if (!delta) 
     668      return id; /* error state */ 
    664669 
    665   return id; 
     670    state += delta; 
     671  } 
    666672} 
    667673 
    668674 
     
    671677do_dfa_matchpat(dfa_rt_t *pdfa, 
    672678                int anchor, matchpat_callback_fn_ptr callback, 
    673679                int color, struct pattern *database, 
    674                 void *callback_data, signed char goal[BOARDMAX], 
    675                 int anchor_in_goal) 
     680                void *callback_data, signed char goal[BOARDMAX]) 
    676681{ 
    677682  int k; 
    678683  int ll;      /* Iterate over transformations (rotations or reflections)  */ 
    679   int patterns[DFA_MAX_MATCHED + 8]; 
     684  int patterns[DFA_MAX_MATCHED + 8]; /* Reserve 8 for -1 value 
     685                                      * (a transformation separator). */ 
    680686  int num_matched = 0; 
    681687  int *dfa_pos = dfa_p + DFA_POS(I(anchor), J(anchor)); 
    682688 
     
    694700 
    695701  /* Constraints and other tests. */ 
    696702  for (ll = 0, k = 0; ll < 8; k++) { 
    697     int matched; 
     703    struct pattern *matched; 
    698704 
    699705    if (patterns[k] == -1) { 
    700706      ll++; 
    701707      continue; 
    702708    } 
    703709 
    704     matched = patterns[k]; 
     710    matched = database + patterns[k]; 
    705711 
    706712#if PROFILE_PATTERNS 
    707     database[matched].dfa_hits++; 
     713    matched->dfa_hits++; 
    708714#endif 
    709715 
    710     check_pattern_light(anchor, callback, color, database + matched, 
    711                         ll, callback_data, goal, anchor_in_goal); 
     716    /* Throw out duplicating orientations of symmetric patterns. */ 
     717    if (matched->trfno == 5) { 
     718      if (ll < 2 || ll >= 6) 
     719        continue; 
     720    } 
     721    else { 
     722      if (ll >= matched->trfno) 
     723        continue; 
     724    } 
     725 
     726    check_pattern_light(anchor, callback, color, matched, 
     727                        ll, callback_data, goal); 
    712728  } 
    713729} 
    714730 
     
    722738static void 
    723739check_pattern_light(int anchor, matchpat_callback_fn_ptr callback, int color, 
    724740                    struct pattern *pattern, int ll, void *callback_data, 
    725                     signed char goal[BOARDMAX], int anchor_in_goal) 
     741                    signed char goal[BOARDMAX]) 
    726742{ 
    727743  int k;                        /* Iterate over elements of pattern */ 
    728   int found_goal = 0; 
     744  int found_goal = (goal == NULL); 
    729745   
    730746#if PROFILE_PATTERNS 
    731747  int nodes_before; 
    732748#endif 
    733749   
    734   if (0) 
    735     gprintf("check_pattern_light @ %1m rot:%d pattern: %s\n",  
    736             anchor, ll, pattern->name); 
    737  
    738   /* Throw out duplicating orientations of symmetric patterns. */ 
    739   if (pattern->trfno == 5) { 
    740     if (ll < 2 || ll >= 6) 
    741       return; 
    742   } 
    743   else { 
    744     if (ll >= pattern->trfno) 
    745       return; 
    746   } 
     750#if 0 
     751  gprintf("check_pattern_light @ %1m rot:%d pattern: %s\n",  
     752          anchor, ll, pattern->name); 
     753#endif 
    747754 
    748   
    749   /* Now iterate over the elements of the pattern. */ 
     755  /* Iterate over the elements of the pattern. */ 
    750756  for (k = 0; k < pattern->patlen; k++) { 
    751757                                /* match each point */ 
    752758    int pos;                    /* absolute (board) co-ords of  
     
    756762    pos = AFFINE_TRANSFORM(pattern->patn[k].offset, ll, anchor); 
    757763    ASSERT_ON_BOARD1(pos); 
    758764 
    759     if (!anchor_in_goal) {  
    760       /* goal check */ 
    761       if (goal != NULL && board[pos] != EMPTY && goal[pos]) 
    762         found_goal = 1; 
    763     } 
     765    /* goal check */ 
     766    if (!found_goal && board[pos] && goal[pos]) 
     767      found_goal = 1; 
    764768 
    765769    /* class check */ 
    766770    ASSERT1(dragon[pos].status < 4, anchor); 
     
    770774  } /* loop over elements */ 
    771775   
    772776  /* Make it here ==> We have matched all the elements to the board. */ 
    773   if (!anchor_in_goal) {  
    774     if (goal != NULL && !found_goal) 
    775       goto match_failed; 
    776   } 
     777  if (!found_goal) 
     778    goto match_failed; 
    777779 
    778780#if PROFILE_PATTERNS 
    779781  pattern->hits++; 
     
    808810  int pos; 
    809811 
    810812  for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    811     if (board[pos] == anchor && (!anchor_in_goal || goal[pos] != 0)) 
     813    if (board[pos] == anchor && (!anchor_in_goal || goal[pos])) 
    812814      do_dfa_matchpat(pdb->pdfa, pos, callback, color, pdb->patterns, 
    813                       callback_data, goal, anchor_in_goal); 
     815                      callback_data, goal); 
    814816  } 
    815817} 
    816818 
     
    852854                     struct pattern_db *pdb, void *callback_data, 
    853855                     signed char goal[BOARDMAX], int anchor_in_goal)  
    854856{ 
    855   loop_fn_ptr_t loop = matchpat_loop; 
    856   prepare_fn_ptr_t prepare = prepare_for_match; 
     857  loop_fn_ptr_t loop; 
     858  prepare_fn_ptr_t prepare; 
    857859 
    858860  /* check board size */ 
    859861  if (pdb->fixed_for_size != board_size) { 
    860     fixup_patterns_for_board_size(pdb->patterns); 
     862    fixup_patterns_for_board_size(pdb); 
    861863    pdb->fixed_for_size = board_size; 
    862864  } 
    863865 
     
    866868    loop = dfa_matchpat_loop; 
    867869    prepare = dfa_prepare_for_match; 
    868870  } 
     871  else { 
     872    loop = matchpat_loop; 
     873    prepare = prepare_for_match; 
     874  } 
    869875 
    870876  /* select strategy */ 
    871877  switch (color) { 
    872878    case ANCHOR_COLOR: 
    873       { /* match pattern for the color of their anchor */ 
     879      { /* match patterns for the color of their anchor; patterns must be 
     880         * compiled to always anchor our color */ 
    874881        prepare(WHITE); 
    875882        loop(callback, WHITE, WHITE, pdb, callback_data, goal, anchor_in_goal); 
    876883        prepare(BLACK); 
     
    878885      } 
    879886      break; 
    880887    case ANCHOR_OTHER: 
    881       { /* match pattern for the opposite color of their anchor */ 
     888      { /* match patterns for the opposite color of their anchor; patterns must 
     889         * be compiled to always anchor the opposite color */ 
    882890        prepare(WHITE); 
    883891        loop(callback, WHITE, BLACK, pdb, callback_data, goal, anchor_in_goal); 
    884892        prepare(BLACK); 
     
    896904 
    897905 
    898906static int 
    899 fullboard_transform(int pos, int trans) 
     907fullboard_transform(int pos, int trans, int half_board) 
    900908{ 
    901   int dx = I(pos) - (board_size-1)/2; 
    902   int dy = J(pos) - (board_size-1)/2; 
     909  int dx = I(pos) - half_board; 
     910  int dy = J(pos) - half_board; 
    903911  int x, y; 
    904   gg_assert(POS((board_size-1)/2, (board_size-1)/2) + DELTA(dx, dy) == pos); 
     912  gg_assert(POS(half_board, half_board) + DELTA(dx, dy) == pos); 
    905913  TRANSFORM2(dx, dy, &x, &y, trans); 
    906   return POS(x + (board_size-1)/2, y + (board_size-1)/2); 
     914  return POS(x + half_board, y + half_board); 
    907915} 
    908916 
    909917/* A dedicated matcher which can only do fullboard matching on 
     
    919927  static int color_map[gg_max(WHITE, BLACK) + 1]; 
    920928  /* One hash value for each rotation/reflection: */ 
    921929  Hash_data current_board_hash[8]; 
     930  int half_board = (board_size-1)/2; 
     931  int half_board_pos = POS(half_board, half_board); 
    922932   
    923933  /* Basic sanity check. */ 
    924934  gg_assert(color != EMPTY); 
     
    936946 
    937947  /* Get hash data of all rotations/reflections of current board position. */ 
    938948  for (ll = 0; ll < 8; ll++) { 
    939     Intersection p[BOARDSIZE]; 
     949    Intersection p[BOARDMAX]; 
    940950    int pos; 
    941     for (pos = 0; pos < BOARDSIZE; pos++) 
     951    for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    942952      if (ON_BOARD(pos)) 
    943         p[pos] = color_map[board[fullboard_transform(pos, ll)]]; 
     953        p[pos] = color_map[board[fullboard_transform(pos, ll, half_board)]]; 
    944954      else 
    945955        p[pos] = GRAY; 
    946956 
    947957    if (ON_BOARD(board_ko_pos)) 
    948958      hashdata_recalc(&current_board_hash[ll], p, 
    949                       fullboard_transform(board_ko_pos, ll)); 
     959                      fullboard_transform(board_ko_pos, ll, half_board)); 
    950960    else  
    951961      hashdata_recalc(&current_board_hash[ll], p, NO_MOVE); 
    952962  } 
     
    959969    for (ll = 0; ll < 8; ll++) 
    960970      if (hashdata_is_equal(current_board_hash[ll], pattern->fullboard_hash)) { 
    961971        /* A match!  - Call back to the invoker to let it know. */ 
    962         int pos = AFFINE_TRANSFORM(pattern->move_offset, ll, 
    963                                    POS((board_size-1)/2, (board_size-1)/2)); 
     972        int pos = AFFINE_TRANSFORM(pattern->move_offset, ll, half_board_pos); 
    964973        callback(pos, pattern, ll); 
    965974      } 
    966975  } 
     
    10121021                   int match_color, corner_matchpat_callback_fn_ptr callback, 
    10131022                   int callback_color, int trans, int anchor, int stones) 
    10141023{ 
    1015   for (; --num_variations >= 0; variation++) { 
     1024  for (; num_variations--; variation++) { 
    10161025    int move = AFFINE_TRANSFORM(variation->move_offset, trans, anchor); 
    10171026    int color_check = match_color ^ variation->xor_att; 
    10181027    struct corner_pattern *pattern = variation->pattern; 
     
    10621071    int dx = TRANSFORM(OFFSET(1, 0), k); 
    10631072    int dy = TRANSFORM(OFFSET(0, 1), k); 
    10641073    int pos; 
     1074    int prev_stones; 
    10651075    struct corner_variation *variation = database->top_variations; 
    10661076 
    10671077    /* Fill in the NUM_STONES() array. We use `max_width' and `max_height' 
    10681078     * fields of database structure to stop working as early as possible. 
    10691079     */ 
    1070     NUM_STONES(anchor) = IS_STONE(board[anchor]); 
     1080    prev_stones = IS_STONE(board[anchor]); 
     1081    NUM_STONES(anchor) = prev_stones; 
    10711082 
    10721083    pos = anchor; 
    10731084    for (i = 1; i < database->max_height; i++) { 
     
    10811092        break; 
    10821093      } 
    10831094 
    1084       NUM_STONES(pos) = NUM_STONES(pos - dx) + IS_STONE(board[pos]); 
     1095      prev_stones += IS_STONE(board[pos]); 
     1096      NUM_STONES(pos) = prev_stones; 
    10851097    } 
    10861098 
    10871099    pos = anchor; 
     1100    prev_stones = NUM_STONES(anchor); 
     1101 
    10881102    for (j = 1; j < database->max_width; j++) { 
    10891103      pos += dy; 
    10901104      if (!ON_BOARD(pos)) { 
     
    10961110        break; 
    10971111      } 
    10981112       
    1099       NUM_STONES(pos) = NUM_STONES(pos - dy) + IS_STONE(board[pos]); 
     1113      prev_stones += IS_STONE(board[pos]); 
     1114      NUM_STONES(pos) = prev_stones; 
    11001115    } 
    11011116     
    11021117    for (i = 1; i < database->max_height; i++) { 
    11031118      pos = anchor + i * dy; 
     1119      prev_stones = NUM_STONES(pos); 
    11041120      for (j = 1; j < database->max_width; j++) { 
    11051121        pos += dx; 
    1106         NUM_STONES(pos) = NUM_STONES(pos - dx) + NUM_STONES(pos - dy) 
    1107                         - NUM_STONES(pos - dx - dy); 
     1122        prev_stones += NUM_STONES(pos - dy) - NUM_STONES(pos - dx - dy); 
    11081123        if (ON_BOARD1(pos) && IS_STONE(board[pos])) 
    1109           NUM_STONES(pos)++; 
     1124          prev_stones++; 
     1125        NUM_STONES(pos) = prev_stones; 
    11101126      } 
    11111127    } 
    11121128 
  • patterns/attack.db

    diff -N -r -u -X .ignore gnugo-copy/patterns/attack.db gnugo/patterns/attack.db
    old new  
    5454# Even if a ladder works (and is found by the tactical reading) we 
    5555# also want to consider the geta capture. 
    5656 
    57 XOO?    capture one stone 
     57?OO?    capture one stone 
    5858OX.. 
    5959O.*? 
    6060?.?? 
  • patterns/defense.db

    diff -N -r -u -X .ignore gnugo-copy/patterns/defense.db gnugo/patterns/defense.db
    old new  
    8080 
    8181Pattern Def4 
    8282 
    83 XOO?    capture one stone 
     83?OO?    capture one stone 
    8484OX.. 
    8585O.*? 
    8686?.?? 
  • patterns/dfa.h

    diff -N -r -u -X .ignore gnugo-copy/patterns/dfa.h gnugo/patterns/dfa.h
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    2424#define _DFA_H_ 
    2525 
    2626 
     27/* We must leave DFA_MAX_BOARD reserve on each side, because moving 
     28 * through the board with spiral order could throw us outside the 
     29 * board up to DFA_MAX_BOARD intersections. 
     30 */ 
    2731#define DFA_MAX_BOARD           MAX_BOARD 
    28 #define DFA_MAX_ORDER           ((2 * DFA_MAX_BOARD - 1)        \ 
    29                                  * (2 * DFA_MAX_BOARD - 1)) 
    3032#define DFA_BASE                (3 * DFA_MAX_BOARD) 
    3133#define DFA_POS(i, j)           (((i) + DFA_MAX_BOARD) * DFA_BASE       \ 
    3234                                 + ((j) + DFA_MAX_BOARD)) 
    3335 
     36/* Spiral order looks like rectangle. If a pattern anchor is at the 
     37 * corner of the board and we want to be sure that pattern can match 
     38 * whole board, spiral order must be rectangle of side sized 
     39 * 2 * DFA_MAX_BOARD - 1, because anchor is in the middle of this 
     40 * rectangle. 
     41 */ 
     42#define DFA_MAX_ORDER           ((2 * DFA_MAX_BOARD - 1)        \ 
     43                                 * (2 * DFA_MAX_BOARD - 1)) 
     44 
    3445#ifndef EMPTY 
    3546#define EMPTY     0             /* . */ 
    3647#define WHITE     1             /* O */ 
     
    3950#define OUT_BOARD 3             /* # */ 
    4051 
    4152 
    42 /* Maximum pattern matched at one positions. */ 
     53/* Maximum patterns matched at one position - 8 transformations 
     54 * (24 is an arbitrary value). 
     55 */ 
    4356#define DFA_MAX_MATCHED         (8 * 24) 
    4457 
    4558 
    46 /* DFA spiral order. */ 
     59/* DFA spiral order (for each transformation). */ 
    4760extern int spiral[DFA_MAX_ORDER][8]; 
    4861 
    4962void build_spiral_order(void); 
     
    5568/* Attribute list. */ 
    5669typedef struct attrib_rt 
    5770{ 
    58   short val; 
    59   short next; 
     71  short val;  /* Number of a matched pattern. */ 
     72  short next; /* Same position could match to more than one pattern. */ 
    6073} attrib_rt_t; 
    6174 
    6275/* DFA state. */ 
    6376typedef struct state_rt 
    6477{ 
    65   short next[4]; 
    66   short att; 
     78  short next[4]; /* Next state to jump to. */ 
     79  short att;     /* An index in the attributes table. */ 
    6780} state_rt_t; 
    6881 
    6982typedef struct dfa_rt 
  • patterns/patterns.h

    diff -N -r -u -X .ignore gnugo-copy/patterns/patterns.h gnugo/patterns/patterns.h
    old new  
    1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\ 
     1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ 
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    119119 * patterns.db and other databases which are handled by shapes.c. 
    120120 */ 
    121121#define CLASS_O     0x0001   /* O stones must be alive or unknown */ 
    122 #define CLASS_o     0x0002   /* O stones must be dead or unknown */ 
    123 #define CLASS_X     0x0004   /* X stones must be alive or unknown */ 
    124 #define CLASS_x     0x0008   /* X stones must be dead or unknown */ 
     122#define CLASS_o     0x0002   /* O stones must be dead, critical or unknown */ 
     123#define CLASS_X     0x0004   /* X stones must be alive, critical or unknown */ 
     124#define CLASS_x     0x0008   /* X stones must be dead, critical or unknown */ 
    125125#define CLASS_s     0x0010   /* move is a sacrifice */ 
    126126#define CLASS_n     0x0020   /* X could also make this move if we do not */ 
    127127#define CLASS_D     0x0040   /* defense pattern */ 
     
    230230 * Each pattern as a whole is compiled to an instance of this structure. 
    231231 */ 
    232232struct pattern { 
    233   struct patval *patn;  /* array of elements */ 
     233  struct patval *patn;  /* array of elements; some of them can be filtered due to 
     234        &n