Various tunings.
[rattatechess.git] / main.cpp
bloba4c6dd7d111d6d5deba3a2f154e42e03d32d353b
1 /***************************************************************************
2 main.cpp - description
3 -------------------
4 begin : Fri Jan 11 2002
5 copyright : (C) 2002-2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include "board.h"
24 #include "engine.h"
26 //--------------------------------------------------------------------------------------------
29 int main(int argc, char *argv[])
31 #if defined(_WIN32) || defined(_WIN64)
32 putenv("HOME=C:");
33 #endif
35 init_stdin();
36 //setvbuf(stdin, NULL, _IOLBF, 0);
37 setbuf(stdin, NULL);
38 setvbuf(stdout, NULL, _IOLBF, 0);
40 bool message = false;
41 Engine *eng = new Engine();
43 /*#define PRINT_SIZE(c) printf("sizeof(" #c ") = %ld\n", sizeof(c))
44 PRINT_SIZE(Move);
45 PRINT_SIZE(HashKey);
46 PRINT_SIZE(HashEntry);
47 PRINT_SIZE(LinePawns);
48 PRINT_SIZE(MatTrack);*/
50 if(argc >=2 && !strcmp(argv[1], "-a"))
51 eng->autotune();
53 if(argc >=4 && !strcmp(argv[1], "-b"))
55 int tot_nodes = 0;
56 eng->set_depth(atoi(argv[2]));
57 for(int i=3;i<argc;i++)
59 FILE* f = fopen(argv[i],"r");
60 if(f)
62 eng->read_board(f);
63 fclose(f);
65 eng->start();
66 printf("\nanalyzing %s\n", argv[i]);
67 eng->find_best_move();
68 tot_nodes += eng->processed_nodes;
71 printf("\ntot processed nodes is %d\n", tot_nodes);
72 return 0;
75 if(argc >=3 && !strcmp(argv[1], "-e"))
77 for(int i=2;i<argc;i++)
79 FILE* f = fopen(argv[i],"r");
80 if(f)
82 eng->read_board(f);
83 fclose(f);
84 eng->print_board();
87 return 0;
90 #if 0
91 eng->print_board();
92 eng->set_depth(9);
93 eng->read_board("r2rb1k1/pp1q1p1p/2n1p1p1/2bp4/5P2/PP1BPR1Q/1BPN2PP/R5K1 w - - 0 1");
94 eng->start();
95 eng->find_best_move();
96 #endif
98 if(!eng->io_xboard)
99 eng->print_board();
101 int prev_move_index = 999;
102 int prev_move_val = 0;
104 while(1)
106 char str[256];
108 if(eng->eng_status==ANALYZING)
110 eng->analyze();
112 else if(eng->computer_color() != eng->color_to_move()
113 || eng->get_status() != PLAYING) //wait for command or move...
115 if(eng->ponder && eng->eng_status==PLAYING &&
116 eng->status == PLAYING &&
117 eng->st_computer_color == eng->board.other_color)
118 eng->do_ponder();
119 else
120 eng->process_input();
122 else
124 if(prev_move_index > eng->mv_done_num)
125 prev_move_val = +INF;
126 prev_move_index = eng->mv_done_num;
128 Move mv = eng->find_best_move();
129 int t = current_time(); ////
130 if(t < eng->max_think_time-5) ////
132 printf("# will simulate a human think %d centiseconds\n", 50*(eng->max_think_time-t));
133 //usleep(5000*(eng->max_think_time-t)); ////
136 //// if(mv.val > prev_move_val+200 && mv.capture && PIECE_OF(mv.capture) != PAWN)
137 //// eng->output("tellicsnoalias say Chomp!\n");
139 prev_move_val = mv.val;
141 if(!eng->io_xboard)
142 eng->print_moves(&mv,1);
144 if(eng->io_xboard && !eng->io_san)
145 eng->output("move %s\n",eng->move_to_coord(str,&mv));
146 else
147 eng->output("move %s\n",eng->move_to_alg(str,&mv));
148 eng->move(mv);
150 if(!eng->io_xboard)
151 eng->print_board();
152 message=true;
155 if(eng->get_status()!=PLAYING && message)
157 message=false;
158 eng->output("%s {%s}\n", eng->status==_01?"0-1":
159 eng->status==_10?"1-0":"1/2-1/2",
160 eng->status_string );