C++ DOS Chess

I'm trying to make a Chess game that runs on Dos in C++

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 4597 Views - Last Post: 14 July 2009 - 07:32 PM Rate Topic: -----

#1 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

C++ DOS Chess

Posted 14 July 2009 - 10:19 AM

I'm trying to make a Chess game that runs on Dos in C++. And I'm giving
a menu with that you click 1,2,3 or 4 to do something I'm thinking I would need
an if statement to do that, I need help on the Syntax of If statements.
Here's my code!
// Versoin: 0.1  
// Author: Rick
// Name: Chess
// Copyright: 2008-2009
#include <iostream>
   
	 using namespace std;
	 int main()
	  {
string inputPawn;
string inputRook;
			   
printf	("_________________\n");			  
printf	("|r|n|b|q|k|b|n|r| 8 "); 
printf	("Team 2\n");
printf	("|p|p|p|p|p|p|p|p| 7\n");
printf	("|_|_|_|_|_|_|_|_| 6\n");
printf	("|_|_|_|_|_|_|_|_| 5\n");
printf	("|_|_|_|_|_|_|_|_| 4\n");
printf	("|_|_|_|_|_|_|_|_| 3\n");
printf	("|P|P|P|P|P|P|P|P| 2\n");
printf	("|R|N|B|Q|K|B|N|R| 1 ");
printf	("Team 1\n");
printf	("-----------------\n");
printf	(" A B C D E F G H\n");
//--------------------------------------------------
cout<< "\n";
cout<< "Team 1's Turn!\n"; 
printf ("\n");
printf ("MENU\n");
printf ("Click the # of the action you want to do.\n");
printf ("1. Select A Pawn to move.\n");
printf ("2. Select A Knight to move.\n");
printf ("3. End turn\n");
printf ("4. QUIT\n");
system("PAUSE");
	 return 0;
}

And here's a screen
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: C++ DOS Chess

#2 xPurplex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 93
  • Joined: 17-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 10:41 AM

Well, do you want the user to click on the option, or type it in? Also, in some cases, there will be more than 4 options. And u can't "end your turn" in chess; you must move every turn.
Was This Post Helpful? 0
  • +
  • -

#3 AGRAC393  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Re: C++ DOS Chess

Posted 14 July 2009 - 11:05 AM

Well, you would need a case statement... I'm at robotics now, but when I get home I will see what I can get for you.
Was This Post Helpful? 0
  • +
  • -

#4 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: C++ DOS Chess

Posted 14 July 2009 - 11:12 AM

Thanks! And I want the User to type it sorry I wrote the wrong thing in the game I'll have to change that.
Was This Post Helpful? 0
  • +
  • -

#5 xPurplex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 93
  • Joined: 17-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 11:38 AM

ok, well how I would do it is have a grid (like you do now) and make the user type the current coordinates (for lack of a better word) of the piece he/she wants to move, and of where he/she wants to move it to. It would be a bit easier to write if you had x1 - x8 and y1 - y8 as opposed to letters.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Neumann*


Reputation:

Re: C++ DOS Chess

Posted 14 July 2009 - 12:48 PM

I'm just wondering. Have you figured out an algorithm that will check if the current position on the board is a stalemate or a checkmate? What about an algorithm that will check if the move is legal? For example, there are many restrictions if the king is currently under attack.

When I was writing a game of chess, the above were the core obstacles that I had to overcome.
Was This Post Helpful? 0

#7 xPurplex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 93
  • Joined: 17-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 01:24 PM

yeah, writing a game of chess is alot harder than it sounds.
Was This Post Helpful? 0
  • +
  • -

#8 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: C++ DOS Chess

Posted 14 July 2009 - 02:24 PM

I thought about your way that's why there are still letters and numbers there, but I thought it would be more complicated to program all the different Variables the User might type.

View PostAGRAC393, on 14 Jul, 2009 - 10:05 AM, said:

Well, you would need a case statement... I'm at robotics now, but when I get home I will see what I can get for you.
And when will you get home?
Was This Post Helpful? 0
  • +
  • -

#9 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1048
  • View blog
  • Posts: 4,455
  • Joined: 09-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 02:30 PM

i would look into 2D arrays, but if statment syntax? cant you just google that. you probably want to use cases

cin>>input;
switch(input)
{
case 1:
//do this
break;
case 2: 
// do this
break;
default:
// any other execption
// do this
break;
}


Was This Post Helpful? 0
  • +
  • -

#10 xPurplex  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 93
  • Joined: 17-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 02:31 PM

hmm, maybe the best way to do it is to input a letter and a number, then convert the letter into a number. Then u could just work with numbers without worrying about the input being complex.

SLIGHTLY OFFTOPIC - I'm thinking of making a game of chess myself, but if I do I'll use SDL, console windows are icky! D=
Was This Post Helpful? 0
  • +
  • -

#11 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: C++ DOS Chess

Posted 14 July 2009 - 03:35 PM

View PostImaSexy, on 14 Jul, 2009 - 01:30 PM, said:


cin>>input;
switch(input)
{
case 1:
//do this
break;
case 2: 
// do this
break;
default:
// any other execption
// do this
break;
}


OK, but where would that fit into my code show me an example of my code with that code
in it.
Was This Post Helpful? 0
  • +
  • -

#12 BlackPhoenix  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 152
  • Joined: 11-July 09

Re: C++ DOS Chess

Posted 14 July 2009 - 03:53 PM

You are not ready to build a game of chess.

Chess has more if-statements and checks than any other game. If you cannot create simple if-statements on your own, please check out some tutorial pages and teach yourself C++.

Don't get ahead of yourself.
Was This Post Helpful? 1
  • +
  • -

#13 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: C++ DOS Chess

Posted 14 July 2009 - 04:00 PM

Well would you at least answer my Question?
Was This Post Helpful? 0
  • +
  • -

#14 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1048
  • View blog
  • Posts: 4,455
  • Joined: 09-June 09

Re: C++ DOS Chess

Posted 14 July 2009 - 04:21 PM

i agree you should probably just put this off till later, i mean how are you even mapping the board. All you have now is the prompt to enter the move. How are you keeping a record of all your moves, and what condtions will be true if a piece is kicked off the board. You need to use classes to give diffent properties to each type of piece, you also i need to configure a compute AI. It cant all be done with if statments. Are you sure your up for this?
Was This Post Helpful? 1
  • +
  • -

#15 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 535
  • Joined: 31-December 08

Re: C++ DOS Chess

Posted 14 July 2009 - 04:42 PM

Well I want to atleast learn how to do an if statement as a learning experience, I followed my instinct on how the code worked and I wrote this:
// Versoin: 0.1  
// Author: Rick
// Name: Chess
// Copyright: 2008-2009
#include <iostream>
   
	 using namespace std;
	 int main()
	  {

			   
printf	("_________________\n");			  
printf	("|r|n|b|q|k|b|n|r| 8 "); 
printf	("Team 2\n");
printf	("|p|p|p|p|p|p|p|p| 7\n");
printf	("|_|_|_|_|_|_|_|_| 6\n");
printf	("|_|_|_|_|_|_|_|_| 5\n");
printf	("|_|_|_|_|_|_|_|_| 4\n");
printf	("|_|_|_|_|_|_|_|_| 3\n");
printf	("|P|P|P|P|P|P|P|P| 2\n");
printf	("|R|N|B|Q|K|B|N|R| 1 ");
printf	("Team 1\n");
printf	("-----------------\n");
printf	(" A B C D E F G H\n");
//--------------------------------------------------
cout<< "\n";
cout<< "Team 1's Turn!\n"; 
printf ("\n");
printf ("MENU\n");
printf ("Click the # of the action you want to do.\n");
printf ("1. Select A Pawn to move.\n");
printf ("2. Select A Knight to move.\n");
printf ("3. End turn\n");
printf ("4. QUIT\n");
cin>>input;
switch(input)
{
case 1:
system("CLS");
printf	("_________________\n");			  
printf	("|r|n|b|q|k|b|n|r| 8 "); 
printf	("Team 2\n");
printf	("|p|p|p|p|p|p|p|p| 7\n");
printf	("|_|_|_|_|_|_|_|_| 6\n");
printf	("|_|_|_|_|_|_|_|_| 5\n");
printf	("|_|_|_|_|_|_|_|_| 4\n");
printf	("|1|2|3|4|5|6|7|8| 3\n");
printf	("|P|P|P|P|P|P|P|P| 2\n");
printf	("|R|N|B|Q|K|B|N|R| 1 ");
printf	("Team 1\n");
printf	("-----------------\n");
printf	(" A B C D E F G H\n");
cout<< "\n";
cout<< "You have chosen to move a Pawn.\n";
cout<< " Which one do you want to move?\n";
system("PAUSE");
break;
case 2:
system("CLS");
printf	("_________________\n");			  
printf	("|r|n|b|q|k|b|n|r| 8 "); 
printf	("Team 2\n");
printf	("|p|p|p|p|p|p|p|p| 7\n");
printf	("|_|_|_|_|_|_|_|_| 6\n");
printf	("|_|_|_|_|_|_|_|_| 5\n");
printf	("|_|_|_|_|_|_|_|_| 4\n");
printf	("|_|1|_|_|_|_|2|_| 3\n");
printf	("|P|P|P|P|P|P|P|P| 2\n");
printf	("|R|N|B|Q|K|B|N|R| 1 ");
printf	("Team 1\n");
printf	("-----------------\n");
printf	(" A B C D E F G H\n");
cout<< "\n";
cout<< "You have chosen to move a Knight.\n";
cout<< " Which one do you want to move?\n";
system("PAUSE");
break;
default:
cout<< "Invalid Command, Please enter A valid command\n";
break;
}

	 return 0;
}	 



I get this error when I compile:

In function 'int main()':
'input' undeclared (for this function)
(Each undeclared identifier is reported only once for each function it appears in.)
[Build Error] [Chesstest.o] Error 1



I guess I should just give up on C++ I'll never be good at it I should just
sitck to ASP, HTML and Actionscript. :sad3:
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2