Moderator: Andres Valverde
Uri Blass wrote:There is a mistake here.
TSCP does not use bitboards.
/*
* BOARD.C
* Tom Kerrigan's Simple Chess Program (TSCP)
*
* Copyright 1997 Tom Kerrigan
*/
/*
* Simple Bitboard move generator by Michael Sherwin
*/
case BISHOP:
first = first_one(ray_plus_7[fs] & occupied);
moves = ray_plus_7[fs] & below[first];
captures = set_mask[first];
first = first_one(ray_plus_9[fs] & occupied);
moves |= ray_plus_9[fs] & below[first];
captures |= set_mask[first];
first = last_one(ray_minus_7[fs] & occupied);
Jaime Benito de Valle wrote:My engine Ayito has the same features as well. Below you can find an automated perft test that I run every now and then just in case. If you can get these figures, chances of having a bug in move generation and/or make and unmake are indeed low.
do{
if (!SinglePeftTest(c++, 4, 1066400,"r1b4r/p2p1ppp/1ppbn2k/4P2P/1PB5/2P2PP1/P7/RNKQ3R w - -")) break;
if (!SinglePeftTest(c++, 4, 1233636,"1q5k/8/1p2n3/p1p1rb2/2Pp3n/PP1P2P1/3B1R2/2R2QK1 b - -")) break;
if (!SinglePeftTest(c++, 4, 1240989,"r3kb1r/pp1bpppp/8/5n2/4n3/4B3/PPP2PPP/RN1K1B1R w kq -")) break;
if (!SinglePeftTest(c++, 5, 1745545,"8/PPP4k/8/8/8/8/4Kppp/8 w - - ")) break;
if (!SinglePeftTest(c++, 4, 1797968,"r3r2k/pp2qp1p/5pb1/8/4P2Q/3PBP2/PP4P1/R2K3R b - -")) break;
if (!SinglePeftTest(c++, 4, 4085603, "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -")) break;
if (!SinglePeftTest(c++, 4, 4466732, "r3k2r/1P1p2P1/1q6/4P3/4p3/6Q1/1p1P2p1/R3K2R w KQkq - 0 1 ")) break;
if (!SinglePeftTest(c++, 6, 11030083,"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -")) break;
if (!SinglePeftTest(c++, 5, 11677860, "R6R/8/1Q4Q1/4Q3/2Q4Q/Q4Q2/pp1Q4/kBNN1KB1 w - - ")) break;
if (!SinglePeftTest(c++, 5, 29014483, "4r1k1/p1p3pp/1bp3r1/5p2/1P6/2PQ1P1b/R2P1P1P/2B2R1K w - -")) break;
if (!SinglePeftTest(c++, 6, 55577643, "3rr1n1/2qb2p1/2p1pk1p/1p3P2/3P1R1Q/1pP5/P5PP/4R1K1 b - -")) break;
if (!SinglePeftTest(c++, 5, 126222830, "1r4r1/1ppn2pk/p1npq2p/4Pp2/P4p1Q/2PBB2R/1PP1KP1P/6R1 w - f6")) break;
end=1;
}while (false);
Regards,
Abhay Kumar wrote:Is it possible that I can write a program without using perft?
And is there any other method so that I can setup my board structure without using 0x88 and bitboards?
Pradu wrote:Uri Blass wrote:
There is a mistake here.
TSCP does not use bitboards.
I do not recommend tscp but for different reasons.
It has a lot of global variables and I think that it is not the best way for starting a chess program.
Uri
I do agree TSCP isn't that great but what else is there for the new programmer?
Dann Corbit wrote:Look at Scorpio to understand basic chess designs. The source is about 188K, which is 3x bigger than TSCP, but I don't think that is a serious handicap.
Abhay Kumar wrote:Dann Corbit wrote:Look at Scorpio to understand basic chess designs. The source is about 188K, which is 3x bigger than TSCP, but I don't think that is a serious handicap.
Where can I get the 'source code + engine' for the programs you recommened?
And what interface should I use for the testing purposes?
#define F(I,S,N) for(I=S;I<N;I++)
#define W(A) while(A)
#define C(A) if(A)continue;
#define B(A) if(A)break;
int V=112,M=136,I=4000,C=799,X,Y,i,Q,N,
w[]={0,1,1,3,-1,3,5,9},
o[]={6,3,5,7,4,5,3,6},
g[]={0,3,-1,21,7,11,16,7},
d[]={16,15,17,0,-16,-15,-17,0,1,-1,16,-16,15,-15,17,-17,0,1,-1,16,-16,0,
14,-14,18,-18,31,-31,33,-33,0},
b[128];
char n[]=".?+pkltd?*?PKLTD";
P()
{F(i,0,121)
printf(" %c",i&8&&(i+=7)?10:n[b[i]&15]);
}
D(k,q,l,e,x,n)
int k,q,l,e,x,n;
{
int i,j,t,p,u,r,y,m=n>1|q>e?q:e,v,h,z;
N++;
F(i,0,120)
{i=i+8&~8;
u=b[i];C(!(u&k))
j=g[p=u&7];
W(r=d[++j])
{y=i;
do
{y+=r;B(y&M)
t=b[y];B(t&k)
B(j<7&&!(r&7)!=!t)
v=99*w[t&7];
if(v<0)m=I;
if(m>=l)return m;
if(h=n-(y!=x))
{if(p<6)v+=b[i+8]-b[y+8];
if(p==4)v+=9*(e>C?!((x^y)&68):-3);
b[i]=0;b[y]=u;
if(p<3)
{v-=9*(((i-2)&M||b[i-2]!=u)+((i+2)&M||b[i+2]!=u)-1);
if(y+r+1&128){b[y]|=7;v+=C;}
}
z=-e-v;
v=-D(24-k,-l,-m,z,y,h);
if(v>1500)v-=50;
if(x==9){if(v!=-I&i==X&y==Y){Q=z;return l;}v=m;}
b[i]=u;b[y]=t;
if(v>m){m=v;if(x&8){X=i;Y=y;}}
}
t+=p<5;if(j<7&&6*k+(y&V)==128)t--;
}W(!t);
}
}
return m+I?m:-D(24-k,-I,I,0,x,1)/2;
}
main()
{
int i,j,k=8,*p,c[9],d;
F(i,0,8)
{b[i]=(b[i+V]=o[i]+8)+8;b[i+16]=18;b[i+96]=9;
F(j,0,8)b[16*j+i+8]=(i-4)*(i-4)+(j-3.5)*(j-3.5);
}
W(1)
{P();p=c;W((*p++=getchar())>10);
if(*c-10){X=c[0]-16*c[1]+C;Y=c[2]-16*c[3]+C;}else
{d=6;N=0;W(N<4e6)D(k,-I,I,Q,8,d++);}
if(D(k,-I,I,Q,9,2)==I)k^=24;
}
}
#include "stdio.h"
#define F(I,S,N) for(I=S;I<N;I++)
#define W(A) while(A)
#define C(A) if(A)continue;
#define B(A) if(A)break;
int V=112,M=136,I=4000,C=799,X,Y,i,Q,N,
w[]={0,1,1,3,-1,3,5,9},
o[]={6,3,5,7,4,5,3,6},
g[]={0,3,-1,21,7,11,16,7},
d[]={16,15,17,0,-16,-15,-17,0,1,-1,16,-16,15,-15,17,-17,0,1,-1,16,-16,0,
14,-14,18,-18,31,-31,33,-33,0},
b[128];
char n[]=".?+pkltd?*?PKLTD";
void P()
{F(i,0,121)
printf(" %c",i&8&&(i+=7)?10:n[b[i]&15]);
}
D(int k,int q,int l,int e,int x,int n)
//int k,q,l,e,x,n;
{
int i,j,t,p,u,r,y,m=n>1|q>e?q:e,v,h,z;
N++;
F(i,0,120)
{i=i+8&~8;
u=b[i];C(!(u&k))
j=g[p=u&7];
W(r=d[++j])
{y=i;
do
{y+=r;B(y&M)
t=b[y];B(t&k)
B(j<7&&!(r&7)!=!t)
v=99*w[t&7];
if(v<0)m=I;
if(m>=l)return m;
if(h=n-(y!=x))
{if(p<6)v+=b[i+8]-b[y+8];
if(p==4)v+=9*(e>C?!((x^y)&68):-3);
b[i]=0;b[y]=u;
if(p<3)
{v-=9*(((i-2)&M||b[i-2]!=u)+((i+2)&M||b[i+2]!=u)-1);
if(y+r+1&128){b[y]|=7;v+=C;}
}
z=-e-v;
v=-D(24-k,-l,-m,z,y,h);
if(v>1500)v-=50;
if(x==9){if(v!=-I&i==X&y==Y){Q=z;return l;}v=m;}
b[i]=u;b[y]=t;
if(v>m){m=v;if(x&8){X=i;Y=y;}}
}
t+=p<5;if(j<7&&6*k+(y&V)==128)t--;
}W(!t);
}
}
return m+I?m:-D(24-k,-I,I,0,x,1)/2;
}
int main()
{
int i,j,k=8,*p,c[9],d;
F(i,0,8)
{b[i]=(b[i+V]=o[i]+8)+8;b[i+16]=18;b[i+96]=9;
F(j,0,8)b[16*j+i+8]=(i-4)*(i-4)+(j-3.5)*(j-3.5);
}
W(1)
{P();p=c;W((*p++=getchar())>10);
if(*c-10){X=c[0]-16*c[1]+C;Y=c[2]-16*c[3]+C;}else
{d=6;N=0;W(N<4e6)D(k,-I,I,Q,8,d++);}
if(D(k,-I,I,Q,9,2)==I)k^=24;
}
return 0;
}
Uri Blass wrote:Note that the following order is wrong and you first need to define variables and later to use them(not the opposite)
D(k,q,l,e,x,n)
int k,q,l,e,x,n;
after some corrections I still get some warning but I get some code
that let me to play game against myself or play against it when I need to press enter to tell it to move but it does not let me to play enpassent capture or castle so it does not support playing chess and by definition cannot beat most players because it is not going to accept castling moves by them.
Abhay Kumar wrote:Is providing the features of enpassent and castling that much difficult? I guess that's why it's not supported in the original code.
Will somebody tell me?
Uri Blass wrote:after some corrections I still get some warning but I get some code
that let me to play game against myself or play against it when I need to press enter to tell it to move but it does not let me to play enpassent capture or castle so it does not support playing chess and by definition cannot beat most players because it is not going to accept castling moves by them.
Uri Blass wrote:The only reason that it may beat most of the humans is that most of the humans are not chess players.
#define F(I,S,N) for(I=S;I<N;I++)
#define W(A) while(A)
#define C(A) if(A)continue;
#define B(A) if(A)break;
int V=112,M=136,I=4e3,C=799,X,Y,i,Q,N,K=128,
w[]={0,1,1,3,-1,3,5,9},
o[]={6,3,5,7,4,5,3,6},
g[]={0,3,-1,21,7,11,16,7},
d[]={16,15,17,0,-16,-15,-17,0,1,-1,16,-16,15,-15,17,-17,0,1,-1,16,-16,0,
14,-14,18,-18,31,-31,33,-33,0},
b[129];
char n[]=".?+nkbrq?*?NKBRQ";
P()
{F(i,0,121)
printf(" %c",i&8&&(i+=7)?10:n[b[i]&15]);
}
D(k,q,l,e,E,x,n)
int k,q,l,e,E,x,n;
{
int i,j,t,p,u,r,y,m=n>1|q>e?q:e,v,h,z,F,G,H;
N++;
F(i,0,120)
{i=i+8&~8;
u=b[i];C(!(u&k))
j=g[p=u&7];
W(r=d[++j])
{y=i;F=G=128;
do
{H=y+=r;B(y&M)
if(y==E)H=y^16;
t=b[H];B(t&k)
B(p<3&&!(r&7)!=!t)
v=99*w[t&7];
if(v<0||E-128&&b[E]&&y-E<2&E-y<2)m=I;
if(m>=l)return m;
if(h=n-(y!=x))
{if(p<6)v+=b[i+8]-b[y+8];
if(p==4)v+=9*(e>C?!((x^y)&68):-3);
b[G]=b[H]=b[i]=0;b[y]=u&31;
if(!(G&M)){b[F]=k+6;v+=55;}
if(p<3)
{v-=10*(((i-2)&M||b[i-2]!=u)+((i+2)&M||b[i+2]!=u)-1);
if(y+r+1&128){b[y]|=7;v+=C;}
}
v=-D(24-k,-l,-m,z=-e-v,F,y,h);
if(v>1500)v-=50;
if(x==9){if(v!=-I&i==X&y==Y){Q=z;K=F;return l;}v=m;}
b[G]=k+38;b[F]=b[y]=0;b[i]=u;b[H]=t;
if(v>m){m=v;if(x&8){X=i;Y=y;}}
}
t+=p<5;
if(j<7&&6*k+(y&V)==128
||(u&~24)==36&&!(j&~9)&&
G&M&&b[G=(i&V)+7-(r>>1&7)]&32
&&!(b[G^1]|b[G^2])
){F=y;t--;}
}W(!t);
}
}
return m+I?m:-D(24-k,-I,I,0,128,x,1)/2;
}
main()
{
int i,j,k=8,*p,c[9],d;
F(i,0,8)
{b[i]=(b[i+V]=o[i]+40)+8;b[i+16]=18;b[i+96]=9;
F(j,0,8)b[16*j+i+8]=(i-4)*(i-4)+(j-3.5)*(j-3.5);
}
W(1)
{P();p=c;W((*p++=getchar())>10);
if(*c-10){X=c[0]-16*c[1]+C;Y=c[2]-16*c[3]+C;}else
{d=6;N=0;W(N<4e6)D(k,-I,I,Q,K,8,d++);
printf("%d ply, %d searched\n",d-2,N);
}
if(D(k,-I,I,Q,K,9,2)==I)k^=24;
}
}
#include <stdio.h>
static int V = 112,
M = 136,
I = 4e3,
C = 799,
X,
Y,
i,
Q,
N,
K = 128,
w[] = {0, 1, 1, 3, -1, 3, 5, 9},
o[] = {6, 3, 5, 7, 4, 5, 3, 6},
g[] = {0, 3, -1, 21, 7, 11, 16, 7},
d[] = { 16, 15, 17, 0, -16, -15, -17, 0, 1, -1, 16, -16, 15, -15, 17,
-17, 0, 1, -1, 16, -16, 0, 14, -14, 18, -18, 31, -31, 33, -33, 0},
b[129];
static char n[] = ".?+nkbrq?*?NKBRQ";
void P(void)
{
for (i = 0; i < 121; i++)
printf(" %c", i & 8 && (i += 7) ? 10 : n[b[i] & 15]);
}
int D(int k, int q, int l, int e, int E, int x, int n)
{
int i,
j,
t,
p,
u,
r,
y,
m = n > 1 | q > e ? q : e,
v,
h,
z,
F,
G,
H;
N++;
for (i = 0; i < 120; i++) {
i = i + 8 & ~8;
u = b[i];
if (!(u & k))
continue;
j = g[p = u & 7];
while (r = d[++j]) {
y = i;
F = G = 128;
do {
H = y += r;
if (y & M)
break;
if (y == E)
H = y ^ 16;
t = b[H];
if (t & k)
break;
if (p < 3 && !(r & 7) != !t)
break;
v = 99 * w[t & 7];
if (v < 0 || E - 128 && b[E] && y - E < 2 & E - y < 2)
m = I;
if (m >= l)
return m;
if (h = n - (y != x)) {
if (p < 6)
v += b[i + 8] - b[y + 8];
if (p == 4)
v += 9 * (e > C ? !((x ^ y) & 68) : -3);
b[G] = b[H] = b[i] = 0;
b[y] = u & 31;
if (!(G & M)) {
b[F] = k + 6;
v += 55;
}
if (p < 3) {
v -= 10 * (((i - 2) & M || b[i - 2] != u) + ((i + 2) & M || b[i + 2] != u) - 1);
if (y + r + 1 & 128) {
b[y] |= 7;
v += C;
}
}
v = -D(24 - k, -l, -m, z = -e - v, F, y, h);
if (v > 1500)
v -= 50;
if (x == 9) {
if (v != -I & i == X & y == Y) {
Q = z;
K = F;
return l;
}
v = m;
}
b[G] = k + 38;
b[F] = b[y] = 0;
b[i] = u;
b[H] = t;
if (v > m) {
m = v;
if (x & 8) {
X = i;
Y = y;
}
}
}
t += p < 5;
if (j < 7 && 6 * k + (y & V) == 128
|| (u & ~24) == 36 && !(j & ~9) &&
G & M && b[G = (i & V) + 7 - (r >> 1 & 7)] & 32
&& !(b[G ^ 1] | b[G ^ 2])
) {
F = y;
t--;
}
} while (!t);
}
}
return m + I ? m : -D(24 - k, -I, I, 0, 128, x, 1) / 2;
}
int main(void) {
int i,
j,
k = 8,
*p,
c[9],
d;
for (i = 0; i < 8; i++) {
b[i] = (b[i + V] = o[i] + 40) + 8;
b[i + 16] = 18;
b[i + 96] = 9;
for (j = 0; j < 8; j++)
b[16 * j + i + 8] = (i - 4) * (i - 4) + (j - 3.5) * (j - 3.5);
}
for (;;) {
P();
p = c;
while ((*p++ = getchar()) > 10);
if (*c - 10) {
X = c[0] - 16 * c[1] + C;
Y = c[2] - 16 * c[3] + C;
} else {
d = 6;
N = 0;
while (N < 4e6)
D(k, -I, I, Q, K, 8, d++);
printf("%d ply, %d searched\n", d - 2, N);
}
if (D(k, -I, I, Q, K, 9, 2) == I)
k ^= 24;
}
return 0;
}
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 30 guests