[Computer-go] Cogito--another minimal Go engine

robertfinkng555 at o2.co.uk robertfinkng555 at o2.co.uk
Fri Mar 27 15:57:51 PDT 2015

I suspect some people may not be curious enough to follow the link, but 
may be intrigued if they saw the code...

#define S W*W
#define A B.s[1]-B.s[2]-K
#define F(x,l)for(x=0; x<l; x++)
#define P F(x,4)
#define Q(n)P z(~(s=n[x]))
#define R while
#define r return
#define z if
#define C int
#define L struct
L N{ C i,g; float w; L N*h,*s; } O[G*W];
L{ L{ C h[4],p,l; } M[S]; C b[S],c,u[S],i[S],I,p,J,s[3]; } B,F; g; Z; m; 
i; e[S][4]; a[S][4]; E; J=2;
char T[9]; long long t,Q[4096],_,v=k,q;
#define M B.M
#define b B.b
#define c B.c
#define u B.u
#define I B.I
p(i){ r~M[i].p?p(M[i].p):i; } X(i){ C x,s; B.s[b[i]]--; 
Q(e[i])b[s]&&M[p(s)].l++; P M[i].h[x]=M[i].p=-1;
b[u[B.i[i]=I++]=i]=0; } y(i){ C x,s; z(b[i]){ Q(M[i].h)y(s); X(i); } }
V(i){ C x,s,l,v,h,w,f[m=S],*d=f,*j=f+4,g[4],o; z(i-S||0*++B.p){ 
z(i==B.J|b[i])r 1; m=I; P g[x]=-1;
l=0; Q(e[i])z(b[s]||0*++l)z(v=p(s),b[s]^c)--M[*d=v].l||d++; else{ o=0; 
l+=M[g[x]=v].l*!o-1; } z(!l&d==f){ Q(e[i])b[s]^c^3||M[p(s)].l++; r 1; } 
M[i].l=l; B.s[b[i]=c]++;
u[B.i[u[--I]]=B.i[i]]=u[I]; Q(e[i])b[s]-c||(*j++=p(s),*j++=x); 
R(d-->f)y(*d); B.p=0; } B.J=m-I?-1:u[I-1]; c^=3; r 0; } Y(i,o){ C 
x,s,l=0,h[4]={ 0} ; Q(e[u[i]])l|=b[s]^o;
Q(a[u[i]])h[b[s]^3]++; else*h=1; r!l&h[o]+*h<2; } H(){ C 
x,s;t=18782*Q[v=v+1&4095]+_; _=t>>32; q=t+_;
z(q<_)q++,_++; s=x=abs(Q[v]=-2-q)%I; do{ z(!Y(s,c)&&!V(u[s]))r 0; 
s++,s%=I; } R(s-x); V(S); }
D(L N*n){ n->h=n->g=n->w=0; } U(L N*n){ L N*h,*v=0; float l,j; C 
f=0,x,w=0; z(n->g<W){ x=c;
R(B.p<2&abs(A)<30&f++<2*S)H(); F(m,I)w+=Y(m,1)-Y(m,2); g=x^(A+w)>0; Z=1; 
} else{
z(!n->h)F(f,I)Y(f,c)||(D(h=O+E++),h->i=u[f],h->s=n->h,n->h=h); l=-1; 
for(h=n->h; h;
V(v->i)?v->g=-1,Z=0:U(v); } n->w+=g&Z; n->g+=Z; g^=1; } main(){ C*x,*d; 
I=0; F(i,S){
X(i); B.s[i%3]=B.p=0; x=e[i]; d=a[i]; *d=(*x=i-W)-1; d[2]=(x[1]=i-1)+W; 
d[c=1]=(x[2]=i+1)-W; d[3]=1+(x[3]=i+W);
i<W&&(*x=*d=d[1]=-1); i%W||(x[1]=*d=d[2]=B.J=-1); 
i%W^W-1||(x[2]=d[1]=d[3]=-1); i<S-W||(x[3]=d[2]=d[3]=-1);
} R(B.p<2){ z(c&J){ L N*h,*l; i=0; F=B; E=1; D(O); R(i++<G)U(O),B=F; 
for(l=h=O->h; h;
h=h->s)z(h->g>l->g&&~h->i)l=h; i=l->i; printx("%c%i\n",i%W+97,W-i/W); 
V(i); }
else R(gets(T)?*T<64?J=*T,0:V(*T-80?*T-97+S-W*atoi(T+1):S):(exit(0),0));
F(m,S)printx("%c%c",b[m][".#o"]," \n"[m%W+1==W]); } }

On 27/03/2015 21:55, Zach Wegner wrote:
> With all the talk about Michi (which is very nice btw, Petr!), I
> figured now would be a good time to do a little more work on my old
> super-minimalist obfuscated Go engine, and finally show it off to the
> world. Cogito was mostly written in 2008/2009, I only did some
> cleaning up/bug fixing/shrinking.
> At current count, using the IOCCC rules, there are only 1891
> characters of C source code, or 2277 bytes if counted normally. It
> only uses basic UCT with no eye-filling. I might try experimenting
> with adding more heuristics, perhaps RAVE, as long as there isn't too
> much code required. The code is certainly twisted and unintelligible,
> but I might be convinced to write up some explanation of the code
> structure and what all the one-character variable names mean...
> Cogito has a simple terminal interface, but currently no way to play
> through gtp. I once had a shell script that would interface it with
> CGOS (where it played a bit in ~2009, with a rating of something like
> 1300), but it's been lost. I might whip up a little adapter script in
> Python if there's interest. For just playing a terminal game, there's
> some instructions in the readme.
> Without further ado, the repository: https://github.com/zwegner/cogito
> _______________________________________________
> Computer-go mailing list
> Computer-go at computer-go.org
> http://computer-go.org/mailman/listinfo/computer-go
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5856 / Virus Database: 4315/9395 - Release Date: 03/27/15

More information about the Computer-go mailing list