Author: Matthias Gemuh
Date: 15:39:08 11/28/02
Go up one level in this thread
On November 28, 2002 at 16:54:16, Sune Fischer wrote: >On November 28, 2002 at 13:21:14, Matthias Gemuh wrote: > >>My book record is >> >> >>typedef struct { >> unsigned long HashKey, HashLock; >> CHESSMOVE Move; >> int Result, lrnResult; >> unsigned int Count; >>} BOOKENTRY; >> >>/Matthias. > >Do you know of a clever way to print such a struct binary to a file, and read it >back in? > By taking a look at this memory mapped read/write (Borland C++ Builder 5), you should be able to read and dump BigLion's book. Note the meaning of first bytes in book. typedef unsigned long CHESSMOVE; //unsigned long Move Bits (from high to low): nSideMoving=1, nPieceNr=3, nFrom=6, nTo=6, nCapturedNr=3, promo=3, CastleRights=4(C8G8C1G1), ep=6 void InsertBookEntry(TMemoryStream* pMemFile, BOOKENTRY bk) { int i, j, k, nGameResult; unsigned long nCount=0, Offset1, Offset2, nMove; BOOKENTRY tmpbk; pMemFile->Position = 0; pMemFile->Read((void *)(unsigned long *)&nCount, sizeof(unsigned long)); Offset1 = pMemFile->Position; pMemFile->Read((void *)(unsigned long *)&Offset2, sizeof(unsigned long)); pMemFile->Position = Offset2; if (nCount) { for (int i= 0; i < nCount; i++) { Offset1 = pMemFile->Position; pMemFile->Read((void *)(BOOKENTRY *)&tmpbk, sizeof(BOOKENTRY)); if ((tmpbk.HashKey == bk.HashKey) && (tmpbk.HashLock == bk.HashLock) && (tmpbk.Move == bk.Move)) { tmpbk.Result += bk.Result; tmpbk.Count += 1; pMemFile->Position = Offset1; pMemFile->Write((void *)(BOOKENTRY *)&tmpbk, sizeof(BOOKENTRY)); return; } } } pMemFile->Write((void *)(BOOKENTRY *)&bk, sizeof(BOOKENTRY)); pMemFile->Position = 0; nCount++; pMemFile->Write((void *)(unsigned long *)&nCount, sizeof(unsigned long)); } /Matthias. >-S.
This page took 0 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.