Author: William Kerr
Date: 15:09:06 12/27/99
Go up one level in this thread
On December 27, 1999 at 15:40:51, Bert van den Akker wrote:
>On December 26, 1999 at 17:53:11, William Kerr wrote:
>
>>I quickly wrote a program that will read a .epd file and print to display and
>>store to a file all positions contained in the file. If you print the output
>>file you get 28 chess boards per page. However if you have an editor such as
>>UltaEdit (see below) which allows printing two pages on one side (landscape
>>view) and you print on both sides of the page you can display 112 chess boards
>>on one 8.5 by 11 piece of paper. This is great for displaying those large epd
>>files that contain hundreds of test positions. There is no limit to the number
>>of chess boards that the program will display and print to a file. If people are
>>interented I can post the source code (MS VC++).
>>
>>I recommend going to the UltraEdit web site to discover this powerfull editor.
>>The url is www.ultraedit.com
>>
>>You can download a trial version UltraEdit good for a limited number of days.
>>For a small fee you can register the program and use it permenently. This editor
>>is worth its small cost( approximatel $30 when I registered it). You'll use it
>>all the time.
>
>I'am interested in the source code or the executable.
>
>
>BvdA
Here's the code...
//
// Prints multiple chess diagrams from a epd file to the screen and to
// a disk file.
//
#include "iostream.h"
#include "ctype.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
int FALSE = 0;
int TRUE = 1;
int bldBrdRow( char *fenStr, int &fenStrIndex, char *outStr, int row);
int main()
{
FILE *FPinput;
FILE *FPoutput;
int i, j, numBoards, count;
int row = 0;
char fenString[10][255];
char SourceFile[40];
char OutFile[80];
char outStr[240];
int status = FALSE;
int gotFullLine = FALSE;
int fenStrIndex[10] = {0};
cout << "Don't forget to reduce footer size from 1 inch " << endl
<< "to 0.75 inch when printing the resulting output file." << endl << endl;
cout << "FEN or EPD file to open: ";
cin >> SourceFile;
cout << endl;
if ((FPinput = fopen(SourceFile, "r")) == NULL)
{
cout << "Can't open " << SourceFile << " for reading" << endl;
exit(1);
}
cout << "Output file name: ";
cin >> OutFile;
cout << endl;
if ((FPoutput = fopen(OutFile, "w")) == NULL)
{
cout << "Can't open " << OutFile << " for writing" << endl;
fclose(FPinput);
fclose(FPoutput);
exit(1);
}
cout << "Number of boards on each row (1 - 10; typ = 4)";
cin >> numBoards;
cout << endl;
if (numBoards < 1)
{
numBoards = 1;
}
if (numBoards > 10)
{
numBoards = 10;
}
while (!feof(FPinput))
{
count = 0;
gotFullLine = FALSE;
// read in enough fen lines from the input file to
// process a single row of chess boards accross the page
while (!feof(FPinput) && !gotFullLine)
{
if ( fgets(fenString[count], 254, FPinput) != NULL)
{
count++;
if (count == numBoards)
{
gotFullLine = TRUE;
}
}
}
// start the next group of chess boards to be displayed across the page
row = 1;
for (i = 0; i < 10; i++)
{
fenStrIndex[i] = 0; // clear index into fen strings
}
// process all chess boards that are to be displayed across the page
for (i = 0; i < 8; i++) // eight rows on a chess board
{
outStr[0] = '\0'; // so strcat() works
// Build one complete row for each chess board contained across the
// page
for (j = 0; j < count; j++) // number of boards per row
{
// process current row for a chess board
status = bldBrdRow(fenString[j], fenStrIndex[j], outStr, row);
if (status == FALSE)
{
cout << "fen string error in row " << row << endl;
}
fenStrIndex[j]++; // next chess board
}
cout << outStr << endl;
fprintf(FPoutput, "%s\n", outStr); /* to output file */
row++;
}
// vertical spacing of chess boards
cout << endl << endl;
fprintf(FPoutput,"\n");
fprintf(FPoutput,"\n");
}
// close both files
fclose(FPinput);
fclose(FPoutput);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
// function: bldBrdRow
//
////////////////////////////////////////////////////////////////////////////////
//
// The purpose of this routine is to produce one row of the chess board which
// is pointed to by fenStr and store the result pointed to by outStr.
// FenStrIndex is the index into the complete fen string in which to convert.
// The updated fenStrIndex is returned to the caller. The routine returns status
// of true if all was successful or false if an error was detected.
//
////////////////////////////////////////////////////////////////////////////////
int bldBrdRow( char *fenStr, int &fenStrIndex, char *outStr, int row)
{
int col = 0;
char ch, tempStr[2];
int i;
int count;
// while decoding one row of the fen chess board
while (fenStr[fenStrIndex] != '/' && fenStr[fenStrIndex] != ' ' && col < 9)
{
ch = fenStr[fenStrIndex]; // get current fen character
if (isalpha(ch)) // if alpha charactor then
{ // decode piece
strcat(outStr, " "); // place ' ' in output string
strncat(outStr, &ch, 1); // place fen piece in string
col++;
}
else if (isdigit(ch)) // if num then skip board squares
{
tempStr[0] = ch; // put ascii digit into tmp string
tempStr[1] = '\0';
count = atoi(tempStr); // convert ascii to integer
for (i = 0; i < count; i++)
{
strcat(outStr, " ."); // store empty square
col++; // next column
}
}
else // error if not alpha or num
{
return FALSE;
}
fenStrIndex++; // update fenStrIndex
}
strcat(outStr, " "); // horizontal space between chess
// boards
if (col == 8) // error if not 8 columns
{
return TRUE;
}
else
{
return FALSE;
}
}
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.