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?