author | zecke <zecke> | 2004-04-30 13:27:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-30 13:27:34 (UTC) |
commit | b313bfcc63e972b1dfe059d91fe364d535478c7c (patch) (side-by-side diff) | |
tree | 36c52526da889598133698cb7c914fbe134c9594 | |
parent | 7829ac6b0577bf2398110f327a4b5e40435c105b (diff) | |
download | opie-b313bfcc63e972b1dfe059d91fe364d535478c7c.zip opie-b313bfcc63e972b1dfe059d91fe364d535478c7c.tar.gz opie-b313bfcc63e972b1dfe059d91fe364d535478c7c.tar.bz2 |
some long outstanding 'freeze' bug..
having a function pause(){} conflicts with linux version of pause. So instead
of doing nothing... we were forced to pause(2)
-rw-r--r-- | noncore/games/go/goplayutils.c | 2 | ||||
-rw-r--r-- | noncore/games/go/killable.c | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/noncore/games/go/goplayutils.c b/noncore/games/go/goplayutils.c index 9e2ce4c..91c6db2 100644 --- a/noncore/games/go/goplayutils.c +++ b/noncore/games/go/goplayutils.c @@ -535,769 +535,769 @@ respreicen() maxGroupID = gID; newGID = gID; grpMark = 0; } /* respreicen */ /* play z at [x, y]. killFlag is set true if anything is killed. */ killGroup(x, y, me, him) short x, y, me, him; { /* killGroup */ #ifdef DEBUG printf( "killGroup\n" ); #endif playMark = playMark + 1; /* record this kill */ playStack[playMark].kind = rem; playStack[playMark].uval.rem.who = him; playStack[playMark].uval.rem.xl = x; playStack[playMark].uval.rem.yl = y; playStack[playMark].gID = groupIDs[x][y]; playStack[playMark].uval.rem.sNumber = goboard[x][y].mNum; if (showTrees) rstone(x, y); numCapt = numCapt + 1; bord[x][y] = 0; groupIDs[x][y] = 0; if (x > 0) { if (bord[x - 1][y] == me) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x - 1][y]]; } else if (bord[x - 1][y] == him) killGroup(x - 1, y, me , him); } if (x < maxPoint) { if (bord[x + 1][y] == me) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x + 1][y]]; } else if (bord[x + 1][y] == him) killGroup(x + 1, y, me, him); } if (y > 0) { if (bord[x][y - 1] == me) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y - 1]]; } else if (bord[x][y - 1] == him) killGroup(x, y - 1, me, him); } if (y < maxPoint) { if (bord[x][y + 1] == me) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y + 1]]; } else if (bord[x][y + 1] == him) killGroup(x, y + 1, me, him); } } /* killGroup */ mergeGroup(sGID, myGID) short sGID, myGID; { /* mergeGroup */ short i; #ifdef DEBUG printf( "mergeGroup\n" ); #endif for (i = 1; i <= newGID; i++) if (gMap[i] == sGID) { playMark = playMark + 1; playStack[playMark].kind = reMap; playStack[playMark].gID = i; playStack[playMark].uval.reMap.oldGID = sGID; gMap[i] = myGID; } } /* mergeGroup */ tryPlay(x, y, z) short x, y, z; { /* plei */ short i, me, him, myGID; short isNew; #ifdef DEBUG printf( "tryPlay\n" ); #endif me = z; him = -me; killFlag = FALSE; /* set true if something is killed */ numCapt = 0; tryLevel = tryLevel + 1; isNew = FALSE; bord[x][y] = z; /* play the stone */ if ((x > 0) && (bord[x - 1][y] == me)) /* connect to adjacent group */ myGID = gMap[groupIDs[x - 1][y]]; else if ((x < maxPoint) && (bord[x + 1][y] == me)) myGID = gMap[groupIDs[x + 1][y]]; else if ((y > 0) && (bord[x][y - 1] == me)) myGID = gMap[groupIDs[x][y - 1]]; else if ((y < maxPoint) && (bord[x][y + 1] == me)) myGID = gMap[groupIDs[x][y + 1]]; else /* nobody to connect to */ { newGID = newGID + 1; isNew = TRUE; myGID = newGID; gList[myGID].groupMark = 0; gList[myGID].atLevel = tryLevel; gList[myGID].isLive = FALSE; gList[myGID].numEyes = -1; gList[myGID].size = -1; gList[myGID].lx = x; gList[myGID].ly = y; gMap[myGID] = myGID; } groupIDs[x][y] = myGID; playMark = playMark + 1; /* record this move */ playStack[playMark].kind = add; playStack[playMark].uval.add.who = me; playStack[playMark].uval.add.xl = x; playStack[playMark].uval.add.yl = y; playStack[playMark].gID = myGID; playStack[playMark].uval.add.sNumber = 0; if (isNew) playStack[playMark].uval.add.nextGID = newGID - 1; else playStack[playMark].uval.add.nextGID = newGID; if (showTrees) sstone(me, x, y, 0); /* merge adjacent groups */ if ((x > 0) && (bord[x - 1][y] == me) && (gMap[groupIDs[x - 1][y]] != myGID)) mergeGroup(gMap[groupIDs[x - 1][y]], myGID); if ((x < maxPoint) && (bord[x + 1][y] == me) && (gMap[groupIDs[x + 1][y]] != myGID)) mergeGroup(gMap[groupIDs[x + 1][y]], myGID); if ((y > 0) && (bord[x][y - 1] == me) && (gMap[groupIDs[x][y - 1]] != myGID)) mergeGroup(gMap[groupIDs[x][y - 1]], myGID); if ((y < maxPoint) && (bord[x][y + 1] == me) && (gMap[groupIDs[x][y + 1]] != myGID)) mergeGroup(gMap[groupIDs[x][y + 1]], myGID); /* kill opposing groups, listing affected groups */ nlcGroup.indx = 1; nlcGroup.v[1] = myGID; /* init list to include me */ if ((x > 0) && (bord[x - 1][y] == him) && (gList[gMap[groupIDs[x - 1][y]]].libC == 1)) { killFlag = TRUE; killGroup(x - 1, y, me, him); } if ((x < maxPoint) && (bord[x + 1][y] == him) && (gList[gMap[groupIDs[x + 1][y]]].libC == 1)) { killFlag = TRUE; killGroup(x + 1, y, me, him); } if ((y > 0) && (bord[x][y - 1] == him) && (gList[gMap[groupIDs[x][y - 1]]].libC == 1)) { killFlag = TRUE; killGroup(x, y - 1, me, him); } if ((y < maxPoint) && (bord[x][y + 1] == him) && (gList[gMap[groupIDs[x][y + 1]]].libC == 1)) { killFlag = TRUE; killGroup(x, y + 1, me, him); } /* list groups adjacent to me */ if ((x > 0) && (bord[x - 1][y] == him)) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x - 1][y]]; } if ((x < maxPoint) && (bord[x + 1][y] == him)) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x + 1][y]]; } if ((y > 0) && (bord[x][y - 1] == him)) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y - 1]]; } if ((y < maxPoint) && (bord[x][y + 1] == him)) { nlcGroup.indx = nlcGroup.indx + 1; nlcGroup.v[nlcGroup.indx] = gMap[groupIDs[x][y + 1]]; } /* fix liberty count for affected groups */ grpMark = grpMark + 1; for (i = 1; i <= nlcGroup.indx; i++) if (gList[nlcGroup.v[i]].groupMark != grpMark) { if (gList[nlcGroup.v[i]].atLevel != tryLevel) { playMark = playMark + 1; playStack[playMark].kind = chLib; playStack[playMark].gID = nlcGroup.v[i]; playStack[playMark].uval.chLib.oldLevel = gList[nlcGroup.v[i]].atLevel; playStack[playMark].uval.chLib.oldLC = gList[nlcGroup.v[i]].libC; } gList[nlcGroup.v[i]].groupMark = grpMark; gList[nlcGroup.v[i]].atLevel = tryLevel; spanGroup(gList[nlcGroup.v[i]].lx, gList[nlcGroup.v[i]].ly, &pPlist); gList[nlcGroup.v[i]].libC = pPlist.indx; } } /* plei */ saveState() { /* saveState */ playMark = 0; tryLevel = 0; newGID = maxGroupID; } /* saveState */ /* undoes a move sequence back to uMark */ undoTo(uMark) short uMark; { /* undoTo */ short i, xl, yl; #ifdef DEBUG printf( "undoTo\n" ); #endif for (i = playMark; i >= uMark + 1; i--) if (playStack[i].kind == rem) { xl = playStack[i].uval.rem.xl; yl = playStack[i].uval.rem.yl; bord[xl][yl] = playStack[i].uval.rem.who; groupIDs[xl][yl] = playStack[i].gID; if (showTrees) sstone(playStack[i].uval.rem.who, xl, yl, playStack[i].uval.rem.sNumber); } else if (playStack[i].kind == add) { xl = playStack[i].uval.add.xl; yl = playStack[i].uval.add.yl; bord[xl][yl] = 0; groupIDs[xl][yl] = 0; tryLevel = tryLevel - 1; newGID = playStack[i].uval.add.nextGID; if (showTrees) rstone(xl, yl); } else if (playStack[i].kind == reMap) gMap[playStack[i].gID] = playStack[i].uval.reMap.oldGID; else /* change libs of group - gID is pre-mapped */ { gList[playStack[i].gID].libC = playStack[i].uval.chLib.oldLC; gList[playStack[i].gID].atLevel = playStack[i].uval.chLib.oldLevel; } playMark = uMark; } /* undoTo */ /* restores the state of the world after trying a move sequence */ restoreState() { /* restoreState */ #ifdef DEBUG printf( "restoreState\n" ); #endif if (playMark > 0) { undoTo(0); playMark = 0; tryLevel = 0; } } /* restoreState */ /* exception bpt; */ /* returns true if (the group (at gx, gy) is saveable. if so, returns the point to play at in savex, savey */ short saveable(gx, gy, savex, savey) short gx, gy, *savex, *savey; { /* saveable */ short me, him, gx1, gx2, i, j, smark, mark2, tl, result; char sChar; sPointList dList; point tp; short libList[maxSPoint+1]; #ifdef DEBUG printf( "saveable\n" ); #endif dbStop = TRUE; me = bord[gx][gy]; him = -me; if (me == 1) sChar = '|'; else sChar = '>'; /* write(sChar); */ spanGroup(gx, gy, &plist3); /* find my liberties */ if (adjInAtari) /* one of my options is to kill */ { listAdjacents(gx, gy, &aList); for (i = 1; i <= aList.indx; i++) if (gList[aList.v[i]].libC == 1) { spanGroup(gList[aList.v[i]].lx, gList[aList.v[i]].ly, &pList1); /* find it's liberty */ plist3.indx = plist3.indx + 1; plist3.p[plist3.indx].px = pList1.p[1].px; plist3.p[plist3.indx].py = pList1.p[1].py; } } for (i = 1; i <= maxSPoint; i++) libList[i] = -1; if ((utilPlayLevel > 4) && (gList[gMap[groupIDs[gx][gy]]].libC > 1)) /* account for diags */ { listDiags(gx, gy, &dList); j = 0; i = plist3.indx; while ((j < dList.indx) && (i < maxSPoint)) { j = j + 1; i = i + 1; libList[i] = 100; plist3.p[i].px = dList.p[j].px; plist3.p[i].py = dList.p[j].py; } plist3.indx = i; } if (plist3.indx > 1) /* sort by decreasing lib count */ { for (i = 1; i <= plist3.indx; i++) if (libList[i] != 100) { mark2 = playMark; tryPlay(plist3.p[i].px, plist3.p[i].py, me); libList[i] = gList[gMap[groupIDs[gx][gy]]].libC; if (libList[i] > treeLibLim) /* i'm safe */ { *savex = plist3.p[i].px; *savey = plist3.p[i].py; result = TRUE; goto one; } undoTo(mark2); } for (i = 1; i <= plist3.indx - 1; i++) for (j = i + 1; j <= plist3.indx; j++) if (libList[i] < libList[j]) { tl = libList[i]; libList[i] = libList[j]; libList[j] = tl; tp = plist3.p[i]; plist3.p[i] = plist3.p[j]; plist3.p[j] = tp; } } for (i = 1; i <= plist3.indx; i++) { *savex = plist3.p[i].px; *savey = plist3.p[i].py; if (legal[*savex][*savey]) { smark = playMark; tryPlay(*savex, *savey, me); - pause(); +//pause(); if (gList[gMap[groupIDs[*savex][*savey]]].libC > 1) if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim) { restoreState(); /* sClearChar(sChar, rXor); */ return TRUE; } else if (gList[gMap[groupIDs[gx][gy]]].libC > 1) if (! killable(gx, gy, &gx1, &gx2)) { restoreState(); /* sClearChar(sChar, rXor); */ return TRUE; } undoTo(smark); } } result = FALSE; one: restoreState(); /* sClearChar(sChar, rXor); */ return result; } /* saveable */ /* marks unsavable groups as dead */ markDead() { /* markDead */ short i, j, gx, gy, result; #ifdef DEBUG printf( "markDead\n" ); #endif for (i = 1; i <= maxGroupID; i++) if (killable(gList[i].lx, gList[i].ly, &gx, &gy)) result = ! saveable(gList[i].lx, gList[i].ly, &gx, &gy); else result = FALSE; for (i = 0; i <= maxPoint; i++) for (j = 0; j <= maxPoint; j++) if (bord[i][j] == 0) ndbord[i][j] = 0; else if (gList[groupIDs[i][j]].isDead) ndbord[i][j] = 0; else ndbord[i][j] = bord[i][j]; } /* markDead */ /* marks groups with two eyes as live */ MLspan(x, y, saw1, sawm1, size, sMark) short x, y, *saw1, *sawm1, *size, sMark; { /* span */ if (ndbord[x][y] == 1) *saw1 = TRUE; else if (ndbord[x][y] == -1) *sawm1 = TRUE; else if (sGroups[x][y] == 0) { sGroups[x][y] = sMark; *size = *size + 1; if (x > 0) MLspan(x - 1, y, saw1, sawm1, size, sMark); if (x < maxPoint) MLspan(x + 1, y, saw1, sawm1, size, sMark); if (y > 0) MLspan(x, y - 1, saw1, sawm1, size, sMark); if (y < maxPoint) MLspan(x, y + 1, saw1, sawm1, size, sMark); } } /* span */ short CLspan(x, y, numEyes, who) short x, y, *numEyes, who; { /* span */ markBoard[x][y] = marker; if (ndbord[x][y] == 0) { if ((sList[sGroups[x][y]].sm != marker) && (sList[sGroups[x][y]].w == who)) { sList[sGroups[x][y]].sm = marker; if (sList[sGroups[x][y]].s > 6) return TRUE; *numEyes = *numEyes + 1; if (*numEyes > 1) return TRUE; } } else if (bord[x][y] == who) { if ((x > 0) && (markBoard[x - 1][y] != marker)) if (CLspan(x - 1, y, numEyes, who)) return TRUE; if ((x < maxPoint) && (markBoard[x + 1][y] != marker)) if (CLspan(x + 1, y, numEyes, who)) return TRUE; if ((y > 0) && (markBoard[x][y - 1] != marker)) if (CLspan(x, y - 1, numEyes, who)) return TRUE; if ((y < maxPoint) && (markBoard[x][y + 1] != marker)) if (CLspan(x, y + 1, numEyes, who)) return TRUE; } return FALSE; } /* span */ short checkLive(x, y) short x, y; { /* checkLive */ short numEyes, who; #ifdef DEBUG printf( "checkLive\n" ); #endif numEyes = 0; who = bord[x][y]; marker = marker + 1; return CLspan(x, y, &numEyes, who); } /* checkLive */ markLive() { /* markLive */ short i, j, size, sMark = 0; short saw1, sawm1; #ifdef DEBUG printf( "markLive\n" ); #endif initArray(sGroups); for (i = 0; i <= maxPoint; i++) for (j = 0; j <= maxPoint; j++) if ((sGroups[i][j] == 0) && (ndbord[i][j] == 0)) { size = 0; sMark = sMark + 1; sawm1 = FALSE; saw1 = FALSE; MLspan(i, j, &saw1, &sawm1, &size, sMark); sList[sMark].s = size; sList[sMark].sm = 0; if (sawm1) if (saw1) sList[sMark].w = 0; else sList[sMark].w = -1; else if (saw1) sList[sMark].w = 1; else sList[sMark].w = 0; } for (i = 1; i <= maxGroupID; i++) if (! gList[i].isDead) gList[i].isLive = checkLive(gList[i].lx, gList[i].ly); } /* markLive */ /* generates the connection map and the protected point map. */ genConnects() { /* genConnects */ short x, y, numStones; #ifdef DEBUG printf( "genConnects\n" ); #endif for (x = 0; x <= maxPoint; x++) for (y = 0; y <= maxPoint; y++) { connectMap[x][y] = 0; protPoints[x][y] = 0; } for (x = 0; x <= maxPoint; x++) for (y = 0; y <= maxPoint; y++) if (bord[x][y] == 1) /* map connections to this stone */ { if (x > 0) /* direct connection */ connectMap[x - 1][y] += 1; if (x < maxPoint) connectMap[x + 1][y] += 1; if (y > 0) connectMap[x][y - 1] += 1; if (y < maxPoint) connectMap[x][y + 1] += 1; if ((x > 0) && (y > 0) && /* diagonal connection */ (bord[x - 1][y] == 0) && (bord[x][y - 1] == 0)) connectMap[x - 1][y - 1] += 1; if ((x < maxPoint) && (y > 0) && (bord[x + 1][y] == 0) && (bord[x][y - 1] == 0)) connectMap[x + 1][y - 1] += 1; if ((x < maxPoint) && (y < maxPoint) && (bord[x + 1][y] == 0) && (bord[x][y + 1] == 0)) connectMap[x + 1][y + 1] += 1; if ((x > 0) && (y < maxPoint) && (bord[x - 1][y] == 0) && (bord[x][y + 1] == 0)) connectMap[x - 1][y + 1] += 1; if ((x > 1) && (claim[x - 1][y] > 3)) /* one point jump */ connectMap[x - 2][y] += 1; if ((x < (maxPoint - 1)) && (claim[x + 1][y] > 3)) connectMap[x + 2][y] += 1; if ((y > 1) && (claim[x][y - 1] > 3)) connectMap[x][y - 2] += 1; if ((y < (maxPoint - 1)) && (claim[x][y + 1] > 3)) connectMap[x][y + 2] += 1; if ((x > 1) && (y > 0) && /* knight's move */ (claim[x - 1][y] > 3) && (claim[x - 1][y - 1] > 3)) connectMap[x - 2][y - 1] += 1; if ((x > 0) && (y > 1) && (claim[x][y - 1] > 3) && (claim[x - 1][y - 1] > 3)) connectMap[x - 1][y - 2] += 1; if ((x < (maxPoint - 1)) && (y > 0) && (claim[x + 1][y] > 3) && (claim[x + 1][y - 1] > 3)) connectMap[x + 2][y - 1] += 1; if ((x < maxPoint) && (y > 1) && (claim[x][y - 1] > 3) && (claim[x + 1][y - 1] > 3)) connectMap[x + 1][y - 2] += 1; if ((x > 1) && (y < maxPoint) && (claim[x - 1][y] > 3) && (claim[x - 1][y + 1] > 3)) connectMap[x - 2][y + 1] += 1; if ((x > 0) && (y < (maxPoint - 1)) && (claim[x][y + 1] > 3) && (claim[x - 1][y + 1] > 3)) connectMap[x - 1][y + 2] += 1; if ((x < (maxPoint - 1)) && (y < maxPoint) && (claim[x + 1][y] > 3) && (claim[x + 1][y + 1] > 3)) connectMap[x + 2][y + 1] += 1; if ((x < maxPoint) && (y < (maxPoint - 1)) && (claim[x][y + 1] > 3) && (claim[x + 1][y + 1] > 3)) connectMap[x + 1][y + 2] += 1; } else if (bord[x][y] == 0) /* see if protected point */ { numStones = 0; if (x == 0) numStones = numStones + 1; if (y == 0) numStones = numStones + 1; if (x == maxPoint) numStones = numStones + 1; if (y == maxPoint) numStones = numStones + 1; if ((x > 0) && (bord[x - 1][y] == 1)) numStones = numStones + 1; if ((y > 0) && (bord[x][y - 1] == 1)) numStones = numStones + 1; if ((x < maxPoint) && (bord[x + 1][y] == 1)) numStones = numStones + 1; if ((y < maxPoint) && (bord[x][y + 1] == 1)) numStones = numStones + 1; if (numStones == 4) protPoints[x][y] = 1; else if (numStones == 3) { if ((x > 0) && ((bord[x - 1][y] == 0) || ((bord[x - 1][y] == -1) && (gList[groupIDs[x - 1][y]].libC == 1)))) protPoints[x][y] = 1; else if ((x < maxPoint) && ((bord[x + 1][y] == 0) || ((bord[x + 1][y] == -1) && (gList[groupIDs[x + 1][y]].libC == 1)))) protPoints[x][y] = 1; else if ((y > 0) && ((bord[x][y - 1] == 0) || ((bord[x][y - 1] == -1) && (gList[groupIDs[x][y - 1]].libC == 1)))) protPoints[x][y] = 1; else if ((y < maxPoint) && ((bord[x][y + 1] == 0) || ((bord[x][y + 1] == -1) && (gList[groupIDs[x][y + 1]].libC == 1)))) protPoints[x][y] = 1; } } for (x = 0; x <= maxPoint; x++) for (y = 0; y <= maxPoint; y++) if (bord[x][y] != 0) { connectMap[x][y] = 0; protPoints[x][y] = 0; } } /* genConnects */ /* generates the whole state of the game. */ genState() { /* genState */ #ifdef DEBUG printf( "genState\n" ); #endif inGenState = TRUE; respreicen(); markDead(); markLive(); spread(); genConnects(); #ifdef DEBUG /* printBoard( claim, "claim" ); */ /* printBoard( bord, "bord" ); */ /* printBoard( ndbord, "ndbord" ); printBoard( sGroups, "sGroups" ); printBoard( groupIDs, "groupIDs" ); printBoard( connectMap, "connectMap" ); printBoard( protPoints, "protPoints" ); */ #endif inGenState = FALSE; } /* genState */ /* generates a value for the [x, y] location that appears to get larger for points that are saddle points in the influence graph (klein) */ short tencen(x, y) short x, y; { /* tencen */ short a, b, c, d, w, z; #ifdef DEBUG printf( "tencen\n" ); #endif if (claim[x][y] > -1) /* if (he does not influence this area, return 50 */ { return 50; } w = claim[x][y]; /* w <= -1 */ a = iNil; if (x > 0) if (claim[x - 1][y] > -1) /* if (neighbor is not influenced by him */ a = claim[x - 1][y] - w; /* score is sum of his influence on central */ b = iNil; /* point and my influence on this neighbor */ if (y > 0) if (claim[x][y - 1] > -1) b = claim[x][y - 1] - w; c = iNil; if (x < maxPoint) if (claim[x + 1][y] > -1) c = claim[x + 1][y] - w; d = iNil; if (y < maxPoint) if (claim[x][y + 1] > -1) d = claim[x][y + 1] - w; z = a; /* z = max(a, b, c, d) */ if (z != iNil) { if ((b != iNil) && (b > z)) z = b; } else z = b; if (z != iNil) { if ((c != iNil) && (c > z)) z = c; } else z = c; if (z != iNil) { if ((d != iNil) && (d > z)) z = d; } else z = d; if ((z != iNil) && ((x == 0) || (y == 0) || (x == maxPoint) || (y == maxPoint))) z = z * 2; /* double z if (on the edge of the board ?? */ if (z != iNil) return z; else return 50; } /* tencen */ initGPUtils() { /* initGPUtils */ #ifdef DEBUG printf( "initGPUtils\n" ); #endif initArray(markBoard); initState(); diff --git a/noncore/games/go/killable.c b/noncore/games/go/killable.c index 3ed2d2e..23a133d 100644 --- a/noncore/games/go/killable.c +++ b/noncore/games/go/killable.c @@ -1,373 +1,373 @@ /* By Stoney Ballard */ /* Ported from Pascal to C by Todd R. Johnson */ #include "go.h" #include "goplayutils.h" #include "amigo.h" extern intBoard bord, groupIDs; extern boolBoard legal; extern groupRec gList[maxGroup]; extern short gMap[maxGroup], adjInAtari, adj2Libs, playMark, treeLibLim, utilPlayLevel, killFlag, depthLimit, dbStop, showTrees; extern pointList plist2; /* returns true if the group (at x, y) is killable. if so, returns the point to play at in killx, killy. */ short me, him, depth, i, j, tryCount, tl, topMark, tkMark, mark2; char sChar; sPointList lList, dList; point tp; short libList[maxSPoint+1]; short esc; short mtNbrs(x, y) short x, y; { /* mtNbrs */ short n = 0; if ((x > 0) && (bord[x - 1][y] == 0)) n = n + 1; if ((x < maxPoint) && (bord[x + 1][y] == 0)) n = n + 1; if ((y > 0) && (bord[x][y - 1] == 0)) n = n + 1; if ((y < maxPoint) && (bord[x][y + 1] == 0)) n = n + 1; return n; } /* mtNbrs */ short killTree(tx, ty, gx, gy, escape, tkMark) short tx, ty, gx, gy, *escape, tkMark; { /* killTree */ short curMark, mark2, mark3, i, j, k, tl, dStart, result; sPointList lList1, lList2; short libList[maxSPoint+1]; point tp; short esc = FALSE; tryCount = tryCount + 1; if (tryCount > tryLimit) { undoTo(tkMark); /* for (i = 1; i <= depth - 1; i++) { sClearChar(sChar, rXor); } */ depth = 1; return FALSE; } /* write(sChar); */ depth = depth + 1; curMark = playMark; tryPlay(tx, ty, me); /* try my move */ - pause(); +// pause(); if (gList[gMap[groupIDs[tx][ty]]].libC == 0) /* I'm dead */ { result = FALSE; goto one; } else if (killFlag) /* I killed something of his */ { result = TRUE; goto one; } else if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim) /* safe */ { result = FALSE; goto one; } else { sSpanGroup(gx, gy, &lList1); /* find his liberties */ if (gList[gMap[groupIDs[tx][ty]]].libC == 1) /* he can kill me */ { if (lList1.indx < maxSPoint) /* add that option to his list */ { lList1.indx = lList1.indx + 1; spanGroup(tx, ty, &plist2); /* find my liberty */ lList1.p[lList1.indx].px = plist2.p[1].px; lList1.p[lList1.indx].py = plist2.p[1].py; } else { result = FALSE; goto one; } } for (i = 1; i <= maxSPoint; i++) /* init liblist so diags can be marked */ libList[i] = -1; if ((utilPlayLevel > 4) && (lList1.indx > 1) && (gList[gMap[groupIDs[gx][gy]]].libC > 1)) /* try diags */ { listDiags(gx, gy, &dList); j = 0; i = lList1.indx; while ((j < dList.indx) && (i < maxSPoint)) { j = j + 1; i = i + 1; libList[i] = 0; /* mark this as a diag */ lList1.p[i].px = dList.p[j].px; lList1.p[i].py = dList.p[j].py; } lList1.indx = i; } if (lList1.indx > 1) /* sort by decreasing lib count */ { for (i = 1; i <= lList1.indx; i++) if (libList[i] != 0) /* diags are tried last */ { mark2 = playMark; tryPlay(lList1.p[i].px, lList1.p[i].py, him); libList[i] = gList[gMap[groupIDs[gx][gy]]].libC; if ((libList[i] > treeLibLim) || ((libList[i] > (depthLimit - depth)) && (libList[i] > 2))) { *escape = TRUE; result = FALSE; goto one; } undoTo(mark2); } for (i = 1; i <= lList1.indx - 1; i++) for (j = i + 1; j <= lList1.indx; j++) if (libList[i] < libList[j]) { tl = libList[i]; libList[i] = libList[j]; libList[j] = tl; tp = lList1.p[i]; lList1.p[i] = lList1.p[j]; lList1.p[j] = tp; } } for (i = 1; i <= lList1.indx + 1; i++) /* try his responses */ { mark2 = playMark; if (i <= lList1.indx) /* try his move */ { tryPlay(lList1.p[i].px, lList1.p[i].py, him); /* play his response */ - pause(); +// pause(); if (gList[gMap[groupIDs[lList1.p[i].px] [lList1.p[i].py]]].libC < 2) goto two; /* a bogus move */ } else if (gList[gMap[groupIDs[gx][gy]]].libC <= 1) { result = TRUE; goto one; } if (gList[gMap[groupIDs[gx][gy]]].libC > treeLibLim) { *escape = TRUE; result = FALSE; goto one; } if (gList[gMap[groupIDs[gx][gy]]].libC > 1) { /* look at my responses */ sSpanGroup(gx, gy, &lList2); /* list his liberties */ dStart = lList2.indx + 1; if (adjInAtari) /* he wins */ { result = FALSE; goto one; } if ((lList2.indx > 2) && adj2Libs) /* he wins */ { result = FALSE; goto one; } for (k = 1; k <= maxSPoint; k++) libList[k] = -1; if (utilPlayLevel > 4) /* account for diagonal moves */ { listDiags(gx, gy, &dList); j = 0; k = lList2.indx; while ((j < dList.indx) && (k < maxSPoint)) { j = j + 1; k = k + 1; libList[k] = 100; lList2.p[k].px = dList.p[j].px; lList2.p[k].py = dList.p[j].py; } lList2.indx = k; } if (lList2.indx > 1) /* sort by increasing lib count */ { for (k = 1; k <= lList2.indx; k++) if (libList[k] != 100) /* diags go last */ { mark3 = playMark; tryPlay(lList2.p[k].px, lList2.p[k].py, me); libList[k] = gList[gMap[groupIDs[gx][gy]]].libC; undoTo(mark3); } for (k = 1; k <= lList2.indx - 1; k++) for (j = k + 1; j <= lList2.indx; j++) if (libList[k] > libList[j]) { tl = libList[k]; libList[k] = libList[j]; libList[j] = tl; tp = lList2.p[k]; lList2.p[k] = lList2.p[j]; lList2.p[j] = tp; } else if ((libList[k] == libList[j]) && (libList[k] == 1)) if (mtNbrs(lList2.p[k].px, lList2.p[k].py) < mtNbrs(lList2.p[j].px, lList2.p[j].py)) { tl = libList[k]; libList[k] = libList[j]; libList[j] = tl; tp = lList2.p[k]; lList2.p[k] = lList2.p[j]; lList2.p[j] = tp; } } for (j = 1; j <= lList2.indx; j++) { if (killTree(lList2.p[j].px, lList2.p[j].py, gx, gy, &esc, tkMark)) goto two; /* this kills him */ if (esc && (j >= dStart)) { result = FALSE; goto one; /* don't bother with more diags if escapes */ } } result = FALSE; /* none of my responses kills him */ goto one; } two: undoTo(mark2); } result = TRUE; /* none of his responses saves him */ } one: undoTo(curMark); /* sClearChar(sChar, rXor); */ depth = depth - 1; return result; } /* killTree */ short tKillTree(tx, ty, gx, gy) short tx, ty, gx, gy; { /* tKillTree */ short tkMark, escape; tryCount = 0; tkMark = playMark; return killTree(tx, ty, gx, gy, &escape, tkMark); } /* tKillTree */ short killable(gx, gy, killx, killy) short gx, gy, *killx, *killy; { /* killable */ #ifdef DEBUG printf( "killable\n" ); showTrees = TRUE; #endif dbStop = TRUE; him = bord[gx][gy]; /* find out who I am */ me = -him; /* if (me == 1) sChar = '>'; else sChar = '|'; */ /* write(sChar); */ depth = 1; topMark = playMark; sSpanGroup(gx, gy, &lList); /* find his liberties */ if (lList.indx == 1) { *killx = lList.p[1].px; *killy = lList.p[1].py; return TRUE; } else if (lList.indx > treeLibLim) return FALSE; else if (adjInAtari) return FALSE; else if ((lList.indx > 2) && adj2Libs) return FALSE; else { for (i = 1; i <= maxSPoint; i++) libList[i] = -1; if (utilPlayLevel > 4) /* account for diagonal moves */ { listDiags(gx, gy, &dList); j = 0; i = lList.indx; while ((j < dList.indx) && (i < maxSPoint)) { j = j + 1; i = i + 1; libList[i] = 100; lList.p[i].px = dList.p[j].px; lList.p[i].py = dList.p[j].py; } lList.indx = i; } if (lList.indx > 1) /* sort by increasing lib count */ { for (i = 1; i <= lList.indx; i++) if (libList[i] != 100) /* diags go last */ { mark2 = playMark; tryPlay(lList.p[i].px, lList.p[i].py, me); libList[i] = gList[gMap[groupIDs[gx][gy]]].libC; undoTo(mark2); } for (i = 1; i <= lList.indx - 1; i++) for (j = i + 1; j <= lList.indx; j++) if (libList[i] > libList[j]) { tl = libList[i]; libList[i] = libList[j]; libList[j] = tl; tp = lList.p[i]; lList.p[i] = lList.p[j]; lList.p[j] = tp; } else if ((libList[i] == libList[j]) && (libList[i] == 1)) if (mtNbrs(lList.p[i].px, lList.p[i].py) < mtNbrs(lList.p[j].px, lList.p[j].py)) { tl = libList[i]; libList[i] = libList[j]; libList[j] = tl; tp = lList.p[i]; lList.p[i] = lList.p[j]; lList.p[j] = tp; } } for (i = 1; i <= lList.indx; i++) { if (legal[lList.p[i].px][lList.p[i].py]) { *killx = lList.p[i].px; *killy = lList.p[i].py; if (tKillTree(*killx, *killy, gx, gy)) { /* sClearChar(sChar, rXor); */ return TRUE; } } } return FALSE; } /* sClearChar(sChar, rXor); */ } /* killable */ |