Moving chess pieces

Hey guys,

It's my first post here, so I'm sorry if I do this incorrectly.

I need some help.

I'm trying to create a beginning program that is a basic chess board, except with only one piece. I have to make the knight piece, which starts in the corner of the 8x8 board, move to every available place on the board. Once it landed on that space however, it cannot move back to that space.

I know how to make the board using a 2d array, and I have the knight in one place as an integer. However, I have absolutely no clue on how to move the piece, and how to mark where the piece had been.

Any help at all would be appreciated.



Here is my code so far, so there is an idea of what I am doing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #include <iomanip>
#include <iostream>

using namespace std;


const int knight = 20;

int boardMoving[8][8];

int boardStarting[8][8] =
{
{knight,0,0,0,0,0,0,0};
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}
};

void beginning (void)
{
	int i, j;
	for (i = 0; i < 8; i++)
	{
		for (j = 0; j<8; j++)
		{
			boardMoving[i][j] = boardStarting[i][j];
		}
	}
}

int main (void)
{
	using namespace std;

	beginning();
	
you have
 
const int knight = 20;


how about you also have a
 
const int knightHistory = 21;


Then when you move your piece assign the old element the value of knightHistory. So after all the moves you'll see where it's been.
Last edited on
Thanks. I was planning to do something like that, adding +1 to each zero value after the piece had been moved in order to know that it was already there. Then, I was going to use an if loop to prevent the piece from going there again.
you could go OO and have a ChessPieceClass which would store the coordinate representing it's current position AND a vector that stores the coordinates of everywhere it's been as well?
Topic archived. No new replies allowed.