bitmapper.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* This file contains the main entry-point for CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of CHESS.
  4. CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. CHESS, but only under the conditions described in the
  12. CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. #include <stdio.h>
  18. #include "algdefs.h"
  19. #include "fixeddefs.h"
  20. #include "crucialdefs.h"
  21. #include "bitmacs.h"
  22. #include <ctype.h>
  23. #include <sys/types.h>
  24. #include <sys/time.h>
  25. #include <sys/resource.h>
  26. #include "movelist.h"
  27. extern struct timeval timcpu;
  28. extern struct rusage rubuf;
  29. extern int ngamemvs;
  30. extern struct gmlist game[MAXGAME];
  31. int gfrsq,gtosq,gmover,gpc;
  32. MAP pieces[NCOLORS][NPIECES][WPERM];
  33. MAP side[NCOLORS][WPERM];
  34. MAP empty[WPERM];
  35. MAP edge[WPERM];
  36. MAP sanctuary[WPERM];
  37. MAP sanct1st[NCOLORS][WPERM];
  38. MAP rows[MAXROWS][WPERM];
  39. MAP cols[MAXCOLS][WPERM];
  40. MAP diagleft[MAXDIAG][WPERM];
  41. MAP diagright[MAXDIAG][WPERM];
  42. MAP knightmvmaps[(BPERW * WPERM)][WPERM];
  43. MAP kingmvmaps[(BPERW * WPERM)][WPERM];
  44. MAP attackfr[NCOLORS][BPERW*WPERM][WPERM];
  45. MAP attackto[NCOLORS][BPERW*WPERM][WPERM];
  46. MAP pmovefr[NCOLORS][BPERW*WPERM][WPERM];
  47. MAP pmoveto[NCOLORS][BPERW*WPERM][WPERM];
  48. int okprint,tomove,sqorigin,sqdest;
  49. extern unsigned int sqbits[];
  50. extern char *sqchar[];
  51. extern char *strpiece[];
  52. main (argc, argv)
  53. int argc;
  54. char *argv[];
  55. {
  56. int niterations;
  57. register i;
  58. char cmd[20];
  59. float timused;
  60. printf("Welcome.");
  61. init();
  62. printf("\n");
  63. gen();
  64. for (;;)
  65. {
  66. evalpos(FALSE,tomove);
  67. printf("%s_",tomove == WHITE ? "white":"black");
  68. scanf ("%s",cmd);
  69. if (strcmp(cmd,"bd") == 0)
  70. prbd();
  71. else if (strcmp(cmd,"game") == 0)
  72. list_game();
  73. else if (strcmp(cmd,"wgame") == 0)
  74. write_game();
  75. else if (strcmp(cmd,"eval") == 0)
  76. evalpos(TRUE,tomove);
  77. else if (strcmp(cmd,"test") == 0)
  78. {
  79. printf("Test incremental update move generation.\n");
  80. printf("Which move to make?\n");
  81. scanf("%s",cmd);
  82. makemvstr(cmd); /* First, get global values for iteration */
  83. genupdate(OPP(tomove),FALSE);
  84. unmakemvpc(OPP(tomove),
  85. game[ngamemvs].move.from,
  86. game[ngamemvs].move.to,
  87. game[ngamemvs].move.movpiece);
  88. genupdate(tomove,TRUE);
  89. printf("Iteration count? ");
  90. scanf("%d",&niterations);
  91. timeon();
  92. test_igen(niterations);
  93. timeoff();
  94. timused = (float)timcpu.tv_sec+((float)timcpu.tv_usec/1000000.);
  95. printf("%.2f gens/sec\n",niterations/timused);
  96. }
  97. else if (strcmp(cmd,"maps") == 0)
  98. print_maps();
  99. else if (strcmp(cmd,"amaps") == 0)
  100. {
  101. printf("--------- White attack maps ----------\n");
  102. pramaps(WHITE);
  103. printf("--------- Black attack maps ----------\n");
  104. pramaps(BLACK);
  105. }
  106. else if (strcmp(cmd,"reset") == 0)
  107. {
  108. init();
  109. gen();
  110. }
  111. else if (strcmp(cmd,"legals") == 0)
  112. legals();
  113. else if (strcmp(cmd,"quit") == 0)
  114. exit(0);
  115. else if (strcmp(cmd,"undo") == 0)
  116. {
  117. if (ngamemvs >= 0)
  118. {
  119. unmakemvpc(OPP(tomove),
  120. game[ngamemvs].move.from,
  121. game[ngamemvs].move.to,
  122. game[ngamemvs].move.movpiece);
  123. genupdate(tomove,TRUE);
  124. }
  125. else printf("Sorry, no more moves to retract.\n");
  126. }
  127. else if (((strlen(cmd) == 4) && isalpha(cmd[0]) && isdigit(cmd[1]) &&
  128. isalpha(cmd[2]) && isdigit(cmd[3])) ||
  129. strcmp(cmd,"o-o") == 0 || strcmp(cmd,"o-o-o") == 0)
  130. {
  131. makemvstr(cmd);
  132. genupdate(OPP(tomove),FALSE);
  133. }
  134. else if (strcmp(cmd,"?") == 0 || strcmp(cmd,"help") == 0)
  135. {
  136. printf("? or help - show this help list\n");
  137. printf("amaps - show attack bitmaps\n");
  138. printf("bd - print the board\n");
  139. printf("eval - show evaluation of current board\n");
  140. printf("game - print the game so far with statistics\n");
  141. printf("legals - show movelists for current position\n");
  142. printf("maps - show initialization bitmaps\n");
  143. printf("quit - quit and exit from program\n");
  144. printf("test - run a timing test of move generation\n");
  145. printf("undo - retract last move\n");
  146. printf("wgame - as 'game' but to the file ch<number>\n");
  147. }
  148. }
  149. }
  150. test_igen (niterations)
  151. {
  152. register i;
  153. for (i = 0; i < niterations; i++)
  154. {
  155. makemvpc(tomove,gfrsq,gtosq,gpc);
  156. genupdate(OPP(tomove),FALSE);
  157. unmakemvpc(OPP(tomove),
  158. game[ngamemvs].move.from,
  159. game[ngamemvs].move.to,
  160. game[ngamemvs].move.movpiece);
  161. genupdate(tomove,TRUE);
  162. }
  163. }