|
-
March 16th, 2008, 09:30 PM
#1
Incrementing through an Enumeration
I'm using Microdoft Visual C++ 2008 Express Edition, but I'm currently using it to create a console chess application. I have an enumerated type called Player, and a variable of type Player called TURN. I want to be able to use the incement operator on TURN (prefix or postfix, doesn't really matter). Although I think the prefix is easier to overload than the postfix... if, in fact, I have to overload it to make this work (I don't even know if you can overload an operator for an enumeration).
Code:
enum Player { HUMAN, COMPUTER, NO_PLAYER };
Player TURN = HUMAN;
bool MATE = false;
while(!MATE)
{
Move theMove; // Move class used to retrieve and store the user's move
if(TURN == NO_PLAYER)
TURN = HUMAN;
if(TURN == HUMAN) // use TURN to determine if it's human's turn to move
{
while(theMove.isValid() == false)
{
theMove.getMove(); // prompt user to input next move
}
applyMove(theMove); // carry out the move
}
else
{
// have AI determine computer's best next move
}
++TURN; // increment turn
if( . . . ) // test for checkmate
MATE = true;
}
So, how can I do this without getting errors from the compiler? I appreciate your help. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|