Cant refresh the checkers board on my application

I Cant get my checkers game board to refresh every time i make a move. i have
system("cls")
But it does nothing of the sort..

To move a pice ive created an illusion which swaps one pieces appearance with another :
1
2
3
4
5
6
7
8
9
10
11
void getpiecetomove(int startx,int starty, int endx, int endy)
{
	boardpiece tmp;
     
    //Regular Moves Pieces
    tmp = board[startx][starty];
    board[startx][starty] = board[startx+1][starty+1];
    board[startx+1][starty+1] = tmp;
 
	system("cls");
}
1. 'tmp' is being set to be equivalent to the original board.

2. Then you are moving the piece to have the new board.

3. Afterwards, you are setting the new board equal to 'tmp' (which holds the old board).

So, you're moving the piece and then moving it back. ;)
Just take out that last line of the algorithm.

Cheers,
Tresky
Now the board wont even be re-drawn. Im guessing it was before.

This is my main:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
		cout << "What piece do you want to move?" << endl << "(4,4)" << endl; 
		cin >> w >> x;

		cout << "Enter destination > ";
		cin >> y >> z;
		
		getpiecetomove;

		cout << "Your move is " << "(" << w << "," << x << ")"  "to" "(" << y << "," << z << endl;
		
			system("cls");

		system("pause");


the 'getpiecetomove' is my algorithm. What am i missing?
You aren't passing any parameters into the function. I don't know why that even compiles. Haha.

Also, move the system("cls") to after the system("pause"). It's clearing really quickly so you can't see anything probably.

Also, do you have a function that redraws the board every loop? The board won't refresh itself just cause you alter some values. You have to change the values, clear the screen, and then draw the new board.

-Move Piece
-Clear Screen
-Draw New Board
so,

-Move Piece
-Clear Screen
-Draw New Board

would that be:

getpiecetomove;
system("cls")
displayBoard;

I also noticed that theres no link from the 'movements (what piece do you want to move)' etc to the Algorithm. The computer doesnt know what to swap. Am i right?

sorry, i am a total beginner at this
That's the correct order of things, but your functions need arguments.

You defined in the original post your function getpiecetomove() with four arguments. You have to pass it four arguments when you call it. So, yes you are exactly right. The computer doesn't know what to swap.

1
2
3
4
5
6
7
8
9
10
// Now it does. :)
getpiecetomove(w, x, y, z);

system("cls");

// I haven't seen how you defined this function, but if it has arguments
// you have to pass arguments to it like we did with the first one.
// If there are no arguments you still need the parentheses, but you leave them
// empty like I did below.
displayBoard();
it done the trick, thank you very much!
You're very welcome!

Cheers. :)
Topic archived. No new replies allowed.