Friday, December 14, 2012

Chess Engine Programming - Checking the legal moves for White and Black on the first move

/*
PROGRAM 9: Chess Engine Programming - Checking the legal moves for White and Black on the first move

PURPOSE: On the first move of White, there are only 4 valid and legal Knight moves and also
         4 valid legal Knight moves for Black, making a total of 8 acceptable Knight moves
         on the first move. This program checks this validity using a hard coded method
         but it can also be done by reading from a file containing a list of all the legal
         moves on the first move of White or Black. It can also be tested using a procedure
         by coding the rules how the Knight moves in 'L-shaped' fashion, and other methods
         such as using a coordinate system and noting the "from square" (previous location)
         going to the "to square" (destination location).
         Also, on the first move for White, there are 16 legal and valid pawn moves and the
         same is true for Black, making a total of 32 acceptable pawn moves on the first
         move for White and Black. A total of 40 legal and valid moves (8 Knight moves and 32 Pawn moves)
         are possible on the first move of White and Black.
         This program assumes White is a Human Player and the Black Player is Computer. The user
         (player) enters a move first then the program tests the validity or legality of White's
         first move (in this case 20 legal moves). If White's move is acceptable, the Computer
         player responds with a move. If White Human Player moves any other move beside the
         20 acceptable moves, it will display an error to prompt the player "Illegal move.".

LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 6
*/

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

#define newline '\n'

string player_move;
string from_valid_move_choices = "e5";
int move_counter = 0;

int main ()
{
cout << endl;
cout << "Computer Chess Engine program 1.0" << endl << endl;
cout << "[Event: Chess Game Match]" << endl;
cout << "[Site: USA]" << endl;
cout << "[Date: 2010 October 6]" << endl;
cout << "[White: Human Player]" << endl;
cout << "[Black: Computer]" << endl << endl;

move_counter = move_counter + 1;

cout << "White Player: Please enter your move. " << move_counter << "."; cin >> player_move;

if  ((player_move == "Nf3") || (player_move == "Nh3")
  || (player_move == "Nc3") || (player_move == "Na3")
  || (player_move == "a3")  || (player_move == "a4")
  || (player_move == "b3")  || (player_move == "b4")
  || (player_move == "c3")  || (player_move == "c4")
  || (player_move == "d3")  || (player_move == "d4")
  || (player_move == "e3")  || (player_move == "e4")
  || (player_move == "f3")  || (player_move == "f4")
  || (player_move == "g3")  || (player_move == "g4")
  || (player_move == "h3")  || (player_move == "h4"))
     
   cout << "Thank you! Computer Player move is " << move_counter << "... " << from_valid_move_choices << endl;
else
   cout << "Illegal move." << endl << endl;

}

No comments:

Post a Comment