# Thread: annoying problem, solution should be simple...

1. ## annoying problem, solution should be simple...

Hey all,

Wednesday I started writing a console-based chess program in my C++ class and today I've gotten the basis for the program completed (need to add a check to see if there's check or checkmate, and AI in the future...).

BUT tonight I remembered that I didn't put in a check to prevent pieces from jumping over other pieces, so I started going through and fixing it. While I was doing that, I added a couple of lines to my pawn movement code and now my pawns can't move at all.. hmm!!

here's the pertinent code, with the parts I added in BOLD:

Code:
```if(board[x1][y1] == 'p')
{
if(x1 == 6) // for starting pawns
{
if((x2 == (x1-1) || x2 == (x1-2)) && (y2 == (y1-1) || y2 == (y1+1)) && (board[x2][y2] == '_'))
{
cout << "Invalid move." << endl;
return false;
}
if(x2 == (x1-1) || x2 == (x1-2) && (y2 != y1))
{
cout << "Invalid move." << endl;
return false;
}
if(x2 == (x1-2) && (x1-1) != '_')
{
cout << "Invalid move." << endl;
return false;
}
else
{

board[x1][y1] = '_';
board[x2][y2] = 'p';
this->showBoard();
this->setTurn(2);
return true;
}
}```
this is part of a class method for the class BOARD. The function is called Move, and takes 4 integers (x1, y1, x2, y2), and returns a bool statement (when it was working, it returned void, but I changed it for future functionality I'm adding - I don't see how that would change it though?)

Any ideas? I have a feeling its a really obvious mistake, but those are the hardest for me to spot

Here's the entire code if you need it:

http://dydx.no-ip.com:8080/main.cpp
http://dydx.no-ip.com:8080/board.h
http://dydx.no-ip.com:8080/board.cpp

Popular pages Recent additions