Friday, December 14, 2012
How to program a chess engine in C++ language compatible with Xboard/Winboard: Selection of player color
This is a function called by the main () function to let the player select the color he/she prefers. Options include 'w' for selecting the White pieces and 'b' for selecting the Black pieces. The program checks the user input with the expected letters w or b. If the user enters any other letters or characters, it will display the valid selection choices.
Source code:
/*
PROGRAM 8: Chess Engine Programming - Selection of player color
AUTHOR: eternaltreasures
DATE: 2010 September 26
TITLE: How to program a chess engine in C++ language compatible with Xboard/Winboard:
Selection of player color
*/
#include <iostream>
#include <string>
using namespace std;
#define newline '\n'
void selectcolor ()
{
char playercolor = 'w';
cout << newline;
cout << "Please choose your color, w or b: ";
cin >> playercolor;
if (playercolor == 'w')
{
cout << "playercolor w=" << playercolor;
}
else if (playercolor == 'b')
{
cout << "playercolor b=" << playercolor;
}
else
{
cout << newline;
cout << "Please select:";
cout << newline;
cout << "w for White";
cout << newline;
cout << "b for Black";
cout << newline;
cout << newline;
cout << "Wrong player color=" << playercolor;
}
}
int main ()
{
selectcolor ();
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment