C souce code for the game of Go
Submitted By:
WEBMASTER
Rating:





(
Rate It)
/* alf.c ... artificial lifeform fabrication */
#include <dos.h>
#include <conio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <alloc.h>
#include <graphics.h>
#define EXTCDECL extern
#include "goh.c"
void deadones()
{
struct root *rootp;
struct link *neighbp, *rtlp;
unsigned jndex, kndex, success;
rtlp = rootlist->nextl;
if (rtlp) {
do {
rootp = (struct root *) rtlp->loc;
jndex = rootp->ridx;
if (rootp->clr != colour) {
if (rootp->nlib <= 4) {
success = 0;
success = akill(jndex);
if (success) {
neighbp = rootp->neighbs->nextl;
do {
kndex = neighbp->loc;
ownctrl[kndex] = 1;
neighbp = neighbp->nextl;
} while (neighbp);
}
}
}
rtlp = locate(rootp, rootlist);
rtlp = rtlp->nextl;
} while (rtlp && !attn);
}
}
void suispots()
{
struct root *rootp;
struct link *libp, *rtlp;
unsigned jndex, valid, success, killer;
rtlp = rootlist->nextl;
if (rtlp) {
doit(0);
/*rtlp = rootlist->nextl;*/
do {
rootp = rtlp->loc;
if (rootp->clr != colour) {
libp = rootp->liberties->nextl;
do {
jndex = libp->loc;
ownctrl[jndex] = 1;
libp = libp->nextl;
} while (libp);
libp = rootp->spaces->nextl;
if (libp) {
do {
jndex = libp->loc;
ownctrl[jndex] = 1;
libp = libp->nextl;
} while (libp);
}
}
rtlp = rtlp->nextl;
} while (rtlp);
/* include corners */
/*
jndex = fxy(1, 1);
if (!dir[jndex]) {
libxp = xtlocate(jndex, libxp);
if (!xtmember(jndex, libxp)) {
libxp = xtinsert(jndex, libxp);
poke(libxp, LEVEL, 1);
}
}
jndex = fxy(1, nsize);
if (!dir[jndex]) {
libxp = xtlocate(jndex, libxp);
if (!xtmember(jndex, libxp)) {
libxp = xtinsert(jndex, libxp);
poke(libxp, LEVEL, 1);
}
}
jndex = fxy(nsize, 1);
if (!dir[jndex]) {
libxp = xtlocate(jndex, libxp);
if (!xtmember(jndex, libxp)) {
libxp = xtinsert(jndex, libxp);
poke(libxp, LEVEL, 1);
}
}
jndex = fxy(nsize, nsize);
if (!dir[jndex]) {
libxp = xtlocate(jndex, libxp);
if (!xtmember(jndex, libxp)) {
libxp = xtinsert(jndex, libxp);
poke(libxp, LEVEL, 1);
}
}
*/
for(jndex=1; jndex<=nsize2; ++jndex) {
if (ownctrl[jndex]) {
valid = doit(jndex);
if (valid) {
success = 0;
if (dir[jndex]->nlib <= 4) {
success = akill(jndex);
}
ownctrl[jndex] = success;
jndex = undoit();
}
}
if (attn) break;
}
undoit();
deadones();
}
}
void evaliz()
{
unsigned indexes, indexp, index;
unsigned i, feasible, jndex, kndex, diachk, diamax, edgy;
int stotogo;
struct root *rootp;
unsigned *point;
unsigned diagvec[NDIAGS];
for (i=1; i<=nsize2; ++i) ownctrl[i] = 0;
for (i=1; i<=nsize2; ++i) owniz[i] = 0xff;
suispots();
/* pass 1 evaluate eye potential of points under own control */
for (kndex=1; kndex<=nsize2; ++kndex) {
if (ownctrl[kndex]) {
edgy = edge(kndex);
stotogo = 8;
if (!edgy) --stotogo;
feasible = 1;
point = NEWS(kndex);
for (i=0; i<NLIBS; ++i) {
jndex = *point;
if (jndex) {
rootp = dir[jndex];
if (ownctrl[jndex]) --stotogo;
if (rootp) {
if (rootp->clr == colour) --stotogo;
else {
if (!dir[kndex]) feasible = 0;
}
}
} else --stotogo;
++point;
if (!feasible) break;
}
if (feasible) {
diamax = 1;
if (edgy) --diamax;
diachk = 0;
diags(kndex, diagvec);
point = diagvec;
for (i=0; i<NDIAGS; ++i) {
jndex = *point;
if (jndex) {
rootp = dir[jndex];
if (ownctrl[jndex]) --stotogo;
if (rootp) {
if (rootp->clr == colour) --stotogo;
else {
if (!ownctrl[jndex]) {
++diachk;
if (diachk > diamax) feasible = 0;
}
}
}
} else --stotogo;
++point;
if (!feasible) break;
}
}
if (feasible) {
if (stotogo < 0) stotogo = 0;
owniz[kndex] = stotogo;
}
}
}
/* pass 2 refine evaluation by weeding out special cases */
indexes = xtinsert(0, 0);
indexp = indexes;
for (kndex=1; kndex<=nsize2; ++kndex) {
if (owniz[kndex] != 255) {
feasible = 1;
point = NEWS(kndex);
for (i=0; i<NLIBS; ++i) {
jndex = *point;
if (jndex) {
if (owniz[jndex] == 255) {
rootp = dir[jndex];
if (rootp) {
if (rootp->clr != colour) {
if (dir[kndex]) {
feasible = 0;
}
}
}
else {
if (ownctrl[jndex]) {
if (!dir[kndex]) {
++owniz[kndex];
}
}
}
}
}
++point;
if (!feasible) break;
}
if (!feasible) {
indexp = xtlocate(kndex, indexp);
indexp = xtinsert(kndex, indexp);
}
}
}
indexp = peek(indexes, NEXTL);
if (indexp) {
do {
index = peek(indexp, LOC);
owniz[index] = 255;
indexp = peek(indexp, NEXTL);
} while (indexp);
}
xtfreelist(indexes);
}