Hey,

I've developed a 8puzzle solver using a fixed width and height

Below is my input condition and the pre-set goal state which i use for testing.

Assume initstate and endstate have been defined as two dimensional arrays with dimensions[3][3].Code:for (i = 0; i < 9; i++) cin >> initstate[i/3][i%3]; for (i = 0; i < 9 ; i++){ if (i != 8){ endstate[i/3][i%3] = i+1; }else { endstate[i/3][i%3] = 0; }

I've used a-star search to find the shortest path f(n) = h(n) + g(n)

A couple of questions

1. How do i go about getting the input from a text file ?

Yes i am familiar with fstream and getline but

for example if the text file is such:

4

4

1@(3,1) 6@(3,3) 0@(1,2) etc upto 16 values

1@(1,1) 2@(1,2) 3@(1,3) etc upto 16 values

In this case the first line denotes its Height, second line its Width

third line its initial state and fourth line its goal state.

Also if the input is put into a hashtable(if someone suggests)

do the parameters given such as (3,1) (3,3) which are the position

values of each of the pre-fix'd numbers "1" @(3,1)

if Not then what sort of string strip/trim is required and how do

you specify delimiters with @(can be any number, can be anynumber)

2. Equally large problem im facing is how do i use the input Height, Width info from the text file to define/initialise my node & priority queue ? Currently they are all pre-set to function for a 3x3. I want to attempt a 4x4 & 5x3. Basically the size of the board, goal array need to be set at runtime.

3. I've tried substituting certain fixed values such as 3, with 4

and 9 with 16 in for loops and the respective i/dimension, i%dimension cases and the possible number of states 9factorial/8bits replaced by 16!factorial/15 bits respectively where it's required in the program and the base table (multiples of 9 or 16)

Where am i going wrong ? what functions for a 3x3 should do the same for 4x4 with appropriately replaced values yes ? I was wondering if parity needs to be used if so then how ? I know the basic parity function.

I've tried various test cases for the 3x3 and it performs perfectly.

I've also seen a code online which uses template metamorphing but i cant quite get the hang of it (it works for a set dimension value, 4x4)

Below is some sample code which gives an idea of my problem

If you require any further code to understand my question better, let me know.Code:`// My header file -> class node {private: // functions omitted public: node(valNum board[3][3]); //valnum can be double or valNum nodeBoard[3][3]; //unsigned short/long int // other functions omitted }; class Pqueue { private: // code omitted valNum startState[3][3]; //3x3 i need dynamic 5x3/4x4 char stateChecked[45360]; //9factorial/8bits public: Pqueue(valNum begin[3][3], valNum end[3][3]); ~Pqueue(); // code omitted }; void Pqueue::doOpen(node *posn) { // code omitted //marks position as visited stateChecked[pos/8] = stateChecked[pos/8] | check; }`