diff -N -r -u -X .ignore gnugo-copy/engine/matchpat.c gnugo/engine/matchpat.c
|
old
|
new
|
|
| 2 | 2 | * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * |
| 3 | 3 | * http://www.gnu.org/software/gnugo/ for more information. * |
| 4 | 4 | * * |
| 5 | | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006 * |
| | 5 | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * |
| 6 | 6 | * by the Free Software Foundation. * |
| 7 | 7 | * * |
| 8 | 8 | * This program is free software; you can redistribute it and/or * |
| … |
… |
|
| 135 | 135 | |
| 136 | 136 | /* Forward declarations. */ |
| 137 | 137 | |
| 138 | | static void fixup_patterns_for_board_size(struct pattern *pattern); |
| | 138 | static void fixup_patterns_for_board_size(struct pattern_db *pdb); |
| 139 | 139 | static void prepare_for_match(int color); |
| 140 | 140 | static void do_matchpat(int anchor, matchpat_callback_fn_ptr callback, |
| 141 | 141 | int color, struct pattern *database, |
| … |
… |
|
| 214 | 214 | */ |
| 215 | 215 | |
| 216 | 216 | static void |
| 217 | | fixup_patterns_for_board_size(struct pattern *pattern) |
| | 217 | fixup_patterns_for_board_size(struct pattern_db *pdb) |
| 218 | 218 | { |
| | 219 | struct pattern *pattern = pdb->patterns; |
| | 220 | int undo = pdb->fixed_for_size != -1; |
| | 221 | |
| 219 | 222 | for (; pattern->patn; ++pattern) |
| 220 | 223 | if (pattern->edge_constraints != 0) { |
| 221 | 224 | |
| … |
… |
|
| 225 | 228 | * called, this step is effectively a no-op. |
| 226 | 229 | */ |
| 227 | 230 | |
| 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; |
| 230 | 234 | |
| 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; |
| 233 | 237 | |
| 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; |
| 236 | 240 | |
| 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 | } |
| 239 | 244 | |
| 240 | 245 | /* we extend the pattern in the direction opposite the constraint, |
| 241 | 246 | * such that maxi (+ve) - mini (-ve) = board_size-1 |
| … |
… |
|
| 342 | 347 | { |
| 343 | 348 | int end_transformation; |
| 344 | 349 | 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 */ |
| 346 | 351 | int found_goal; |
| 347 | 352 | |
| 348 | 353 | /* We can check the color of the anchor stone now. |
| … |
… |
|
| 365 | 370 | if (anchor_test != pattern->anchored_at_X) |
| 366 | 371 | continue; /* does not match the anchor */ |
| 367 | 372 | |
| 368 | | ll = 0; /* first transformation number */ |
| 369 | | end_transformation = pattern->trfno; |
| 370 | | |
| 371 | 373 | /* Ugly trick for dealing with 'O' symmetry. */ |
| 372 | 374 | if (pattern->trfno == 5) { |
| 373 | 375 | ll = 2; |
| 374 | 376 | end_transformation = 6; |
| 375 | 377 | } |
| | 378 | else { |
| | 379 | ll = 0; /* first transformation number */ |
| | 380 | end_transformation = pattern->trfno; |
| | 381 | } |
| 376 | 382 | |
| 377 | 383 | /* try each orientation transformation. Assume at least 1 */ |
| 378 | 384 | |
| … |
… |
|
| 425 | 431 | } |
| 426 | 432 | |
| 427 | 433 | /* 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 */ |
| 430 | 439 | 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 */ |
| 432 | 441 | |
| 433 | 442 | /* Work out the position on the board of this pattern element. */ |
| 434 | 443 | |
| 435 | 444 | /* transform pattern real coordinate... */ |
| 436 | | pos = AFFINE_TRANSFORM(pattern->patn[k].offset, ll, anchor); |
| | 445 | pos = AFFINE_TRANSFORM(elpat->offset, ll, anchor); |
| 437 | 446 | |
| 438 | 447 | ASSERT_ON_BOARD1(pos); |
| 439 | 448 | |
| … |
… |
|
| 441 | 450 | if ((board[pos] & and_mask[color-1][att]) != val_mask[color-1][att]) |
| 442 | 451 | goto match_failed; |
| 443 | 452 | |
| 444 | | if (goal != NULL && board[pos] != EMPTY && goal[pos]) |
| | 453 | if (!found_goal && board[pos] && goal[pos]) |
| 445 | 454 | found_goal = 1; |
| 446 | 455 | |
| 447 | 456 | /* Check out the class_X, class_O, class_x, class_o |
| … |
… |
|
| 463 | 472 | |
| 464 | 473 | |
| 465 | 474 | /* Make it here ==> We have matched all the elements to the board. */ |
| 466 | | if ((goal != NULL) && !found_goal) |
| | 475 | if (!found_goal) |
| 467 | 476 | goto match_failed; |
| 468 | 477 | |
| 469 | 478 | #if PROFILE_PATTERNS |
| … |
… |
|
| 485 | 494 | pattern->name, ll, anchor); |
| 486 | 495 | |
| 487 | 496 | } while (++ll < end_transformation); /* ll loop over symmetries */ |
| 488 | | } /* if not rejected by maxwt */ |
| | 497 | } |
| 489 | 498 | } while ((++pattern)->patn); /* loop over patterns */ |
| 490 | 499 | } |
| 491 | 500 | |
| … |
… |
|
| 493 | 502 | /* |
| 494 | 503 | * Scan the board to get patterns anchored by anchor from color |
| 495 | 504 | * 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) ! |
| 497 | 506 | */ |
| 498 | 507 | static void |
| 499 | 508 | matchpat_loop(matchpat_callback_fn_ptr callback, int color, int anchor, |
| … |
… |
|
| 503 | 512 | int pos; |
| 504 | 513 | |
| 505 | 514 | 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])) |
| 507 | 516 | do_matchpat(pos, callback, color, pdb->patterns, |
| 508 | 517 | callback_data, goal); |
| 509 | 518 | } |
| … |
… |
|
| 537 | 546 | static void do_dfa_matchpat(dfa_rt_t *pdfa, |
| 538 | 547 | int anchor, matchpat_callback_fn_ptr callback, |
| 539 | 548 | 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]); |
| 542 | 550 | static void check_pattern_light(int anchor, |
| 543 | 551 | matchpat_callback_fn_ptr callback, |
| 544 | 552 | int color, struct pattern *pattern, int ll, |
| 545 | 553 | void *callback_data, |
| 546 | | signed char goal[BOARDMAX], |
| 547 | | int anchor_in_goal); |
| | 554 | signed char goal[BOARDMAX]); |
| 548 | 555 | static void dfa_matchpat_loop(matchpat_callback_fn_ptr callback, |
| 549 | 556 | int color, int anchor, |
| 550 | 557 | struct pattern_db *pdb, void *callback_data, |
| … |
… |
|
| 643 | 650 | scan_for_patterns(dfa_rt_t *pdfa, int l, int *dfa_pos, int *pat_list) |
| 644 | 651 | { |
| 645 | 652 | int delta; |
| 646 | | int state = 1; /* initial state */ |
| | 653 | const state_rt_t *state = pdfa->states + 1; /* initial state */ |
| 647 | 654 | int row = 0; /* initial row */ |
| 648 | 655 | int id = 0; /* position in id_list */ |
| 649 | 656 | |
| 650 | | do { |
| | 657 | for (;;) { |
| 651 | 658 | /* collect patterns indexes */ |
| 652 | | int att = pdfa->states[state].att; |
| | 659 | int att = state->att; |
| 653 | 660 | while (att != 0) { |
| 654 | | pat_list[id] = pdfa->indexes[att].val; |
| 655 | | id++; |
| | 661 | pat_list[id++] = pdfa->indexes[att].val; |
| 656 | 662 | att = pdfa->indexes[att].next; |
| 657 | 663 | } |
| 658 | 664 | |
| 659 | 665 | /* 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 */ |
| 664 | 669 | |
| 665 | | return id; |
| | 670 | state += delta; |
| | 671 | } |
| 666 | 672 | } |
| 667 | 673 | |
| 668 | 674 | |
| … |
… |
|
| 671 | 677 | do_dfa_matchpat(dfa_rt_t *pdfa, |
| 672 | 678 | int anchor, matchpat_callback_fn_ptr callback, |
| 673 | 679 | 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]) |
| 676 | 681 | { |
| 677 | 682 | int k; |
| 678 | 683 | 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). */ |
| 680 | 686 | int num_matched = 0; |
| 681 | 687 | int *dfa_pos = dfa_p + DFA_POS(I(anchor), J(anchor)); |
| 682 | 688 | |
| … |
… |
|
| 694 | 700 | |
| 695 | 701 | /* Constraints and other tests. */ |
| 696 | 702 | for (ll = 0, k = 0; ll < 8; k++) { |
| 697 | | int matched; |
| | 703 | struct pattern *matched; |
| 698 | 704 | |
| 699 | 705 | if (patterns[k] == -1) { |
| 700 | 706 | ll++; |
| 701 | 707 | continue; |
| 702 | 708 | } |
| 703 | 709 | |
| 704 | | matched = patterns[k]; |
| | 710 | matched = database + patterns[k]; |
| 705 | 711 | |
| 706 | 712 | #if PROFILE_PATTERNS |
| 707 | | database[matched].dfa_hits++; |
| | 713 | matched->dfa_hits++; |
| 708 | 714 | #endif |
| 709 | 715 | |
| 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); |
| 712 | 728 | } |
| 713 | 729 | } |
| 714 | 730 | |
| … |
… |
|
| 722 | 738 | static void |
| 723 | 739 | check_pattern_light(int anchor, matchpat_callback_fn_ptr callback, int color, |
| 724 | 740 | struct pattern *pattern, int ll, void *callback_data, |
| 725 | | signed char goal[BOARDMAX], int anchor_in_goal) |
| | 741 | signed char goal[BOARDMAX]) |
| 726 | 742 | { |
| 727 | 743 | int k; /* Iterate over elements of pattern */ |
| 728 | | int found_goal = 0; |
| | 744 | int found_goal = (goal == NULL); |
| 729 | 745 | |
| 730 | 746 | #if PROFILE_PATTERNS |
| 731 | 747 | int nodes_before; |
| 732 | 748 | #endif |
| 733 | 749 | |
| 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 |
| 747 | 754 | |
| 748 | | |
| 749 | | /* Now iterate over the elements of the pattern. */ |
| | 755 | /* Iterate over the elements of the pattern. */ |
| 750 | 756 | for (k = 0; k < pattern->patlen; k++) { |
| 751 | 757 | /* match each point */ |
| 752 | 758 | int pos; /* absolute (board) co-ords of |
| … |
… |
|
| 756 | 762 | pos = AFFINE_TRANSFORM(pattern->patn[k].offset, ll, anchor); |
| 757 | 763 | ASSERT_ON_BOARD1(pos); |
| 758 | 764 | |
| 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; |
| 764 | 768 | |
| 765 | 769 | /* class check */ |
| 766 | 770 | ASSERT1(dragon[pos].status < 4, anchor); |
| … |
… |
|
| 770 | 774 | } /* loop over elements */ |
| 771 | 775 | |
| 772 | 776 | /* 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; |
| 777 | 779 | |
| 778 | 780 | #if PROFILE_PATTERNS |
| 779 | 781 | pattern->hits++; |
| … |
… |
|
| 808 | 810 | int pos; |
| 809 | 811 | |
| 810 | 812 | 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])) |
| 812 | 814 | do_dfa_matchpat(pdb->pdfa, pos, callback, color, pdb->patterns, |
| 813 | | callback_data, goal, anchor_in_goal); |
| | 815 | callback_data, goal); |
| 814 | 816 | } |
| 815 | 817 | } |
| 816 | 818 | |
| … |
… |
|
| 852 | 854 | struct pattern_db *pdb, void *callback_data, |
| 853 | 855 | signed char goal[BOARDMAX], int anchor_in_goal) |
| 854 | 856 | { |
| 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; |
| 857 | 859 | |
| 858 | 860 | /* check board size */ |
| 859 | 861 | if (pdb->fixed_for_size != board_size) { |
| 860 | | fixup_patterns_for_board_size(pdb->patterns); |
| | 862 | fixup_patterns_for_board_size(pdb); |
| 861 | 863 | pdb->fixed_for_size = board_size; |
| 862 | 864 | } |
| 863 | 865 | |
| … |
… |
|
| 866 | 868 | loop = dfa_matchpat_loop; |
| 867 | 869 | prepare = dfa_prepare_for_match; |
| 868 | 870 | } |
| | 871 | else { |
| | 872 | loop = matchpat_loop; |
| | 873 | prepare = prepare_for_match; |
| | 874 | } |
| 869 | 875 | |
| 870 | 876 | /* select strategy */ |
| 871 | 877 | switch (color) { |
| 872 | 878 | 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 */ |
| 874 | 881 | prepare(WHITE); |
| 875 | 882 | loop(callback, WHITE, WHITE, pdb, callback_data, goal, anchor_in_goal); |
| 876 | 883 | prepare(BLACK); |
| … |
… |
|
| 878 | 885 | } |
| 879 | 886 | break; |
| 880 | 887 | 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 */ |
| 882 | 890 | prepare(WHITE); |
| 883 | 891 | loop(callback, WHITE, BLACK, pdb, callback_data, goal, anchor_in_goal); |
| 884 | 892 | prepare(BLACK); |
| … |
… |
|
| 896 | 904 | |
| 897 | 905 | |
| 898 | 906 | static int |
| 899 | | fullboard_transform(int pos, int trans) |
| | 907 | fullboard_transform(int pos, int trans, int half_board) |
| 900 | 908 | { |
| 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; |
| 903 | 911 | 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); |
| 905 | 913 | 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); |
| 907 | 915 | } |
| 908 | 916 | |
| 909 | 917 | /* A dedicated matcher which can only do fullboard matching on |
| … |
… |
|
| 919 | 927 | static int color_map[gg_max(WHITE, BLACK) + 1]; |
| 920 | 928 | /* One hash value for each rotation/reflection: */ |
| 921 | 929 | Hash_data current_board_hash[8]; |
| | 930 | int half_board = (board_size-1)/2; |
| | 931 | int half_board_pos = POS(half_board, half_board); |
| 922 | 932 | |
| 923 | 933 | /* Basic sanity check. */ |
| 924 | 934 | gg_assert(color != EMPTY); |
| … |
… |
|
| 936 | 946 | |
| 937 | 947 | /* Get hash data of all rotations/reflections of current board position. */ |
| 938 | 948 | for (ll = 0; ll < 8; ll++) { |
| 939 | | Intersection p[BOARDSIZE]; |
| | 949 | Intersection p[BOARDMAX]; |
| 940 | 950 | int pos; |
| 941 | | for (pos = 0; pos < BOARDSIZE; pos++) |
| | 951 | for (pos = BOARDMIN; pos < BOARDMAX; pos++) |
| 942 | 952 | 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)]]; |
| 944 | 954 | else |
| 945 | 955 | p[pos] = GRAY; |
| 946 | 956 | |
| 947 | 957 | if (ON_BOARD(board_ko_pos)) |
| 948 | 958 | hashdata_recalc(¤t_board_hash[ll], p, |
| 949 | | fullboard_transform(board_ko_pos, ll)); |
| | 959 | fullboard_transform(board_ko_pos, ll, half_board)); |
| 950 | 960 | else |
| 951 | 961 | hashdata_recalc(¤t_board_hash[ll], p, NO_MOVE); |
| 952 | 962 | } |
| … |
… |
|
| 959 | 969 | for (ll = 0; ll < 8; ll++) |
| 960 | 970 | if (hashdata_is_equal(current_board_hash[ll], pattern->fullboard_hash)) { |
| 961 | 971 | /* 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); |
| 964 | 973 | callback(pos, pattern, ll); |
| 965 | 974 | } |
| 966 | 975 | } |
| … |
… |
|
| 1012 | 1021 | int match_color, corner_matchpat_callback_fn_ptr callback, |
| 1013 | 1022 | int callback_color, int trans, int anchor, int stones) |
| 1014 | 1023 | { |
| 1015 | | for (; --num_variations >= 0; variation++) { |
| | 1024 | for (; num_variations--; variation++) { |
| 1016 | 1025 | int move = AFFINE_TRANSFORM(variation->move_offset, trans, anchor); |
| 1017 | 1026 | int color_check = match_color ^ variation->xor_att; |
| 1018 | 1027 | struct corner_pattern *pattern = variation->pattern; |
| … |
… |
|
| 1062 | 1071 | int dx = TRANSFORM(OFFSET(1, 0), k); |
| 1063 | 1072 | int dy = TRANSFORM(OFFSET(0, 1), k); |
| 1064 | 1073 | int pos; |
| | 1074 | int prev_stones; |
| 1065 | 1075 | struct corner_variation *variation = database->top_variations; |
| 1066 | 1076 | |
| 1067 | 1077 | /* Fill in the NUM_STONES() array. We use `max_width' and `max_height' |
| 1068 | 1078 | * fields of database structure to stop working as early as possible. |
| 1069 | 1079 | */ |
| 1070 | | NUM_STONES(anchor) = IS_STONE(board[anchor]); |
| | 1080 | prev_stones = IS_STONE(board[anchor]); |
| | 1081 | NUM_STONES(anchor) = prev_stones; |
| 1071 | 1082 | |
| 1072 | 1083 | pos = anchor; |
| 1073 | 1084 | for (i = 1; i < database->max_height; i++) { |
| … |
… |
|
| 1081 | 1092 | break; |
| 1082 | 1093 | } |
| 1083 | 1094 | |
| 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; |
| 1085 | 1097 | } |
| 1086 | 1098 | |
| 1087 | 1099 | pos = anchor; |
| | 1100 | prev_stones = NUM_STONES(anchor); |
| | 1101 | |
| 1088 | 1102 | for (j = 1; j < database->max_width; j++) { |
| 1089 | 1103 | pos += dy; |
| 1090 | 1104 | if (!ON_BOARD(pos)) { |
| … |
… |
|
| 1096 | 1110 | break; |
| 1097 | 1111 | } |
| 1098 | 1112 | |
| 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; |
| 1100 | 1115 | } |
| 1101 | 1116 | |
| 1102 | 1117 | for (i = 1; i < database->max_height; i++) { |
| 1103 | 1118 | pos = anchor + i * dy; |
| | 1119 | prev_stones = NUM_STONES(pos); |
| 1104 | 1120 | for (j = 1; j < database->max_width; j++) { |
| 1105 | 1121 | 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); |
| 1108 | 1123 | if (ON_BOARD1(pos) && IS_STONE(board[pos])) |
| 1109 | | NUM_STONES(pos)++; |
| | 1124 | prev_stones++; |
| | 1125 | NUM_STONES(pos) = prev_stones; |
| 1110 | 1126 | } |
| 1111 | 1127 | } |
| 1112 | 1128 | |
diff -N -r -u -X .ignore gnugo-copy/patterns/attack.db gnugo/patterns/attack.db
|
old
|
new
|
|
| 54 | 54 | # Even if a ladder works (and is found by the tactical reading) we |
| 55 | 55 | # also want to consider the geta capture. |
| 56 | 56 | |
| 57 | | XOO? capture one stone |
| | 57 | ?OO? capture one stone |
| 58 | 58 | OX.. |
| 59 | 59 | O.*? |
| 60 | 60 | ?.?? |
diff -N -r -u -X .ignore gnugo-copy/patterns/defense.db gnugo/patterns/defense.db
|
old
|
new
|
|
| 80 | 80 | |
| 81 | 81 | Pattern Def4 |
| 82 | 82 | |
| 83 | | XOO? capture one stone |
| | 83 | ?OO? capture one stone |
| 84 | 84 | OX.. |
| 85 | 85 | O.*? |
| 86 | 86 | ?.?? |
diff -N -r -u -X .ignore gnugo-copy/patterns/dfa.h gnugo/patterns/dfa.h
|
old
|
new
|
|
| 2 | 2 | * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * |
| 3 | 3 | * http://www.gnu.org/software/gnugo/ for more information. * |
| 4 | 4 | * * |
| 5 | | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006 * |
| | 5 | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * |
| 6 | 6 | * by the Free Software Foundation. * |
| 7 | 7 | * * |
| 8 | 8 | * This program is free software; you can redistribute it and/or * |
| … |
… |
|
| 24 | 24 | #define _DFA_H_ |
| 25 | 25 | |
| 26 | 26 | |
| | 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 | */ |
| 27 | 31 | #define DFA_MAX_BOARD MAX_BOARD |
| 28 | | #define DFA_MAX_ORDER ((2 * DFA_MAX_BOARD - 1) \ |
| 29 | | * (2 * DFA_MAX_BOARD - 1)) |
| 30 | 32 | #define DFA_BASE (3 * DFA_MAX_BOARD) |
| 31 | 33 | #define DFA_POS(i, j) (((i) + DFA_MAX_BOARD) * DFA_BASE \ |
| 32 | 34 | + ((j) + DFA_MAX_BOARD)) |
| 33 | 35 | |
| | 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 | |
| 34 | 45 | #ifndef EMPTY |
| 35 | 46 | #define EMPTY 0 /* . */ |
| 36 | 47 | #define WHITE 1 /* O */ |
| … |
… |
|
| 39 | 50 | #define OUT_BOARD 3 /* # */ |
| 40 | 51 | |
| 41 | 52 | |
| 42 | | /* Maximum pattern matched at one positions. */ |
| | 53 | /* Maximum patterns matched at one position - 8 transformations |
| | 54 | * (24 is an arbitrary value). |
| | 55 | */ |
| 43 | 56 | #define DFA_MAX_MATCHED (8 * 24) |
| 44 | 57 | |
| 45 | 58 | |
| 46 | | /* DFA spiral order. */ |
| | 59 | /* DFA spiral order (for each transformation). */ |
| 47 | 60 | extern int spiral[DFA_MAX_ORDER][8]; |
| 48 | 61 | |
| 49 | 62 | void build_spiral_order(void); |
| … |
… |
|
| 55 | 68 | /* Attribute list. */ |
| 56 | 69 | typedef struct attrib_rt |
| 57 | 70 | { |
| 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. */ |
| 60 | 73 | } attrib_rt_t; |
| 61 | 74 | |
| 62 | 75 | /* DFA state. */ |
| 63 | 76 | typedef struct state_rt |
| 64 | 77 | { |
| 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. */ |
| 67 | 80 | } state_rt_t; |
| 68 | 81 | |
| 69 | 82 | typedef struct dfa_rt |
diff -N -r -u -X .ignore gnugo-copy/patterns/patterns.h gnugo/patterns/patterns.h
|
old
|
new
|
|
| 1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\ |
| | 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ |
| 2 | 2 | * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * |
| 3 | 3 | * http://www.gnu.org/software/gnugo/ for more information. * |
| 4 | 4 | * * |
| 5 | | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006 * |
| | 5 | * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * |
| 6 | 6 | * by the Free Software Foundation. * |
| 7 | 7 | * * |
| 8 | 8 | * This program is free software; you can redistribute it and/or * |
| … |
… |
|
| 119 | 119 | * patterns.db and other databases which are handled by shapes.c. |
| 120 | 120 | */ |
| 121 | 121 | #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 */ |
| 125 | 125 | #define CLASS_s 0x0010 /* move is a sacrifice */ |
| 126 | 126 | #define CLASS_n 0x0020 /* X could also make this move if we do not */ |
| 127 | 127 | #define CLASS_D 0x0040 /* defense pattern */ |
| … |
… |
|
| 230 | 230 | * Each pattern as a whole is compiled to an instance of this structure. |
| 231 | 231 | */ |
| 232 | 232 | struct 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 |