Making a checkers game and cannot get the pieces to move after entering the coordinates

I am making a checkers game and cannot make the pieces move after entering the input. I enter the input and the figure does not move.

#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <Windows.h>
#include <conio.h>
using namespace std;
char row11, row22;
bool kingfigure;
int row1, row2;
int column1, column2;
bool jump;
bool gameinprocess;
const int row = 8, column = 8;
char figureMatrix[row][column];
char moveofwhichplayer;
char yesorno;
char player2;
void displayboard();
void userinput();
bool allowedmove();
void performmove();
void makejump();
void kingpromotion();
void gamefinished();
void displayboard() {
cout << " 1 2 3 4 5 6 7 8" << '\n';
char boardletters = 'A';
for (int j = 0; j < 8; j++) {
cout << " +-------+-------+-------+-------+-------+-------+-------+-------+" << endl;
for (int i = 0; i < 1; i++) {
cout << " | | | | | | | | |" << '\n';
}
cout <<char (boardletters+j) <<" | | | | | | | | |" << '\n';
for (int i = 0; i < 1; i++) {
cout << " | | | | | | | | |" << '\n';
}
}
cout << " +-------+-------+-------+-------+-------+-------+-------+-------+" << '\n';
}
void userinput(){
cout << '\n' << '\n' << '\n' << "From Row: ";
cin >> row11;
cin.ignore();
cout << "From Column: ";
cin >> column1;
cin.ignore();
while (!((row11 >= 'A' && row11 <= 'H') && (column1 >= 0 && column1 <= 7)))
{
cout << "Wrong Input enter only numbers 0 - 7 and letters uppercase 'A' - 'H'" << '\n';
cout << "From Row: ";
cin >> row11;
cin.ignore();
cout << "From Column: ";
cin >> column1;
cin.ignore();
}
cout << "To Row: ";
cin >> row22;
cin.ignore();
cout << "To Column: ";
cin >> column2;
cin.ignore();
while (!((row22 >= 'A' && row22 <= 'H') && (column2 >= 0 && column2 <= 7)))
{
cout << "Wrong Input enter only numbers 0 - 7 and letters uppercase 'A'-'H'" << '\n';
cout << "To Row: ";
cin >> row22;
cin.ignore();
cout << "To Column: ";
cin >> column2;
cin.ignore();
}
}
void gotoxy(short x, short y) {
COORD p = { x , y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
}
struct figure {
char value;
int posX;
int posY;
};
int main() {
displayboard();
figure figureMatrix[8][8] = {
{{' ', 10,3},{'w', 18,3},{' ',26,3},{'w',34,3},{' ',42,3},{'w',50,3},{' ', 58,3},{'w', 66,3}},
{{'w', 10,7},{' ', 18,7},{'w',26,7},{' ',34,7},{'w',42,7},{' ',50,7},{'w', 58,7},{' ', 66,7}},
{{' ', 10,11},{'w', 18,11},{' ',26,11},{'w',34,11},{' ',42,11},{'w',50,11},{' ', 58,11},{'w', 66,11}},
{{' ', 10,15},{' ', 18,15},{' ',26,15},{' ',34,15},{' ',42,15},{' ',50,15},{' ', 58,15},{' ', 66,15}},
{{' ', 10,19},{' ', 18,19},{' ',26,19},{' ',34,19},{' ',42,19},{' ',50,19},{' ', 58,19},{' ', 66,19}},
{{'b', 10,23},{' ', 18,23},{'b',26,23},{' ',34,23},{'b',42,23},{' ',50,23},{'b', 58,23},{' ', 66,23}},
{{' ', 10,27},{'b', 18,27},{' ',26,27},{'b',34,27},{' ',42,27},{'b',50,27},{' ', 58,27},{'b', 66,27}},
{{'b', 10,31},{' ', 18,31},{'b',26,31},{' ',34,31},{'b',42,31},{' ',50,31},{'b', 58,31},{' ', 66,31}},
};
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
gotoxy(figureMatrix[i][j].posX, figureMatrix[i][j].posY);
cout << figureMatrix[i][j].value;
}
userinput();
performmove();
kingpromotion();
gamefinished();
}

bool allowedmove() {
if (figureMatrix[row1][column1] == ' ') {
jump = false;
}
if (row1 == row2 || column1 == column2) {
jump = false;
}
if (figureMatrix[row2][column2] != ' ') {
jump = false;
}
if (figureMatrix[row1][column1] != 'B' && figureMatrix[row1][column1] != 'W') {
if ((moveofwhichplayer == 'B' && row2 < row1) || (moveofwhichplayer == 'W' && row2 > row1))
{
jump = false;
}
}
if ((column2 > column1 + 1 || column2 < column1 - 1) && (row2 == row1 + 1 || row2 == row1 - 1)) {
jump = false;
}
if ((row2 > row1 + 1 || row2 < row1 - 1) && (column2 == column1 + 1 || column2 == column1 - 1)) {
jump = false;
}
if (row2 > row1 + 1 || row2 < row1 - 1) {
if (row2 > row1 + 2 || row2 < row1 - 2) {
jump = false;
}
if (column2 != column1 + 2 && column2 != column1 - 2) {
jump = false;
char player2;
if ((figureMatrix[row1][column1]) == 'w' || 'W') {
player2 = 'b' || 'B';
}
else {
player2 = 'w' || 'W';
}
if (row2 > row1 && column2 > column1) {
if ((figureMatrix[row2 - 1][column2 - 1]) != player2) {
jump = false;
}
}
else if (row2 > row1 && column2 < column1) {
if ((figureMatrix[row2 - 1][column2 + 1]) != player2) {
jump = false;
}
}
else if (row2 < row1 && column2 > column1) {
if ((figureMatrix[row2 + 1][column2 - 1]) != player2)
{
jump = false;
}
}
else if (row2 < row1 && column2 < column1) {
if ((figureMatrix[row2 + 1][column2 + 1]) != player2) {
jump = false;
}
}
jump = true;
}
}
jump = false;
return true;
}


void performmove() {
bool kingfigure = false;
if (figureMatrix[row1][column1] == 'B' || figureMatrix[row1][column1] == 'W') {
bool kingfigure = true;
}
if (moveofwhichplayer == 'B') {
if (kingfigure == false) {
figureMatrix[row2][column2] = 'b';
}
else if (kingfigure == true) {
figureMatrix[row2][column2] = 'B';
}
moveofwhichplayer = 'W';
}
else if (moveofwhichplayer == 'W') {
if (kingfigure == false) {
figureMatrix[row2][column2] = 'w';
}
else if (kingfigure == true) {
figureMatrix[row2][column2] = 'W';
}
moveofwhichplayer = 'B';
}
if (jump == true) {
makejump();
}

}
void makejump() {
if (row2 > row1 && column2 > column1) {
figureMatrix[row2 - 1][column2 - 1] = ' ';
}
else if (row2 > row1 && column2 < column1) {
figureMatrix[row2 - 1][column2 + 1] = ' ';
}
else if (row2 < row1 && column2 > column1) {
figureMatrix[row2 + 1][column2 - 1] = ' ';
}
else if (row2 < row1 && column2 < column1) {
figureMatrix[row2 + 1][column2 + 1] = ' ';
}
displayboard();
do {
cout << "You have jumped over a figure type yes/no, YES/NO if you would like to leap again" << '\n';
cin >> yesorno;
}
while (yesorno != 'yes' && yesorno != 'YES' && yesorno != 'no' && yesorno != 'NO');
if (yesorno == 'yes' || 'YES') {
row11 = row22;
column1 = column2;
cout << "Jump piece from row: " << row1 << " column: " << column1 << '\n';
cout << " To row uppercase A-H: ";
cin >> row2;
cin.ignore();
cout << "To column numbered 0-7: ";
cin >> column2;
cin.ignore();
while (!((row22 >= 'A' && row22 <= 'H') && (column2 >= 0 && column2 <= 7))) {
cout << "Wrong Input enter only numbers 0 - 7 and letters uppercase 'A'-'H'" << '\n';
cout << "To Row: ";
cin >> row22;
cin.ignore();
cout << "To Column: ";
cin >> column2;
cin.ignore();

here is the rest of the code. Thank you!

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 }
				if (moveofwhichplayer == 'B') {
					moveofwhichplayer = 'R';
				}
				else if (moveofwhichplayer == 'R') {
					moveofwhichplayer = 'B';
				}
				allowedmove();
				if (jump == false) {
					cout << "Leap is not valid!!!!!!!!!" << '\n';
					if (moveofwhichplayer == 'B')
					{
						moveofwhichplayer = 'R';
					}
					else if (moveofwhichplayer == 'R') {
						moveofwhichplayer = 'B';
					}
				}
				else if (jump == true) {
					performmove();
				}
			}
	}
	



void kingpromotion() {
		for (int j = 0; j < 8; j++) {
			if (figureMatrix[0][j] == 'b') {
				figureMatrix[0][j] = 'B';
			}
				if (figureMatrix[7][j] == 'w') {
					figureMatrix[7][j] = 'W';
				}
			}
		}
		
	


void gamefinished() {
	int count = 0;
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				{
					if (figureMatrix[i][j] == 'b', 'B', 'w', 'W'); {
							count++;
						}
					}
				}
				if (count > 1) {
					gameinprocess = true;
				}
				else if (count == 1) {
					gameinprocess = false;
				}
			}
		}

Last edited on
Line 6: Get rid of <conio.h>. It's not a standard header.

Lines 8-13: Globals should be avoided.

Line 26: displayboard() leaves a lot to be desired in displaying a checkerboard.

Line 136: C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example:
if (ans == 'Y' || 'y') evaluates as if ((ans == 'Y') || ('y'))

('y') always evaluates to 1 (true), therefore the if statement is always true.

Lines 137, 140, 217: player2 = 'b' || 'B'; Will assign 1 player2.
('b' || 'B') is evaluated first, The result is true.

Line 281: Extraneous semicolon. No statements executes as a result of the conditional.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Why should you avoid globals? Also how would you make the pieces move? Thanks!
moving a piece is going to be a multi part thing. you need to erase it at the old location, erase any enemy that were jumped (could be many), and draw it at its final location, and it could even involve a convoluted jump, kinged, jump back out scenario where you draw it kinged but it was basic before.

I would start simple, then. First try to erase and redraw to indicate a normal move (eg first move made in a new game).

you avoid globals because complicated code of many files and many pages will eventually confuse even the best coder, and you will inadvertently forget what function changed the variable last, and whether its current value is valid, or you will forget and make a local with the same name, or you wlll try to reuse a function that uses a global and the new code is using that global name differently or not at all and it does not work out of the box ... to list just a few of the more common problems they create. In the math sense, constants are not variables, and global 'constants' are more acceptable (though a namespace or enum or other wrapper is considered far better than just out there unqualified). On top of this if you want to code as a career, you will be expected to not use them at most workplaces, so you may as well forget they exist.
Topic archived. No new replies allowed.