*** simplech.c	Fri Nov 20 22:29:05 1998
--- ../../simplech.work/simplech.c	Sat Nov 21 22:05:57 1998
***************
*** 100,107 ****
  
  #endif
- #ifdef UNIX
- #define CLK_TCK 1000000
- #endif
- 
  
  /*----------> includes */
--- 100,103 ----
***************
*** 109,112 ****
--- 105,113 ----
  #include <string.h>
  #include <time.h>
+ #include <ctype.h>
+ 
+ #ifdef UNIX
+ #define CLK_TCK 1000000
+ #endif
  
  /*----------> definitions */
***************
*** 122,128 ****
  
  /*----------> compile options  */
! #undef MUTE
  #undef VERBOSE
! #define STATISTICS
  #undef SHOWLONGMOVES
  #ifdef SHOWLONGMOVES
--- 123,129 ----
  
  /*----------> compile options  */
! #define MUTE
  #undef VERBOSE
! #undef STATISTICS
  #undef SHOWLONGMOVES
  #ifdef SHOWLONGMOVES
***************
*** 142,145 ****
--- 143,148 ----
  void initcheckers(int b[46]);
  void wait(double t);
+ char * reduce (char b[240]);
+ int partof(char buf[240], char c[80]);
  void timerroutine(int b[46]);
  void movetonotation(struct move2 move,char str[80]);
***************
*** 176,185 ****
  
     char str[80];
     int b[46];
     int choice=0;
     int n;
     struct move2 movelist[MAXMOVES];
!    int i;
!    double maxtime=5.0;
  
  #ifdef WIN95
--- 179,192 ----
  
     char str[80];
+    char buf[240];
+    int human;
+    int program;
+    int len;
     int b[46];
     int choice=0;
     int n;
     struct move2 movelist[MAXMOVES];
!    int i = 1;
!    double maxtime=0.25;
  
  #ifdef WIN95
***************
*** 190,219 ****
  #endif
  
!    printf("\nsimple checkers version 1.11");wait(0.1);
     printf("\n8th october 98");wait(0.1);
     printf("\nby martin fierz");wait(0.1);
  
     initcheckers(b);
  
     do
  		{
!       printboard(b);
!       if(testcapture(b,BLACK))
! 			n=generatecapturelist(b, movelist, BLACK);
        else
! 			n=generatemovelist(b, movelist, BLACK);
!       for(i=0;i<n;i++)
  			{
  	 		if( !(i%6)) printf("\n");
  	 		movetonotation(movelist[i],str);
! 	 		printf("%li: %s   ",i+1,str);
  	 		}
        fflush(stdin);
!       printf("\nyour move? (0 exits, 99 tests)  ");
        do
  			{
! 	 		scanf("%d",&choice);
! 			if(choice==99) {timerroutine(b);scanf("%d",&choice);}
! 	 		} while(choice==99);
        if(choice>0 && choice <=n)
  			{
--- 197,258 ----
  #endif
  
!    setvbuf(stdout, NULL, _IOLBF,80);
! 
!    printf("\nsimple checkers version 1.11d");wait(0.1);
     printf("\n8th october 98");wait(0.1);
     printf("\nby martin fierz");wait(0.1);
  
+    printf ("\n\ntype b/w to play black/white: ");
+    scanf ("%1s", &str[0]);
+    if (tolower (str[0]) == 'w') {
+      human = WHITE;
+      program = BLACK;
+    }
+    else {
+      human = BLACK;
+      program = WHITE;
+    }
+ 
+    printf ("set program strength (1-9): ");
+    scanf ("%d", &i);
+    i *= i;
+    maxtime *= i;
+ 
     initcheckers(b);
  
+    if (program == BLACK) {
+      printboard(b);
+      checkers(b,program,maxtime,&str[0]);
+    }
+ 
     do
  		{
!      len=0;
!      printboard(b);
!       if(testcapture(b,human))
! 			n=generatecapturelist(b, movelist, human);
        else
! 			n=generatemovelist(b, movelist, human);
!       for(i=0;i<n&&i<17;i++)
  			{
  	 		if( !(i%6)) printf("\n");
  	 		movetonotation(movelist[i],str);
! 	 		printf("%c: %s   ",i+97,str);
! 			len += sprintf(buf+len,"%c: %s ",i+97,str);
  	 		}
        fflush(stdin);
!       printf("\nyour move? (q exits, t tests)  ");
        do
  			{
! 			  scanf("%70s",&str[0]);
! 			  if (isalpha(str[0]))
! 			    choice = tolower (str[0] - 96);
! 			  else if ((i = partof (buf, reduce (str)))) {
! 			    choice = (buf[i-3] - 96);
! 			  }
! 			  else
! 			    choice=0;
! 			if(choice==20) {timerroutine(b);scanf("%d",&choice);}
! 	 		} while(choice==20);
        if(choice>0 && choice <=n)
  			{
***************
*** 221,234 ****
     		}
     	else break;
!       checkers(b,WHITE,maxtime,&str[0]);
!       printf("%s",str);
        }
     while(1);
!    printf("\nsimple checkers version 1.11");wait(0.1);
     printf("\n8th october 98");wait(0.1);
     printf("\nby martin fierz");wait(1.0);
     return(0);
     }
  
  void movetonotation(struct move2 move,char str[80])
  	{
--- 260,310 ----
     		}
     	else break;
!       printboard(b);
!       checkers(b,program,maxtime,&str[0]);
! #ifdef VERBOSE
!       printf ("%s", str);
! #endif
        }
     while(1);
!    printf("\nsimple checkers version 1.11d");wait(0.1);
     printf("\n8th october 98");wait(0.1);
     printf("\nby martin fierz");wait(1.0);
+    printf("\n");
     return(0);
     }
  
+ char * reduce (char b[240])
+ {
+   int i = strcspn (b, "-");
+   char *tmp = strdup (b);
+ 
+   if (!(tmp = strrchr (tmp, '-')))
+     return ("q");
+   b[i] = 0;
+   strcat (b, tmp);
+   return b;
+ }
+ 
+ int partof (char buf[240], char c[80])
+ {
+   int len = strlen (c);
+   int j = len - 1;
+   int pos = strlen (buf);
+ 
+   while ((pos > 2) && (j >= 0)) {
+     if (!isalpha (buf[pos-3])) {
+       pos --;
+       continue;
+     }
+     if (buf[pos+j] == c[j])
+       j --;
+     else {
+       pos --;
+       j = len - 1;
+     }
+   }
+   return pos;
+ }
+ 
  void movetonotation(struct move2 move,char str[80])
  	{
***************
*** 247,252 ****
  	to++;
  	c='-';
! 	if(move.n>2) c='x';
! 	sprintf(str,"%2li%c%2li",from,c,to);
  	}
  
--- 323,327 ----
  	to++;
  	c='-';
! 	sprintf(str,"%i%c%i",from,c,to);
  	}
  
***************
*** 377,380 ****
--- 452,456 ----
     int eval;
     struct move2 best,movelist[MAXMOVES];
+    char msg[80];
  
  #ifdef STATISTICS
***************
*** 387,395 ****
  /*--------> check if there is only one move */
  	numberofmoves=generatecapturelist(b,movelist,color);
!    if(numberofmoves==1) {domove(b,movelist[0]);sprintf(str,"forced capture");return(1);}
     else
     	{
     	numberofmoves=generatemovelist(b,movelist,color);
!    	if(numberofmoves==1) {domove(b,movelist[0]);sprintf(str,"only move");return(1);}
     	if(numberofmoves==0) {sprintf(str,"no legal moves in this position");return(0);}
        }
--- 463,473 ----
  /*--------> check if there is only one move */
  	numberofmoves=generatecapturelist(b,movelist,color);
!    if(numberofmoves==1) {domove(b,movelist[0]);sprintf(str,"forced capture");
!    movetonotation (movelist[0], msg);printf ("\nsimple-checkers chooses %s\n", msg);return(1);}
     else
     	{
     	numberofmoves=generatemovelist(b,movelist,color);
!    	if(numberofmoves==1) {domove(b,movelist[0]);sprintf(str,"only move");
! 	movetonotation (movelist[0], msg);printf ("\nsimple-checkers chooses %s\n", msg);return(1);}
     	if(numberofmoves==0) {sprintf(str,"no legal moves in this position");return(0);}
        }
***************
*** 400,406 ****
        eval=firstalphabeta(b,i,-10000,10000,color,&best);
  #ifndef MUTE
! 	 	printf("\nt %2.2f, d %2li, v %4li",(clock()-start)/CLK_TCK,i,eval);
  #ifdef STATISTICS
! 	 	printf("  nod %li, gm %li, gc %li, eva %li",
  		alphabetas,generatemovelists,generatecapturelists,
  		evaluations);
--- 478,484 ----
        eval=firstalphabeta(b,i,-10000,10000,color,&best);
  #ifndef MUTE
! 	 	printf("\nt %2.2f, d %2i, v %4i",(clock()-start)/CLK_TCK,i,eval);
  #ifdef STATISTICS
! 	 	printf("  nod %i, gm %i, gc %i, eva %i",
  		alphabetas,generatemovelists,generatecapturelists,
  		evaluations);
***************
*** 410,418 ****
     i--;
  #ifdef STATISTICS
! 	sprintf(str,"\n\nt %2.2f, d %2li, v %4li  nod %li, gm %li, gc %li, eva %li",(clock()-start)/CLK_TCK,i,eval,alphabetas,generatemovelists,generatecapturelists,evaluations);
  #else
!    sprintf(str,"\\nntime %2.2f, depth %li, eval %li",(clock()-start)/CLK_TCK,i,eval);
  #endif
     domove(b,best);
     return(1);
     }
--- 488,499 ----
     i--;
  #ifdef STATISTICS
! 	sprintf(str,"\n\nt %2.2f, d %2i, v %4i  nod %i, gm %i, gc %i, eva %i",(clock()-start)/CLK_TCK,i,eval,alphabetas,generatemovelists,generatecapturelists,evaluations);
  #else
!    sprintf(str,"\\nntime %2.2f, depth %i, eval %i",(clock()-start)/CLK_TCK,i,eval);
  #endif
     domove(b,best);
+    movetonotation (best, msg);
+    printf ("\nsimple-checkers chooses %s\n", msg);
+ 
     return(1);
     }
