summaryrefslogtreecommitdiffstats
path: root/mbbsd/gomo.c
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-09 14:10:51 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-09 14:10:51 +0800
commitfd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66 (patch)
treefadc3445fead35ab66d0196c8dd27b9688f89855 /mbbsd/gomo.c
parente0f54c5ba43c5e4bc15698f5ffb4f222dc1d5e46 (diff)
downloadpttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar.gz
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar.bz2
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar.lz
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar.xz
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.tar.zst
pttbbs-fd0bebe7a68f0ff2a4a3a3aa90fc81bc28ee3e66.zip
merge from my branch
merge chc_*.c to chc.c merge gomo1.c into gomo.c add new feature to chc git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1171 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/gomo.c')
-rw-r--r--mbbsd/gomo.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c
index 0b64e709..1b95ef4d 100644
--- a/mbbsd/gomo.c
+++ b/mbbsd/gomo.c
@@ -1,6 +1,8 @@
/* $Id$ */
#include "bbs.h"
+#define QCAST int (*)(const void *, const void *)
+
static char *chess[] = {"●", "○"};
static int tick, lastcount, mylasttick, hislasttick;
@@ -11,6 +13,139 @@ typedef struct {
static Horder_t *v;
+/* pattern and advance map */
+
+static int
+intrevcmp(const void *a, const void *b)
+{
+ return (*(int *)b - *(int *)a);
+}
+
+// 以 (x,y) 為起點, 方向 (dx,dy), 傳回以 bit 表示相鄰哪幾格有子
+// 如 10111 表示該方向相鄰 1,2,3 有子, 4 空地
+// 最高位 1 表示對方的子, 或是牆
+/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */
+static int
+gomo_getindex(int x, int y, int color, int dx, int dy)
+{
+ int i, k, n;
+ for (n = -1, i = 0, k = 1; i < 5; i++, k*=2) {
+ x += dx;
+ y += dy;
+
+ if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) {
+ n += k;
+ break;
+ } else if (ku[x][y] != BBLANK) {
+ n += k;
+ if (ku[x][y] != color)
+ break;
+ }
+ }
+
+ if (i >= 5)
+ n += k;
+
+ return n;
+}
+
+int
+chkwin(int style, int limit)
+{
+ if (style == 0x0c)
+ return 1 /* style */ ;
+ else if (limit == 0) {
+ if (style == 0x0b)
+ return 1 /* style */ ;
+ return 0;
+ }
+ if ((style < 0x0c) && (style > 0x07))
+ return -1 /* -style */ ;
+ return 0;
+}
+
+/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */
+static int
+dirchk(int x, int y, int color, int limit, int dx, int dy)
+{
+ int le, ri, loc, style = 0;
+
+ le = gomo_getindex(x, y, color, -dx, -dy);
+ ri = gomo_getindex(x, y, color, dx, dy);
+
+ loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) :
+ (((ri * (ri + 1)) >> 1) + le);
+
+ style = pat[loc];
+
+ if (limit == 0)
+ return (style & 0x0f);
+
+ style >>= 4;
+
+ if ((style == 3) || (style == 2)) {
+ int i, n = 0, tmp, nx, ny;
+
+ n = adv[loc / 2];
+
+ if(loc%2==0)
+ n/=16;
+ else
+ n%=16;
+
+ ku[x][y] = color;
+
+ for (i = 0; i < 2; i++) {
+ if ((tmp = (i == 0) ? (-(n >> 2)) : (n & 3)) != 0) {
+ nx = x + (le > ri ? 1 : -1) * tmp * dx;
+ ny = y + (le > ri ? 1 : -1) * tmp * dy;
+
+ if ((dirchk(nx, ny, color, 0, dx, dy) == 0x06) &&
+ (chkwin(getstyle(nx, ny, color, limit), limit) >= 0))
+ break;
+ }
+ }
+ if (i >= 2)
+ style = 0;
+ ku[x][y] = BBLANK;
+ }
+ return style;
+}
+
+/* 例外=F 錯誤=E 有子=D 連五=C 連六=B 雙四=A 四四=9 三三=8 */
+/* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */
+
+/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */
+int
+getstyle(int x, int y, int color, int limit)
+{
+ int i, j, dir[4], style;
+
+ if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ))
+ return 0x0f;
+ if (ku[x][y] != BBLANK)
+ return 0x0d;
+
+ // (-1,1), (0,1), (1,0), (1,1)
+ for (i = 0; i < 4; i++)
+ dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1);
+
+ qsort(dir, 4, sizeof(int), (QCAST)intrevcmp);
+
+ if ((style = dir[0]) >= 2) {
+ for (i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) {
+ if ((style > j) || (dir[i] < 2))
+ break;
+ if (dir[i] > 3)
+ style = 9;
+ else if ((style < 7) && (style > 3))
+ style = 7;
+ else
+ style = 8;
+ }
+ }
+ return style;
+}
static void
HO_init(Horder_t *pool)
{