more eval tunings.
[rattatechess.git] / main.cpp
blobfc1e1d4ef49d2d436e2ae461a1d8060d21caaf81
1 /***************************************************************************
2 main.cpp - description
3 -------------------
4 begin : Fri Jan 11 2002
5 copyright : (C) 2002-2005 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 setbuf(stdin, NULL);
37 setbuf(stdout, NULL);
39 // char cwd[1024];
40 // getcwd(cwd, 1024);
41 // printf("telluser \"cwd = %s\"\n", cwd);
42 // printf("telluser \"sizeof(uint64_t) = %d, sizeof HashKey = %d\"\n", sizeof(uint64_t), sizeof(HashKey));
44 bool message = false;
45 Engine *eng = new Engine();
47 /*#define PRINT_SIZE(c) printf("sizeof(" #c ") = %ld\n", sizeof(c))
48 PRINT_SIZE(Move);
49 PRINT_SIZE(HashKey);
50 PRINT_SIZE(HashEntry);
51 PRINT_SIZE(LinePawns);
52 PRINT_SIZE(MatTrack);*/
54 if(argc >=2 && !strcmp(argv[1], "-a"))
55 eng->autotune();
57 if(argc >=4 && !strcmp(argv[1], "-b"))
59 int tot_nodes = 0;
60 eng->set_depth(atoi(argv[2]));
61 for(int i=3;i<argc;i++)
63 FILE* f = fopen(argv[i],"r");
64 if(f)
66 eng->read_board(f);
67 fclose(f);
69 eng->start();
70 printf("\nanalyzing %s\n", argv[i]);
71 eng->find_best_move();
72 tot_nodes += eng->processed_nodes;
75 printf("\ntot processed nodes is %d\n", tot_nodes);
76 return 0;
79 if(argc >=3 && !strcmp(argv[1], "-e"))
81 for(int i=2;i<argc;i++)
83 FILE* f = fopen(argv[i],"r");
84 if(f)
86 eng->read_board(f);
87 fclose(f);
88 eng->print_board();
91 return 0;
94 #if 0
95 eng->print_board();
96 eng->set_depth(9);
97 eng->read_board("r2rb1k1/pp1q1p1p/2n1p1p1/2bp4/5P2/PP1BPR1Q/1BPN2PP/R5K1 w - - 0 1");
98 eng->start();
99 eng->find_best_move();
100 #endif
102 if(!eng->io_xboard)
103 eng->print_board();
105 int prev_move_index = 999;
106 int prev_move_val = 0;
108 while(1)
110 char str[256];
112 if(eng->eng_status==ANALYZING)
114 eng->analyze();
116 else if(eng->computer_color() != eng->color_to_move()
117 || eng->get_status() != PLAYING) //wait for command or move...
119 if(eng->ponder && eng->eng_status==PLAYING &&
120 eng->status == PLAYING &&
121 eng->st_computer_color == eng->board.other_color)
122 eng->do_ponder();
123 else
124 eng->process_input();
126 else
128 if(prev_move_index > eng->mv_done_num)
129 prev_move_val = +INF;
130 prev_move_index = eng->mv_done_num;
132 Move mv = eng->find_best_move();
134 if(mv.val > prev_move_val+200 && mv.capture && PIECE_OF(mv.capture) != PAWN)
135 //eng->output("tellicsnoalias say Chomp!\n");
136 eng->output("telluser Chomp!\n");
137 prev_move_val = mv.val;
139 if(!eng->io_xboard)
140 eng->print_moves(&mv,1);
142 if(eng->io_xboard && !eng->io_san)
143 eng->output("move %s\n",eng->move_to_coord(str,&mv));
144 else
145 eng->output("move %s\n",eng->move_to_alg(str,&mv));
146 eng->move(mv);
148 if(!eng->io_xboard)
149 eng->print_board();
150 message=true;
153 if(eng->get_status()!=PLAYING && message)
155 message=false;
156 eng->output("%s {%s}\n", eng->status==_01?"0-1":
157 eng->status==_10?"1-0":"1/2-1/2",
158 eng->status_string );