Author: Uri Blass
Date: 04:26:31 04/26/02
I try to implement book and learning in my program. The target of the learning is simply to change the choice of the first move in every game(I may change it later to change the choice of the first move only after a loss or a draw). The program has a textfile of 2 chars when the first char tells it the first move with white and the second char tells it the first move with black. The program always learn to change the first move with white from e4 to d4 and in the next game again to e4 The program also always change the first move with black from 1...Nf6 to 1...Nc6 and back to 1...Nf6 with the exception that it does not choose 1...Nc6 against 1.d4 and prefers 1...d6(I could choose 1...d5 but I do not like the fact that after 1.d4 d5 2.c4 my program plays dxc4 and tries to defend the pawn). Here is the relevant part of my program. I am interested in ideas how to build better opening book(I know that there are a lot of free programs but I know that there are a lot of files in them and the main reason that I almost did not look at other programs except tscp is the fact that I did not know which file to look first). If there is a simple program that only use book(it does not have to be a chess program and it can be in every thinking game) then I am interested to know about it. char c; int fh; char buffer[] = "ee"; unsigned numwrite; FILE *in; for (;;) { if (side == computer_side) { if (hply<2) { //the file moveidata.txt is the book file //if it does not exist we generate it and put the //buffer="ee" in it if (open("moveidata.txt",1)==-1) { fh = _creat( "moveidata.txt", _S_IREAD | _S_IWRITE ); if( fh == -1 ) perror( "Couldn't create data file" ); else { fh=open("moveidata.txt",1); if ((numwrite=_write(fh,buffer,sizeof(buffer)))==-1) perror("write failed"); close( fh ); } } //there is a text file that was created now //or in the past //we try to open it //if we cannot open it we print an error mesage //and finish the program if ((in=fopen("moveidata.txt","rt"))==NULL) { printf("cannot open the file"); return; } //after opening the file we put the file chars into //the string buffer,remember the char //that is relevant to the opening book that is used //and close the file buffer[0]=fgetc(in); buffer[1]=fgetc(in); c=buffer[hply]; fclose(in); //we remember the file that was created by //the variable buffer //We now destroy the file and build again //a similiar file that is designed to be //slightly different fh = _creat( "moveidata.txt", _S_IREAD | _S_IWRITE ); if( fh == -1 ) perror( "Couldn't create data file" ); else { //There was no error in creating a new file //We want to write buffer into the file but //we first need to change buffer in the hply place if (c=='e') buffer[hply]='d'; else buffer[hply]='e'; //we now open the file for writing //,write buffer into it amd close it //I am not sure if we need to check for errors //but I did it to be careful. fh=open("moveidata.txt",1); if ((numwrite=_write(fh,buffer,sizeof(buffer)))==-1) perror("write failed"); close( fh ); } //we now play the book move based on the content of c //that was copied from the previous version of the file //gen_dat[9].m means e4,gen_dat[7].m means d4 based on the order //of moves of my program. if it is black to move and I want //to play Nc6 I check if the square d4=27 //and only if it is empty I play Nc6. if (hply==0) if (c=='e') pv[0][0]=gen_dat[9].m; else pv[0][0]=gen_dat[7].m; if (hply==1) if (c=='e') if (info[27]==EMPTA) pv[0][0]=gen_dat[17].m; else pv[0][0]=gen_dat[6].m; else pv[0][0]=gen_dat[18].m; }
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.