error :no suitable conversion function from "sBoard" to "int" exists

I need to build a game that consists of a board, marbles, holes, and walls.
All marbles are assigned to positive numbers and holes would be negative numbers. It would be read from this file:
4 3 1 //size balls walls
0 1 //marbel 1
1 0 //marbel 2
1 2 //marbel 3
2 3 //hole 1
2 1 //hole 2
3 2 //hole 3
1 1 1 2 //wall (r1, c1, r1,c2)

the game will be over when all the balls are in a hole (they have to match the number that they were assigned to). at some point in the game when the ball goes into the correct hole, they will disappear. The ball can't go over the wall

I created the board using struct as it will recursively call to see which one will give me the best solution.

so far my concern right now is to create the board and put all the necessary parts to start with. Here are my current code and I have some error in bellow.
Thank you in advance for any help.

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
60
 //Game.h
#pragma once
#include <fstream>
public:
	int getBest(int layer);
	int setBest();
	void setupBoard();
};
	int MarbelGame::getBest(int layer) {
	return best;
	}

	int MarbelGame::setBest() {
		getBest(layer + 1);
	}

void Game::setupBoard() {
	//read file
	ifstream infile("marbel.txt");

	infile >> size >> balls >> wallsCount;
	int row, col, row1, row2, col1, col2;
	//balls loop, put positive num for balls
	for (int num = 0; num < balls - 1; num++) {
		infile >> row >> col;
		boardArr[0].board[row][col] = num + 1;
	}
	//hole loop as well put negative num for holes
	for (int num = 0; num < holes - 1; num++) {
		infile >> row >> col;
		boardArr[0].board[row][col] = num - 1;
	}
	//creating walls from file
	for (int num = 0; num < wallsCount; num++) { //wallCount-1?? why
		infile >> row1 >> col1 >> row2 >> col2;

		if (row == row) {//if rows are equal
			if (col1 > col2) {
				//wall is left of col1
				walls[row1][col1] |= LEFT;
				//wall is right of col2
				walls[row2][col2] |= RIGHT;
			}
			else { //col 2 is greater
				walls[row1][col1] |= RIGHT;
				walls[row2][col2] |= LEFT;
			}
		}
		else {
			if (row1 > row2) {
				walls[row1][col1] |= UP;
				walls[row2][col2] |= DOWN;
			}
			else {
				walls[row1][col1] |= DOWN;
				walls[row2][col2] |= UP;
			}
		}
	}
};


Any suggestion on how to check if any of this algorithm correct?
Last edited on
> ifstream infile("marbel.txt"); //error here
read the error message
¿you don't understand the message? post it verbatim and we will explain it to you

apart, ¿have you ever used functions?, ¿have you ever used classes?


for (int num = 0; num < wallsCount - 1; num++)
lets say that `wallsCount' is 1, ¿how many times will that loop execute?
the error is:
	E0079 expected a type specifier

I never used class before, this is the first time. I used functions mostly.

I see what you mean it will end up at 0. I realize that having -1 making it like an array that starts from 0 but it's not an array.

the error in:
1
2
3
4
else { //col 2 is greater
	walls[row1][col1] | = RIGHT;
	walls[row2][col2] | = LEFT;
}

expected a ;

I do not know why I need a ; and I'm not seeing I'm missing that in any place.
You need to read-up on classes. See https://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/

You can't just put code - such as the read file - into a class. All code in a class needs to be part of a member function. Then there are constructors etc which you need to understand.
"| =" needs to be "|="
Thank you I read the link and was able to fix that to the above code.

Moving to the next part of my code to create move right:

I have error in if (!(walls[i][tempj] & RIGHT)) {
expression must have a pointer to object type

and another error in if(tempBoard.board[i][tempj +1]<0){
expression must have integral or unscoped enum type	
Last edited on
at line 2 you've declared `walls' as a single number int size, walls;, not as an array, so you can't use it as an array on line 10

line 4: for int j = size-2; j >= 0; j++) missing open parenthesis '(' after `for'
line 27: temp[i][tempj+1] = temp[i][temp j]; weird space between `temp' and `j'
thank you! that fix some of the error.
but it seems that it still giving me error in line 16 at: col & tempj-1, 27 at: tempj+1 & tempj and 28 at: tempj
all saying
 expression must have a pointer to object type
another question that I have is I need to access best from class Game in another function call solve.

to access that variable, do I need to declare this?
1
2
3
inline int Game::getBest() {
		return best;
	}
I think I was able to fix a lot of my errors after re-reading all the pointers and class tutorials.

This is the next part of my code that needs some help. I try to look online for this problem but still a bit confused about what is wrong.

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
int solve(int layer) { 
	int boardArr[6][6];
	Game Game;

	if (layer > Game.getBest()) {
		return;
	}
	else if (isSolution) {//roll everything to a whole (boardArr[layer])
	//what is the best solution
		if (layer + 1 < Game.getBest()) {
			Game.getBest() = layer + 1; //swap
			return;
		}
	}
}
void roll(int level, int tempBoard) { //call all the roll left right all here
	Game Game;
	int boardArr[6][6];

	if (level == Game.getBest()) {
		return;
	}
	else if (isSolution()) { //boardArr[level] todo: isSolution
		if (level < Game.getBest()) {
			Game.getBest() = level;
			return;
		}
	}
	tempBoard.board = boardArr[level]; //create temp to compare to stop the process if unnecessary
		if (rollRight(tempBoard)) { //succed we call this 
			if (!boardSeen(tempBoard, level)) {} 
			//if havent been seen we out in stack
			boardArr[level + 1] = tempBoard;
			roll(level + 1, tempBoard);
		}
}


I have error in line 11, 25a and 33 with:
expression must be a modifiable lvalue

in line 29 :
expression must have class type

in line 30:
reference of type "sBoard &" (not const-qualified) cannot be initialized with a value of type "int"

Last edited on
11, 25: The return value of Game.getBest() cannot be assigned to.
You might want to say something like Game.setBest(layer + 1).

33: boardArr is two-dimensional but you've only specified one dimension.

29: tempBoard is an int, so it doesn't have any members.

30: again, tempBoard is an int, but rollRight wants an sBoard.
Thank you!
Last edited on
Post the complete current code.
tempBoard is an sBoard.
boardArr[level] is an int.
Does it make sense to compare these two things for equality?

Line 11 looks suspicious as well. And I assume you don't want to print "multiple solutions" in multiple iterations; probably best to move printing outside the function.

Also, boardArr[0] is never reached due to how your for loop is set up.
Last edited on
this is my current code:

I belive I have the rightRoll logic correct but the rest is pretty funky.
All I want at the moment is to see if it is running and I still have the same error that I cant seems to figure out how to fix. I do understand that tempBoard is board while boardArr is int. But I don't know if there is a way to converse it since I still need to assign tempBoard to boardArr.
Last edited on
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Game.h"

using namespace std;

bool rollRight(sBoard& tempBoard) {
	int size;
	int walls[6][6];
	int* temp = new int[size];
	int col, row;
	for (j = size - 2; j >= 0; j++) { //no need to move the last col to the right
		for (i = 0; i >= size - 2; i++) { 
		//so if its all the way to the right then it is in row 3 
				//identify if there is a marbel in that square
			if (tempBoard.board[i][j] > 0) { //we found the ball
				int tempj;
				tempj = j;
				while (true) {
					if (!(walls[i][tempj] & RIGHT)){
						//there is no wall to the right then:
						if (tempBoard.board[i][tempj+1] < 0) {
							//there is a hole next to us
							if (tempBoard.board[i][j] + tempBoard.board[i][tempj-1] == 0) {
								//this is the correct hole
								//then delete the hole and marble = disappear
								tempBoard.board[i][tempj] = 0;
								tempBoard.board[i][tempj+1] = 0;
							}
							else {//is incorrect hole!!!!!!
								return false;
							}
						}
						else if (tempBoard.board[i][tempj+1] == 0) {
							//empty space
							tempBoard.board[i][tempj+1] = tempBoard.board[i][tempj];
							tempBoard.board[i][tempj] = 0;
							tempj++;
						}
					}//else there is a marble =  do nothing
				}   
			} //else there is a wall do nothing
		}
		delete[] temp;
		return true; 
	}
}

bool rollLeft
(sBoard& tempBoard) {
	int size;
	int walls[6][6];
	int* temp = new int[size];
	for (int j = size - 2; col >= 0; j++) {
		for (int i = 0; i>= size - 2; i++) {
			if (tempBoard.board[i][j] > 0) { //we found the ball
				int tempj;
				tempj = j;
				while (true) {
					if (!(walls[i][tempj] & LEFT))
						//there is no wall to the left then:
						if (tempBoard.board[i][tempj+ 1] < 0) {//: //there is a hole next to us
							if (tempBoard.board[i][j] + tempBoard.board[i][tempj - 1] == 0) { //this is the correct hole
							//then delete the hole and marble = disappear
								tempBoard.board[i][tempj] = 0;
								tempBoard.board[i][tempj + 1] = 0;
							}
							else {//is incorrect hole!!!!!!
								return false;
							}
						}
						else if (tempBoard.board[i][tempj + 1] == 0) {//: //empty space
							tempBoard.board[i][tempj + 1] = tempBoard.board[i][tempj];
							tempBoard.board[i][tempj] = 0;
							tempj++;
						}
				}//else there is a marble =  do nothing
			}
		} //else there is a wall do nothing
	}
	delete[] temp;
	return true;
}


bool rollUp(sBoard& tempBoard) {
	int size;
	int walls[6][6];
	int* temp = new int[size];
	for (int i = size - 2; i >= 0; i++) {
		for (int j= 0; j >= size - 2; j++) {
			if (tempBoard.board[i][j] > 0) { //we found the ball
				int tempi;
				tempi = i;
				while (true) {
					if (!(walls[tempi][j] & UP)) {//there is a wall on top
						//there is no wall to the on top then:
						if (tempBoard.board[tempi + 1][j] < 0) { //there is a hole next to us
							if (tempBoard.board[i][j] + tempBoard.board[tempi - 1][j] == 0) { //this is the correct hole
							//then delete the hole and marble = disappear
								tempBoard.board[tempi][j] = 0;
								tempBoard.board[tempi + 1][j] = 0;
							}
							else {//is incorrect hole!!!!!!
								return false;
							}
						}
						else if (tempBoard.board[tempi][j] == 0) {//empty space
							tempBoard.board[tempi + 1][j] = tempBoard.board[tempi][j];
							tempBoard.board[tempi][j] = 0;
							tempi++;
						}
					}//else there is a marble =  do nothing
				}
			} //else there is a wall do nothing
		}
	}
	delete[] temp;
	return true;
}

bool rollDown(sBoard& tempBoard) {
	int size;
	int walls[6][6];
	int* temp = new int[size];
	for (int i= size - 2; i>= 0; i++) {
		for (int j= 0; j>= size - 2; j++) {
			if (tempBoard.board[j][coli> 0) { //we found the ball
				int temprow;
				tempi = i;
				while (true) {
					if (!(walls[tempi][j] & DOWN)) {//there is a wall on the bottom
						//there is no wall to the on bottom then:
						if (tempBoard.board[tempi + 1][j] < 0) { //there is a hole next to us
							if (tempBoard.board[i][j] + tempBoard.board[tempi - 1][j] == 0) { //this is the correct hole
							//then delete the hole and marble = disappear
								tempBoard.board[tempi][j] = 0;
								tempBoard.board[tempi + 1][j] = 0;
							}
							else {//is incorrect hole!!!!!!
								return false;
							}
						}
						else if (tempBoard.board[tempi][j] == 0) {//empty space
							tempBoard.board[temprow + 1][col] = tempBoard.board[tempi][j];
							tempBoard.board[tempi][j] = 0;
							tempi++;
						}
					}//else there is a marble =  do nothing
				}
			} //else there is a wall do nothing
		}
	}
	delete[] temp;
	return true;
}


int solve(int layer) { 
	int boardArr[6][6];
	MarbelGame Game;

	if (layer > Game.getBest(layer)) {
		return;
	}
	else if (isSolution) {//roll everything to a whole (boardArr[layer])
	//what is the best solution
		if (layer + 1 < Game.getBest(layer)) {
			Game.getBest(layer + 1); //swap
			return;
		}
	} 
}

//check if everything is 0
int isSolution() {
	int boardArr[6][6];
	if (boardArr[6][6] = 0) {
		return true;
	} //else should it run another solve
}

bool boardSeen(int tempBoard, int layer) {
	int boardArr[100];
	MarbelGame Game;

	for (int level = layer; level > 0; level--) {
		if (tempBoard == boardArr[level]) {
			return true;
		}
		void roll();
		roll();
		if (Game.getBest(layer) != INT_MAX << Game.getBest(layer + 1));
		else
		{
			cout << "No Solution";
		}

	}
	return false;
}

void roll(int level) { //call all the roll left right all here
	MarbelGame Game;
	int layer;
	int boardArr[6][6];

	if (level == Game.getBest(layer)) {
		return;
	}
	else if (isSolution()) {
		if (level < Game.getBest(layer)) {
			layer = level;
			return;
		}
	}
	sBoard tempBoard;
	boardArr[level][layer]; //create temp to compare to stop the process if unnecessary
		if (rollRight(tempBoard)) { //succed we call this 
			if (!boardSeen(tempBoard, level)) {} //if it been seen we stop recursive
			//if havent been seen we out in stack
			boardArr[level + 1][layer] = tempBoard; //assigning pointer
			roll(level + 1);
		} 
		else if (rollLeft(tempBoard)){
			if (!boardSeen(tempBoard, level)) {} 
			boardArr[level][layer+1] = tempBoard; 
			roll(level);
		}
		else if (rollUp(tempBoard)) {
			if (!boardSeen(tempBoard, level)) {}
			boardArr[level + 1][layer+1] = tempBoard; 
			roll(level + 1);
		}
		else {
			if (!boardSeen(tempBoard, level)) {}
			boardArr[level][layer] = tempBoard; 
			roll(level);
		}
}


int main() {
	cout << "The best solution is: ";
	solve;
	
}
Last edited on
boardArr is int

No. Every one of the variables you've called "boardArr" in your newest code is an array of ints, not an int. In most cases it's a 2-d array, although, bizarrely, in one case it's a 1-d array.

But I don't know if there is a way to converse it since I still need to assign tempBoard to boardArr.

I can't see anywhere where you've shown us the definition of sBoard, so we can't know for sure. But from the code you have posted, it seems as though it has a member called board which appears to be some kind of 2-dimensional array, so maybe that's the thing you want to copy to boardArr?
Last edited on
Topic archived. No new replies allowed.