Improvements to the eval, try to checkmate sacrifying as much as possible.
[rattatechess.git] / io.cpp
blob23b43fa10fb0ff8605e4ec9a77a698b5d32ccdc2
1 /***************************************************************************
2 main.cpp - description
3 -------------------
4 begin : Dom Oct 9 2005
5 copyright : (C) 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 ***************************************************************************/
18 #include <stdarg.h>
19 #include <string.h>
20 #include "engine.h"
21 #include "commands.h"
23 void Engine::output(const char* fmt, ...)
25 char buf[4096];
26 int len;
27 va_list va;
28 va_start( va, fmt );
29 len = MIN(vsnprintf( buf, 4096, fmt, va), 4096);
30 va_end( va );
32 fwrite(buf, 1, len, stdout);
33 if(log)
35 fwrite(buf, 1, len, log);
36 fflush(log);
40 void Engine::process_input()
42 int argc = 0;
43 char **argv;
44 int retv = 0;
45 Move mv;
47 argv = get_tokenized(&argc);
49 if(!argv)
50 exit(0);
52 if(!argc || strlen(argv[0])==0)
54 free(argv);
55 return;
58 /* is this a move? */
59 retv = parse_move(&mv, argv[0]);
61 /* not a move */
62 if(retv == 0)
64 CmdSet::iterator it = commands.lower_bound(argv[0]);
65 if( it != commands.end() &&
66 it->first.compare(0, strlen(argv[0]), argv[0]) == 0 )
68 Cmd& c = it->second;
70 if(it->first != argv[0])
71 output("%s\n", it->first.c_str());
73 if(argc-1 < c.min())
74 output("Error, not enough arguments (%d) for command '%s' (try 'help')\n", argc-1, it->first.c_str() );
75 else if(argc-1 > c.max())
76 output("Error, too many arguments (%d) for command '%s' (try 'help')\n", argc-1, it->first.c_str() );
77 else
78 c.run(argc-1, argv+1);
80 else
81 output("Illegal command: '%s' (try 'help')\n", argv[0]);
83 /* a legal valid move */
84 else if(retv == 1)
86 if(!io_xboard)
87 print_moves(&mv,1);
89 move(mv);
91 if(!io_xboard)
92 print_board();
94 /* a move that is illegal or ambiguous */
95 else if(retv == 2)
100 free(argv);