daniel.moore.5099940 0 Newbie Poster

Hey everyone, i need help with this program im doing for a class, now i havent used c++ in a while so thats why im considerably fresh in all this. any at all help would be greatly apprecietated. ALso i can NOT spell to save my life.

the problem states this much

 Write a program to solve the 8-Tiles Puzzle using the best first search algorithm. You need to compare between using the following heuristics to estimate the distance to the goal:
 h1= 0 (this will be the breadth first search)
 h2= number of misplaced tiles
 h3= sum of distances heuristic

 Your program will prompt the user to enter a starting state (you can use the number zero to represent the blank).

 The output of your program will show the required movements to reach the goal state, the total number of states in the search, and the path length.

 Test your program on the following two starting states:

 For each heuristic on each of the above test states, determine:
 T: total number of states in the search.
 L: path length.

starting state 1
2 8 3
1 6 4
7 0 5

starting state 2
2 8 1
4 6 3
0 7 5

goal state
1 2 3
8 0 4
7 6 5

Heres some of my code so far, and yes i already know it looks bad, just need some help working with 2d arrays and handling some of this in functions.
if anyone could give me examples on how to fix the code that would be greatly appreciated too.

#include <iostream>
#include <iomanip>
#include <array>

using namespace std;

void printarray(int[3][3] num)
{
    for(int i = 0;i < 3; i++)
    {
        for(int j = 0; j< 3; j++)
        {
            cout << num[i][j];
        }
    }
}

class Puzzle
{
private:
    int state1[3][3] = {{2, 8, 3}, {1, 6, 4}, {7, 0, 5}};
    int state2[3][3] = {{2, 8, 1}, {4, 6, 3}, {0, 7, 5}};
    int gstate[3][3] = {{1,2,3}, {8, 0, 4}, {7, 6, 5}};
    char up = 'u';
    char down = 'd';
    char left = 'l';
    char right = 'r';
public:
    Puzzle();
    char changestate();
    void printarray();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.