1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*
GNUGO - the game of Go (Wei-Chi)
Version 1.2 last revised 10-31-95
Copyright (C) Free Software Foundation, Inc.
written by Man L. Li
modified by Wayne Iba
modified by Frank Pursel <fpp%minor.UUCP@dragon.com>
documented by Bob Webber
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation - version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License in file COPYING for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Please report any bug/fix, modification, suggestion to
manli@cs.uh.edu
*/
/*-----------------------------------
matchpat.c -- Match pattern moves
-----------------------------------*/
#include "gnugo.h"
#include "patterns.h"
#define abs(x) ((x) < 0 ? -(x) : (x))
#define line(x) (abs(x - 9))
extern unsigned char p[19][19]; /* go board */
extern int mymove, umove; /* computer color, opponent color */
extern int lib; /* current stone liberty */
int matchpat(int m, /* row origin */
int n, /* column origin */
int *i, /* row number of next move */
int *j, /* column number of next move */
int *val) /* next move value */
/* match pattern and get next move */
{
/* transformation matrice */
static int trf [8][2][2] = {
{{1, 0}, {0, 1}}, /* linear transfomation matrix */
{{1, 0}, {0, -1}}, /* invert */
{{0, 1}, {-1, 0}}, /* rotate 90 */
{{0, -1}, {-1, 0}}, /* rotate 90 and invert */
{{-1, 0}, {0, 1}}, /* flip left */
{{-1, 0}, {0, -1}}, /* flip left and invert */
{{0, 1}, {1, 0}}, /* rotate 90 and flip left */
{{0, -1}, {1, 0}} /* rotate 90, flip left and invert */
};
int k, my, nx, ll, r, cont;
int ti, tj, tval;
*i = -1; *j = -1; *val = -1;
for (r = 0; r < PATNO; r++)
/* try each pattern */
for (ll = 0; ll < pat[r].trfno; ll++)
/* try each orientation transformation */
{
k = 0; cont = 1;
while ((k != pat[r].patlen) && cont)
/* match each point */
{
/* transform pattern real coordinate */
nx = n + trf[ll][0][0] * pat[r].patn[k].x
+ trf[ll][0][1] * pat[r].patn[k].y;
my = m + trf[ll][1][0] * pat[r].patn[k].x
+ trf[ll][1][1] * pat[r].patn[k].y;
/* outside the board */
if ((my < 0) || ( my > 18) || (nx < 0) || (nx > 18))
{
cont = 0;
break;
}
switch (pat[r].patn[k].att) {
case 0 : if (p[my][nx] == EMPTY) /* open */
break;
else
{
cont = 0;
break;
}
case 1 : if (p[my][nx] == umove) /* your piece */
break;
else
{
cont = 0;
break;
}
case 2 : if (p[my][nx] == mymove) /* my piece */
break;
else
{
cont = 0;
break;
}
case 3 : if (p[my][nx] == EMPTY) /* open for new move */
{
lib = 0;
countlib(my, nx, mymove); /* check liberty */
if (lib > 1) /* move o.k. */
{
ti = my;
tj = nx;
break;
}
else
{
cont = 0;
break;
}
}
else
{
cont = 0;
break;
}
case 4 : if ((p[my][nx] == EMPTY) /* open on edge */
&& ((my == 0) || (my == 18) || (nx == 0) || (nx == 18)))
break;
else
{
cont = 0;
break;
}
case 5 : if ((p[my][nx] == umove) /* your piece on edge */
&& ((my == 0) || (my == 18) || (nx == 0) || (nx == 18)))
break;
else
{
cont = 0;
break;
}
case 6 : if ((p[my][nx] == mymove) /* my piece on edge */
&& ((my == 0) || (my == 18) || (nx == 0) || (nx == 18)))
break;
else
{
cont = 0;
break;
}
}
++k;
}
if (cont) /* match pattern */
{
tval = pat[r].patwt;
if ((r >= 8) && (r <= 13)) /* patterns for expand region */
{
if (line(ti) > 7) /* penalty on line 1, 2 */
tval--;
else
if ((line(ti) == 6) || (line(ti) == 7))
tval++; /* reward on line 3, 4 */
if (line(tj) > 7) /* penalty on line 1, 2 */
tval--;
else
if ((line(tj) == 6) || (line(tj) == 7))
tval++; /* reward on line 3, 4 */
}
if (tval > *val)
{
*val = tval;
*i = ti;
*j = tj;
}
}
}
if (*val > 0) /* pattern matched */
return 1;
else /* match failed */
return 0;
} /* end matchpat */
|