Friday, December 14, 2012

How to program a chess engine in C++ language compatible with Xboard/Winboard: New Game or Board Setup


This function lets the user enter n for a new game or s for board setup for analysis, solve for mate, etc. If the user enters any other characters other than n or s, it will display "Invalid entry" and show the correct choices. If the user selects the expected letters n or s, it will just display "New game = n" or "Board Setup = s". If the user enters the correct letters, a series of functions and statements will follow further to proceed to the other validations of the program (which will not be covered in this article). I will try to cover each function in the chess engine program categorically as possible to make it clear and focused to only one topic at a time.

Source code:

/*
PROGRAM 7a: Chess Engine Programming - New Game or Board Setup
AUTHOR: eternaltreasures
DATE: 2010 September 26
TITLE: How to program a chess engine in C++ language compatible with Xboard/Winboard:
       New Game or Board Setup
*/

#include <iostream>
#include <string>
using namespace std;

#define newline '\n'

void newgame ()
{
char gamesetup = 'n';

cout << newline;

cout << "Enter n for New Game, s for Board Setup: ";
cin >> gamesetup;

if (gamesetup == 'n')
{
cout << "New Game = " << gamesetup;
}
else if (gamesetup == 's')
{
cout << "Board Setup = " << gamesetup;
}
else
{
cout << newline;
cout << "Invalid entry:";
cout << newline;
cout << newline;
cout << "Please Enter:";
cout << newline;
cout << "n for New Game";
cout << newline;
cout << "s for Board Setup";
cout << newline;
cout << newline;
cout << "Invalid entry = " << gamesetup;
cout << newline;
newgame ();
}
}

int main ()
{
newgame ();

return 0;
}

No comments:

Post a Comment