problem with moving pieces[solved]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

problem with moving pieces[solved]

Post by cndr »

So I'm working on a chess program and am working on legal moves, so far I have pawns and knights fully implemented but am having a little bit more trouble with the rook, how the pieces move on the board is the user selects a piece that piece is on tempSquare, and selects the square they want to move it to (selectedSquare), I then do a check to see if that piece is a rook, if it is then it goes through the code below. 12 is a vertical move, and 1 is a horizontal move. The problem with this code is that if there is a free square beside the rook it can move anywhere, and when it moves horizontal it doesn't register blocked squares, I've been trying to think of a different way to approach this problem for the last couple of days, well at least when I have time to do so, anyone have any ideas on how I should go about solving this?

Code: Select all

void checkRook()
{
setBlocked(12);
setBlocked(1);
}

Code: Select all

void setBlocked(int x)
{
	//UP the board
	if (tempSquare > selectedSquare)
	{
		
		for (int i = tempSquare-x; i > selectedSquare; i-=x)
		{
				if (textBoard[i] != EMPTY)
				{
				blocked = true;
				}
		}

		checkBlocked();
	}
	//Down the board
	else if (tempSquare < selectedSquare)
	{
		for (int i = tempSquare+x; i < selectedSquare; i+=x)
		{
				if (textBoard[i] != EMPTY)
				{
				blocked = true;
				}
		}
		checkBlocked();
	}
}

Code: Select all

void checkBlocked()
{
	if (blocked == false)
	{
		movePiece();
	}
	else if (blocked == true)
	{
		blocked = false;
	}
}
Last edited by cndr on Fri May 21, 2010 12:07 pm, edited 1 time in total.
Long Live The Queen!
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: problem with moving pieces [solved]

Post by cndr »

never mind I solved it
Long Live The Queen!
Post Reply