-
Notifications
You must be signed in to change notification settings - Fork 4
/
practice.c
138 lines (121 loc) · 3.61 KB
/
practice.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
File: practice.c
Created: January 29, 1998
Modified: July 12, 1999
Author: Gunnar Andersson ([email protected])
Contents: A small utility which enables the user to browse
an opening book file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "constant.h"
#include "display.h"
#include "game.h"
#include "globals.h"
#include "macros.h"
#include "moves.h"
#include "osfbook.h"
#include "patterns.h"
#include "search.h"
#define RANDOM 1
#define HASHBITS 5
int
main( int argc, char *argv[] ) {
char *book_name;
char *buffer;
const char *opening_name;
char move_string[10];
int i;
int side_to_move;
int quit, repeat;
int command, move;
int old_stm[61];
int move_list[61];
int row[61];
if ( argc == 2 )
book_name = argv[1];
else if ( argc == 1 )
book_name = strdup( "book.bin" );
else {
puts( "Usage:\n [practice <book file>]" );
puts( "\nDefault book file is book.bin\n" );
puts( "Commands: When prompted for a move, a legal move may" );
puts( " a number of moves to take back must be entered." );
puts( "To exit the program, type 'quit'." );
puts( "" );
printf( "Gunnar Andersson, %s\n", __DATE__ );
exit( EXIT_FAILURE );
}
init_osf( TRUE );
read_binary_database( book_name );
game_init( NULL, &side_to_move );
toggle_human_openings( FALSE );
set_names( "", "" );
quit = FALSE;
while ( !quit ) {
int val0, val1, orientation;
set_move_list( black_moves, white_moves, score_sheet_row );
opening_name = find_opening_name();
if ( opening_name != NULL )
printf( "\nOpening: %s\n", opening_name );
get_hash( &val0, &val1, &orientation );
display_board( stdout, board, side_to_move, TRUE, FALSE, FALSE );
printf( "Book hash: %d %d (%d)\n\n", val0, val1, orientation );
extended_compute_move( side_to_move, FALSE, TRUE, 6, 16, 18 );
printf( "Scores for the %d moves:\n", get_evaluated_count() );
for ( i = 0; i < get_evaluated_count(); i++ ) {
buffer = produce_eval_text( get_evaluated(i).eval, FALSE );
printf( " %c%c %s\n", TO_SQUARE( get_evaluated(i).move ), buffer );
free( buffer );
}
puts( "" );
do {
repeat = FALSE;
if ( side_to_move == BLACKSQ )
printf( "Black move: " );
else
printf( "White move: " );
fflush( stdout );
scanf( "%s", move_string );
if ( !strcmp( move_string, "quit" ) )
quit = TRUE;
else {
command = atoi( move_string );
if ( (command >= 1) && (command <= disks_played) ) {
for ( i = 1; i <= command; i++ )
unmake_move( old_stm[disks_played - 1],
move_list[disks_played - 1] );
side_to_move = old_stm[disks_played];
score_sheet_row = row[disks_played];
}
else if ( command != 0 ) {
printf( "Can't back up %d moves\n\n", command );
repeat = TRUE;
}
else {
generate_all( side_to_move );
move = (move_string[0] - 'a' + 1) + 10 * (move_string[1] - '0');
if ( (move_string[0] >= 'a') && (move_string[0] <= 'h') &&
(move_string[1] >= '1') && (move_string[1] <= '8') &&
valid_move( move, side_to_move ) ) {
old_stm[disks_played] = side_to_move;
row[disks_played] = score_sheet_row;
move_list[disks_played] = move;
(void) make_move( side_to_move, move, TRUE );
if ( side_to_move == BLACKSQ )
black_moves[++score_sheet_row] = move;
else
white_moves[score_sheet_row] = move;
side_to_move = OPP( side_to_move );
}
else {
puts( "Move infeasible\n" );
repeat = TRUE;
}
}
}
} while ( repeat );
}
return EXIT_SUCCESS;
}