patterncppMinor
Iterative Deepening and A*
Viewed 0 times
anddeepeningiterative
Problem
I am working on a fifteen puzzle, and just got it working finally.
My next step is to implement an Iterative Deepening search on the puzzle to solve it.
I assume you go column by column, row by row with a loop until the checkwin function is complete?
I would really love any pointers or guidance that can be given.
Does not have to be code.
(A is included, as that is the next step of my project to implement IDA)
Here is my Code:
```
#include
#include
enum EMove { keUp = 'w',
keDown = 's',
keLeft = 'a',
keRight = 'd'};
// Function declarations
void InitializeBoard(char[4][4]);
void PrintBoard(char[4][4]);
void LocateSpace(int&, int&, char[4][4]);
void Randomize(char[4][4]);
void Move(char[4][4], const EMove);
void InitializeTestBoard(char[4][4]);
char checkWin(char[4][4], char);
int main() {
char fBoard[4][4];
char mode;
int boardStates;
int depth;
using namespace std;
cout > mode;
int counter = 0;
char isComplete = ' ';
if (mode == 't') //Test Mode
{
InitializeTestBoard(fBoard);
do {
counter++;
PrintBoard(fBoard);
cout > cNextMove;
EMove eNextMove = (EMove)cNextMove;
Move(fBoard, eNextMove);
cout > cNextMove;
EMove eNextMove = (EMove)cNextMove;
Move(fBoard, eNextMove);
cout = 0 && iRowMove = 0 && iColMove < 4) {
fBoard[iRowSpace][iColSpace] = fBoard[iRowMove][iColMove];
fBoard[iRowMove][iColMove] = ' ';
}
}
char checkWin(char fBoard[4][4], char isComplete)
{
const char fInitial[4][4] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'9', 'A', 'B', 'C'},
{'D', 'E', 'F', ' '}
};
for (int i= 0; i < 5; i++)
{
if (fBoard[1][i] == fInitial[1][i] || fBoard[1][i] == fInitial[1][i] || fBoard[1][i] == fInitial[1][i] || fBoard[1][i]
My next step is to implement an Iterative Deepening search on the puzzle to solve it.
I assume you go column by column, row by row with a loop until the checkwin function is complete?
I would really love any pointers or guidance that can be given.
Does not have to be code.
(A is included, as that is the next step of my project to implement IDA)
Here is my Code:
```
#include
#include
enum EMove { keUp = 'w',
keDown = 's',
keLeft = 'a',
keRight = 'd'};
// Function declarations
void InitializeBoard(char[4][4]);
void PrintBoard(char[4][4]);
void LocateSpace(int&, int&, char[4][4]);
void Randomize(char[4][4]);
void Move(char[4][4], const EMove);
void InitializeTestBoard(char[4][4]);
char checkWin(char[4][4], char);
int main() {
char fBoard[4][4];
char mode;
int boardStates;
int depth;
using namespace std;
cout > mode;
int counter = 0;
char isComplete = ' ';
if (mode == 't') //Test Mode
{
InitializeTestBoard(fBoard);
do {
counter++;
PrintBoard(fBoard);
cout > cNextMove;
EMove eNextMove = (EMove)cNextMove;
Move(fBoard, eNextMove);
cout > cNextMove;
EMove eNextMove = (EMove)cNextMove;
Move(fBoard, eNextMove);
cout = 0 && iRowMove = 0 && iColMove < 4) {
fBoard[iRowSpace][iColSpace] = fBoard[iRowMove][iColMove];
fBoard[iRowMove][iColMove] = ' ';
}
}
char checkWin(char fBoard[4][4], char isComplete)
{
const char fInitial[4][4] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'9', 'A', 'B', 'C'},
{'D', 'E', 'F', ' '}
};
for (int i= 0; i < 5; i++)
{
if (fBoard[1][i] == fInitial[1][i] || fBoard[1][i] == fInitial[1][i] || fBoard[1][i] == fInitial[1][i] || fBoard[1][i]
Solution
I see that your using
read this article for more info on it...
http://www.gidnetwork.com/b-61.html
anyway if you replace it with
it has the same effect... it's just a matter of pressing enter to continue
also if you wanted to port this application to unix or mac os x, the system pause wouldn't work: you would get one of those "this command is not recognizable" messages.
so... in conclusion, changing the
also the codes readability might benefit if you put the function implementations in a separate file
hope this helped
system("PAUSE") it works all fine and dandy but behind the scenes it creates some extra overhead that could be avoided using standard c++ callsread this article for more info on it...
http://www.gidnetwork.com/b-61.html
anyway if you replace it with
cin.get();it has the same effect... it's just a matter of pressing enter to continue
also if you wanted to port this application to unix or mac os x, the system pause wouldn't work: you would get one of those "this command is not recognizable" messages.
so... in conclusion, changing the
system('PAUSE')'s to cin.get();'s is the way to goalso the codes readability might benefit if you put the function implementations in a separate file
hope this helped
Context
StackExchange Code Review Q#5942, answer score: 2
Revisions (0)
No revisions yet.