Shop OBEX P1 Docs P2 Docs Learn Events
Toledo: Chess & CP/M — Parallax Forums

Toledo: Chess & CP/M

RaymanRayman Posts: 14,665
edited 2013-05-18 13:24 in Propeller 1
I played around with this stuff with Catalina, but don't remember if I ever got it to work...
http://www.nanochess.org/index.html

Nanochess doesn't compile, but Toledo Chess 1 does (scroll down and the code looks like something:) ):
[SIZE=2]#define    F getchar())
 #define H(z)*n++=z;
       #include        <setjmp.h>
    #define v main(0,0,0
           #define Z while(
                                                 #define _ if(
#define o(d)(S=63,u[l]=0,l[d]=6^e,q=1e4>v,0),l[d]=0,u[l]=e^6,S=b,q)
#define I(H,n) { _ r=l[x=H],!r|(r^e)<-1){ _ j=u[l],-7==r|6==r\
){ n; e=~e; return 1e5-443*f; } u[l]=0,t=j+1,i=j-1; _!i&89<\
x)i=j,t=6; _-1==t&30>x)t=j,i=-7; Z++i<t){ d =0; S&= 63; \
a=((j^e)!=1?6!=(j^e)?O[32+x/10]-O[u/10+32]-q:(S|=6!=j?8\
:1,2==u-x)*9+9*(x-u==2):(d=1==j?x-u:u-x)/8+!(!((x-u)%\
10)|r)*99+(j==1?90<x:29>x)*(9*O[28+i]-288))+O[r+28\
]*9-288+O[x%10+33]-f-O[33+u%10]; x[l]=i; S|=(21=\
=u|21==x)*2+(u==28|28==x)*4+(91==u|x==91)*16+32\
*(u==98|x==98)+(20==d)*64*x; a-=k>f?main(a,f+1\
,M,k):0; _ i==c&u==h&!f&N&a>-1e4&x==y)longjm\
p(z,1); S=b; _!N|f&&(a>M||!f&a==M&&1&rand()\
)){ _!f){ _ k){ c=i; h=u; y=x; } } else _ \
L-a<N){ n; e=~e; u[l]=j; x[l]=r; return\
 a; } M=a; } } x[l]=r; u[l]=j; n; } }
typedef int G; char J [ 78 ], O [ ]
=   "HRQAMS#-smaqrh[UTZYTU[|TBA("
"$#(ABT|ba`gg`ab8>GK[_`fFDZXEYR"         "L\t####"
"##B#A#@#G#F#E#D#K\t\3Zlv#tjm"         "\3J#tjm\3Pwb"
"ofnbwf\3Joofdbo\3)&`&`.&`&`"         "#+&g*\t"; G y,
c,h,e,S,*s,l[149]; jmp_buf z         ; G main(G L,G f,
G N,G k){ G u=99,p,q,r,j,i,x         ,t,a,b=S,d,M=-1e9
; char *n; if( *l){ e=~e; Z       u >21){ q= l[--u]^e;
_!-- q){ _!l[p=e?u-10:u+10]){   I(p,)_ e?u>80   & !l[p
-=10]:u<39&!l[p+=10])I(p,)} _ l[p=e?u-11:9+u]   )I(p,)
else _ u-1==S>>6){ l[u-1]=0; I(p,l[u-1]=-2^e);  } _ l[
p=e?u-9:11+u])I(p,)else _ S>>6==1+u){ l[1+u]=0; I(p,l
[1+u]=e^-2); } } _!--q){ n=O+41; Z++n<50+O)I(u+80-*n,
)} _ 0<q&4>q){  n=q==2?53+O:O+49; Z++n<O+(q!=1)*4+54
){ p=u; do I(p-=*n-80,)Z!p[l]); } } _ 4==q){ n=49+O
 ; Z++n<O+58)I(u-*n+80,)_ e&!(S&24)|!e&!(S&3)   &&
 !l[u-2]&!l[u-1]&!l[u-3]&&o(u)&&o(u-1)){ l[u-1]=4
  ^e; l[u-4]=0; I(u-2,l[u-1]=0; l[u-4]=e^4); } _
  e&!(S&40)|!e&!(S&5)  &&!l[u+1]&!l[2+u]&&o(u)&&
   o(1+u)){ l[u+1]=e^4; l[3+u]=0;   I(u+2,l[1+u
   ]=0; l[u+3]=4^e); } } } e=~e;   return M; }
    Z h<130){l[h]=-(21>h|98<h|2       >(h+1 )%
    10); O[h++]^=3; } n=O +14;       s=20+l; Z
     ++s<29+l){ 10[s]=1; 70[s]=~    ( * s = *
      n++ -+84); 60 [ s] =-2; } Z  n=J){ puts
       (58+O); u=19; Z++u<100){ H(32)_!( u%10
       ))H(32)H(O[7+l[u]])_(9+u)%10>7){ H(58
        -u/10)H(32)_ u&1)puts(n=J); } } puts
         (O+58); _-1e4 >v , 1)){ e=~e; puts
          (O+(v,0)> 1e4?e?90:82:96)); break
           ; } _ 1<L&e) { d=v,2+L); printf
            (O+114,h%10+64,58-h/10,y%10+64
             ,58 -y/10,d); } else{ putchar
              (62+e); h= (95 & F-44; c=l[h
                +=(56-F *10]; y=(95&F-44; y
                   +=(56-F*10; Z 10!=(u=(95
                    &F)){ c=5; Z--c>1&&u!=c
                      [O]); c=e^c-7; } } _!
                         setjmp(z)){ v+1,1);
                               puts(   106+
                                O); }   } Z
                                 10!=
                                  F; }
[/SIZE]

It even works! It's too big for LMM, but works with CMM.

The CP/M code seems to compile if I comment out the "system" calls.
I'll have to try that tonight...

Comments

  • RaymanRayman Posts: 14,665
    edited 2013-04-24 18:07
    Can't seem to get the 8080 CP/M emulator working... Maybe because I had to comment out the "system" commands?

    Did find somebody who got it working on a microcontroller though:
    http://microcontrollers.2385.n7.nabble.com/Intel-8080-system-emulation-Running-CP-M-on-your-Ethernut-Board-td160903.html
  • jazzedjazzed Posts: 11,803
    edited 2013-04-24 18:56
    Rayman wrote: »
    Can't seem to get the 8080 CP/M emulator working... Maybe because I had to comment out the "system" commands?

    Did find somebody who got it working on a microcontroller though:
    http://microcontrollers.2385.n7.nabble.com/Intel-8080-system-emulation-Running-CP-M-on-your-Ethernut-Board-td160903.html

    Not sure about CP/M, but usually a system("text"); call means to run some O/S command.
  • RaymanRayman Posts: 14,665
    edited 2013-04-25 15:20
    For more of a challenge, I tried compiling GNU Chess today...

    First downloaded ver.5, but that didn't look very easy to compile, so I found ver.3 and tried it...

    I can actually get it to compile, but it doesn't run right...
    This one is only a few thousand lines of code though, so maybe one day, I could get it running...
  • RossHRossH Posts: 5,462
    edited 2013-05-14 06:28
    Rayman wrote: »
    I played around with this stuff with Catalina, but don't remember if I ever got it to work...
    http://www.nanochess.org/index.html

    Nanochess doesn't compile

    The Nanochess source code on this web page appears to contain a syntax error. Fix it, and Nanochess compiles and runs under Catalina.

    Below is the corrected code (correction shown in red):
    /**************************************************************************\
    | Toledo Nanochess (c) Copyright 2009 Oscar Toledo G. All rights reserved  |
    | 1257 non-blank characters. Evolution from my winning IOCCC 2005 entry.   |
    | o Use D2D4 algebraic style for movements.  biyubi@gmail.com  Nov/20/2009 |
    | o On promotion add a number for final piece (3=N, 4=B, 5=R, 6=Q)         |
    | o Press Enter alone for computer to play.                                |
    | o Full legal chess moves.                       http://www.nanochess.org |
    | o Remove these comments to get 1326 bytes source code (*NIX end-of-line) |
    \**************************************************************************/
    char*l="ustvrtsuqqqqqqqqyyyyyyyy}{|~z|{}"
    "   76Lsabcddcba .pknbrq  PKNBRQ ?A6J57IKJT576,+-48HLSU";
    #define F getchar()&z
    #define v X(0,0,0,21,
    #define Z while(
    #define _ ;if(
    #define P return--G,y^=8,
    B,i,y,u,b,I[411],*G=I,x=10,z=15,M=1e4;X(w,c,h,e,S,s){int t,o,L,E,d,O=e,N=-M*M,K
    =78-h<<x,p,*g,n,*m,A,q,r,C,J,a=y?-x:x;y^=8;G++;d=w||s&&s>=h&&v 0,0)>M;do{_ o=I[
    p=O]){q=o&z^y _ q<7){A=q--&2?8:4;C=o-9&z?q["& .$  "]:42;do{r=I[p+=C[l]-64]_!w|p
    ==w){g=q|p+a-S?0:I+S _!r&(q|A<3||g)||(r+1&z^y)>9&&q|A>2){_ m=[COLOR=#ff0000](int *)[/COLOR]!(r-2&7))P G[1]=O,
    K;J=n=o&z;E=I[p-a]&z;t=q|E-7?n:(n+=2,6^y);Z n<=t){L=r?l[r&7]*9-189-h-q:0 _ s)L
    +=(1-q?l[p/x+5]-l[O/x+5]+l[p%x+6]*-~!q-l[O%x+6]+o/16*8:!!m*9)+(q?0:!(I[p-1]^n)+
    !(I[p+1]^n)+l[n&7]*9-386+!!g*99+(A<2))+!(E^y^9)_ s>h||1<s&s==h&&L>z|d){p[I]=n,O
    [I]=m?*g=*m,*m=0:g?*g=0:0;L-=X(s>h|d?0:p,L-N,h+1,G[1],J=q|A>1?0:p,s)_!(h||s-1|B
    -O|i-n|p-b|L<-M))P y^=8,u=J;J=q-1|A<7||m||!s|d|r|o<z||v 0,0)>M;O[I]=o;p[I]=r;m?
    *m=*g,*g=0:g?*g=9^y:0;}_ L>N){*G=O _ s>1){_ h&&c-L<0)P L _!h)i=n,B=O,b=p;}N=L;}
    n+=J||(g=I+p,m=p<O?g-3:g+2,*m<z|m[O-p]||I[p+=p-O]);}}}}Z!r&q>2||(p=O,q|A>2|o>z&
    !r&&++C*--A));}}}Z++O>98?O=20:e-O);P N+M*M&&N>-K+1924|d?N:0;}main(){Z++B<121)*G
    ++=B/x%x<2|B%x<2?7:B/x&4?0:*l++&31;Z B=19){Z B++<99)putchar(B%x?l[B[I]|16]:x)_
    x-(B=F)){i=I[B+=(x-F)*x]&z;b=F;b+=(x-F)*x;Z x-(*G=F))i=*G^8^y;}else v u,5);v u,
    1);}}
    
    

    Here is the command I used to compile and load it (this is for a C3):
    catalina nanochess.c -lci -C C3 -C TTY -O4 -C FLASH -C LARGE -C CACHED_1K
    payload FLASH nanochess -i
    

    But given how long the program takes to make a move, I suspect "Deep Blue" doesn't have much to worry about! :)

    Ross.
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 08:28
    Ross, you're back!
  • RaymanRayman Posts: 14,665
    edited 2013-05-18 08:02
    Thanks for the fix Ross. It now compiles on PropGCC too... Seems to fit with regular LMM mode.
    I give it "E2E4" and it moves right. But, when I hit "enter" so it moves itself, it just sits there...
    Maybe it's just very, very slow like you said...
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-05-18 09:55
    Here's an ANS Forth version of chess that I ported to pfth a while ago. Compile and load the pfth_chess.spin program using the Prop tool, and wait for pfth to initialize and compile the chess program. It just takes a few seconds. Then type "chess" to start the chess program. Moves are entered as "A2-A4". You have to use upper-case letters.

    The program is useable and fairly easy to beat at level 2. At level 3, it can take a few minutes per move, but it plays a better game. I'll look into converting the Forth code into C, which should speed it up quite a bit.
  • RaymanRayman Posts: 14,665
    edited 2013-05-18 13:24
    Just checked up on Toledo chess and it finally made a move!
    So, I guess it takes somewhere between 0.5 and 3 hours to make a move.
    Moved again... Maybe it's more like 30 minutes...
Sign In or Register to comment.