This is an path finding algorithm that I did a while back that was not A*, I currently use A* but this algorithm make more logical sense. The algorithm I demonstrated to high school kids because they didn't understand A*. This is more like the weighted node path finding algorithm. Basically this algorithm you make a vector that list that finds the path by following walls. Using the left hand rule that if you put you hand on a wall of a maze you will eventually find the end, but I also but weights on places already visited so it is less likely that it will choose the same node twice. This is a good algorithm if it is a maze like structure game. With not very many open spaces that the can be visited. So I used different collars of tiles to show the progress of the algorithm being solved. A* is still the best algorithm hands down.
Notes press enter to view progress of the node
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "AMAZEHEADER.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
initvector();
readfile("maze.txt");
//resizevector(10,8);
//printvec();
//findsol();
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
bool loop=true;
int turn=90;
// our main loop
dbPositionCamera ( 0, 0, 0 );
while ( LoopGDK ( ) )
{
if(dbReturnKey())
{
findsol();
dbWait(500);
}
dbXRotateCamera(0);
// dbPositionCamera ( 0, 0, 0 );
//dbYRotateCamera(turn);
//dbMakeObjectBox(1,10,10,10);
//dbPositionObject(1,0,0,10);
printvec();
if(dbEscapeKey())
{ break;
}
// move the camera forwards
if ( dbUpKey ( ) )
dbMoveCamera ( 1 );
// move the camera backwards
if ( dbDownKey ( ) )
dbMoveCamera ( -1 );
if(dbLeftKey())
{
// turn=turn+90;
//dbWait(100);
dbTurnCameraRight(-1);
turn=turn-1;
//dbMoveCamera ( 1 );
}
if(dbRightKey())
{
dbTurnCameraRight(1);
turn=turn+1;
//dbWait(100);
//dbMoveCamera ( 1 );
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}
#include<iostream>
#include<fstream>
#include<string>
#include<list>
#include<vector>
#include "AMAZEHEADER.h"
#include "DarkGDK.h"
using std::vector;
using namespace std;
struct PATH
{
bool north;
bool east;
bool south;
bool west;
int x;
int y;
};
PATH apath;
list<PATH> pathlist;
list<PATH>::iterator pathiter;
class AVectorclass
{
public:
AVectorclass();
void setvalueof(int xpos,int ypos, int data);
void readfile(string afile);
void printvec();
void thesolution();
private:
void parsethelist();
void resizevector(int x,int y);
void findsolution();
int height;
int width;
vector<vector<int>> myvector;
//////start and end////
int startx;
int starty;
int endx;
int endy;
///current pos////
int curx;
int cury;
int dirgo;
int dirofwallx;
int dirofwally;
////list///
list<string> aveclist;
list<string>::iterator aveciter;
//int imgid;
int imgid;
};
void AVectorclass::findsolution()
{
/*
if(dirofwally==0)
{
cury=cury+dirgo;
}
if(dirofwallx==0)
{
//myvector[xcurx][cury]=myvector[xcurx][cury]+50;
curx=curx+dirgo;
}
if(myvector[curx][cury+dirofwally]==101)
{
dirofwally=dirofwally;
}
else if(myvector[curx][cury+dirofwally]==0)
{
//myvector[xcurx][
cury=cury+dirofwally;
if(myvector[curx][cury+dirofwally]+myvector[curx+1][cury]+myvector[curx-1][cury]>=300)
{
myvector[curx][cury]=100;
cury=cury-dirofwally;
}
else if(myvector[curx][cury+dirofwally]==100)
{
}
else
{
dirofwallx=dirofwally*-1;
dirofwally=0;
if(dirofwallx==-1)
{
dirgo=1;
}
else
{
dirgo=-1;
}
}
}*/
}
void AVectorclass::thesolution()
{
//cout<<curx<<","<<cury<<endl;
// printvec();
//system("pause");
apath.north=true;
apath.east=true;
apath.south=true;
apath.west=true;
if(myvector[curx][cury-1]==-2)
{
myvector[curx][cury]=myvector[curx][cury]+1;
//cout <<"found solution"<<endl;
apath.north=true;
apath.x=curx;
apath.y=cury+1;
pathlist.push_back(apath);
printvec();
return;
}
else if(myvector[curx][cury+1]==-2)
{
myvector[curx][cury]=myvector[curx][cury]+1;
//cout <<"found solution"<<endl;
apath.north=true;
apath.x=curx;
apath.y=cury+1;
pathlist.push_back(apath);
printvec();
return;
}
else if(myvector[curx+1][cury]==-2)
{
myvector[curx][cury]=myvector[curx][cury]+1;
// cout <<"found solution"<<endl;
apath.north=true;
apath.x=curx+1;
apath.y=cury;
pathlist.push_back(apath);
printvec();
return;
}
else if(myvector[curx-1][cury]==-2)
{
myvector[curx][cury]=myvector[curx][cury]+1;
// cout <<"found solution"<<endl;
apath.north=true;
apath.x=curx-1;
apath.y=cury;
pathlist.push_back(apath);
printvec();
return;
}
else if(myvector[curx][cury-1]+myvector[curx][cury+1]+myvector[curx+1][cury]+myvector[curx-1][cury]>=300&&myvector[curx][cury]!=-1||myvector[curx][cury]>=3)
{
myvector[curx][cury]=100;
list<PATH>::iterator tempp;
pathlist.pop_back();
tempp=pathlist.end();
tempp--;
apath=*tempp;
curx=apath.x;
cury=apath.y;
//thesolution();
}
else if(myvector[curx][cury-1]==0&&myvector[curx][cury-1]!=-1)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
cury--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx+1][cury]==0&&myvector[curx+1][cury]!=-1)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx++;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.south&&!apath.east)
{
myvector[curx][cury]=100;
curx--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury+1]==0&&myvector[curx][cury+1]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
if(myvector[curx][cury]!=-1)
{
cury++;
}
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx-1][cury]==0&&myvector[curx-1][cury]!=-1)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.south)
{
myvector[curx][cury]=100;
curx++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury-1]==1&&myvector[curx][cury-1]!=-1)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
cury--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx+1][cury]==1&&myvector[curx+1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx++;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.south&&!apath.east)
{
myvector[curx][cury]=100;
curx--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury+1]==1&&myvector[curx][cury+1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
myvector[curx][cury]=myvector[curx][cury]+1;
if(myvector[curx][cury]!=-1)
{
cury++;
}
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx-1][cury]==1&&myvector[curx-1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.south)
{
myvector[curx][cury]=100;
curx++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury-1]==2&&myvector[curx][cury-1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
cury--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx+1][cury]==2&&myvector[curx+1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
//cout <<"n";
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx++;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.south&&!apath.east)
{
myvector[curx][cury]=100;
curx--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury+1]==2&&myvector[curx][cury+1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
myvector[curx][cury]=myvector[curx][cury]+1;
if(myvector[curx][cury]!=-1)
{
cury++;
}
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx-1][cury]==2&&myvector[curx-1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.south)
{
myvector[curx][cury]=100;
curx++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury-1]==3&&myvector[curx][cury-1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
cury--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx+1][cury]==3&&myvector[curx+1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx++;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.south&&!apath.east)
{
myvector[curx][cury]=100;
curx--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury+1]==3&&myvector[curx][cury+1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
myvector[curx][cury]=myvector[curx][cury]+1;
if(myvector[curx][cury]!=-1)
{
cury++;
}
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx-1][cury]==3&&myvector[curx-1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.south)
{
myvector[curx][cury]=100;
curx++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury-1]==4&&myvector[curx][cury-1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
cury--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx+1][cury]==4&&myvector[curx+1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx++;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.south&&!apath.east)
{
myvector[curx][cury]=100;
curx--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx][cury+1]==4&&myvector[curx][cury+1]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
myvector[curx][cury]=myvector[curx][cury]+1;
if(myvector[curx][cury]!=-1)
{
cury++;
}
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.north=false;
}
if(myvector[curx+1][cury]>=100)
{
apath.east=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.east)
{
myvector[curx][cury]=100;
cury--;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
else if(myvector[curx-1][cury]==4&&myvector[curx-1][cury]!=-1
&&(myvector[curx][cury]*100+myvector[curx][cury-1]+
myvector[curx][cury+1]+myvector[curx-1][cury]+myvector[curx+1][cury])<=500)
{
if(myvector[curx][cury]!=-1)
{
myvector[curx][cury]=myvector[curx][cury]+1;
}
curx--;
if(myvector[curx][cury]==-2)
{
//cout <<"found solution";
}
if(myvector[curx][cury+1]>=100)
{
apath.south=false;
}
if(myvector[curx-1][cury]>=100)
{
apath.west=false;
}
if(myvector[curx][cury-1]>=100)
{
apath.north=false;
}
apath.x=curx;
apath.y=cury;
pathlist.push_back(apath);
if(!apath.north&&!apath.west&&!apath.south)
{
myvector[curx][cury]=100;
curx++;
pathlist.pop_back();
}
//thesolution();
//else if(!apath.north
}
//else
//{
/* myvector[curx][cury]=100;
list<PATH>::iterator tempp;
tempp=pathlist.end();
tempp--;
apath=*tempp;
if(myvector[curx][cury]*100+myvector[curx+1][cury]+myvector[curx-1][cury]+myvector[curx][cury-1]+myvector[curx][cury+1]>=500)
{
curx=apath.x;
cury=apath.y;
pathlist.pop_back();
//thesolution();
}
else
{
cout<<"did not find solution";
}*/
//}
//if(myvector[curx][cury-1]==0)
/*
if(myvector[curx+1][cury]+myvector[curx-1][cury]+myvector[curx][cury+1]+myvector[curx][cury-1]>=400)
{
cout <<"no solution";
return;
}
while(myvector[curx+1][cury]+myvector[curx-1][cury]+myvector[curx][cury+1]+myvector[curx][cury-1]==0)
{
cury=cury-1;
starty=starty-1;
myvector[curx][cury]=0;
myvector[curx][cury-1]=-1;
}
while(myvector[xx+1][yy]+myvector[xx-1][yy]+myvector[xx][yy+1]+myvector[xx][yy-1]==0)
{
cury=cury+1;
endy=endy+1;
myvector[curx][cury]=0;
myvector[curx][cury+1]=-1;
}
if(myvector[xx-1][yy]==100&&myvector[xx][yy+1]==0)
{
dirofwallx=-1;
dirofwally=0;
dirgo=1;
}
else if(myvector[xx+1][yy]==100&&myvector[xx][yy-1]==0)
{
dirofwallx=1;
dirofwally=0;
dirgo=-1;
}
else if(myvector[xx-1][yy]==0&&myvector[xx][yy-1]==100)
{
dirofwallx=0;
dirofwally=-1;
dirgo=-1;
}
else if(myvector[xx+1][yy]==0&&myvector[xx][yy+1]==100)
{
dirofwallx=0;
dirofwally=1;
dirgo=1;
}
//if
else
{
findsolution();
}*/
}
void AVectorclass::parsethelist()
{
string temp;
int xcnt=0;
int ycnt=0;
aveciter=aveclist.begin();
while(aveciter!=aveclist.end())
{
xcnt=0;
temp=*aveciter;
while(temp[xcnt]!='\0')
{
if(temp[xcnt]=='1')
{
myvector[xcnt+1][ycnt+1]=101;
}
if(temp[xcnt]=='0')
{
myvector[xcnt+1][ycnt+1]=0;
}
if(temp[xcnt]=='s')
{
startx=xcnt+1;
starty=ycnt+1;
curx=startx;
cury=starty;
myvector[xcnt+1][ycnt+1]=-1;
}
if(temp[xcnt]=='e')
{
endx=xcnt+1;
endy=ycnt+1;
myvector[xcnt+1][ycnt+1]=-2;
}
xcnt++;
}
ycnt++;
aveciter++;
}
if(myvector[startx][starty+1]==101)
{
apath.north=false;
}
if(myvector[startx][starty-1]==101)
{
apath.south=false;
}
if(myvector[startx+1][starty]==101)
{
apath.east=false;
}
if(myvector[startx][starty+1]==101)
{
apath.west=false;
}
if(!apath.east&&!apath.west&&!apath.north&&!apath.south)
{
//cout<<"no solution";
}
else{
apath.x=startx;
apath.y=starty;
pathlist.push_front(apath);
pathiter=pathlist.begin();
}
//apath.east
}
void AVectorclass::readfile(string afile)
{
string tstr;
int xcnt=0;
int ysize=0;
int lengthofstr=0;
ifstream thefile(afile.c_str());
while(!thefile.eof())
{
xcnt=0;
getline(thefile,tstr);
if(tstr.length()>lengthofstr)
{
lengthofstr=tstr.length();
}
tstr=tstr+"\0";
aveclist.push_back(tstr);
ysize++;
/* while(tstr[xcnt]!='\0')
{
cout <<tstr[xcnt];
if(tstr[xcnt]=='s')
{
startx=xcnt;
starty=ysize;
}
if(tstr[xcnt]=='e')
{
endx=xcnt;
endy=ysize;
}
}
ysize++;*/
}
height=ysize;
width=lengthofstr;
resizevector(lengthofstr,ysize);
parsethelist();
thefile.close();
}
AVectorclass::AVectorclass()
{
myvector.resize(1);
myvector[0].resize(1);
height=1;
width=1;
startx=0;
starty=0;
endx=0;
endy=0;
apath.north=true;
apath.east=true;
apath.south=true;
apath.west=true;
imgid=0;
dbLoadImage("Greentile.bmp",1);
dbLoadImage("Bluetile.bmp",2);
dbLoadImage("Yellowtile.bmp",3);
dbLoadImage("Redtile.bmp",4);
dbLoadImage("Whitetile.bmp",5);
dbLoadImage("Bricktile.bmp",6);
dbLoadImage("Starttile.bmp",7);
dbLoadImage("Endtile.bmp",8);
}
void AVectorclass::printvec()
{
imgid=0;
/*imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,0,-5,0);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,0,5,0);
dbTextureObject(1,1);
dbTextureObject(2,1);*/
//dbMakeObjectBox(1,10,10,10);
//dbPositionObject(1,0,0,10);
//cout<<"in";
for(int y=0;y<height;y++)
{
for(int x=0;x<width;x++)
{
switch(myvector[x][y])
{
case 100:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,5);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,5);
//cout<<"o";
break;
}
case 101:
{
imgid++;
dbMakeObjectBox(imgid,10,10,10);
dbPositionObject(imgid,y*10,0,x*10);
dbGhostObjectOn(imgid);
//dbTextureObject(imgid,1);
//cout<<"w";
break;
}
case 0:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,1);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,1);
//cout<<"0";
break;
}
case 1:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,2);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,2);
//cout<<"1";
break;
}
case 2:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,3);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,3);
//cout<<"2";
break;
}
case 3:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,4);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,4);
//cout<<"3";
break;
}
case 4:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,5);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,5);
//cout <<"4";
break;
}
case -1:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,7);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,7);
//cout<<"s";
break;
}
case -2:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,8);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,8);
//cout<<"e";
break;
}
default:
{
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,-5,x*10);
dbTextureObject(imgid,2);
imgid++;
dbMakeObjectBox(imgid,10,.1,10);
dbPositionObject(imgid,y*10,5,x*10);
dbTextureObject(imgid,2);
}
}
}
// cout <<endl;
}
// cout<<"out";
}
void AVectorclass::resizevector(int x,int y)
{
x=x+2;
y=y+2;
int xc=0;
if(x>0&&y>0)
{
//cout<<y<<","<<x<<",";
myvector.resize(x);
for(int yc=0;yc<x;yc++)
{
myvector[yc].resize(y);
xc++;
}
height=y;
width=x;
}
for(xc=0;xc<height;xc++)
{
myvector[0][xc]=101;
}
for(xc=0;xc<width;xc++)
{
myvector[xc][0]=101;
}
for(xc=0;xc<height;xc++)
{
myvector[width-1][xc]=101;
}
for(xc=0;xc<width;xc++)
{
myvector[xc][height-1]=101;
}
// cout<<xc;
}
void AVectorclass::setvalueof(int xpos,int ypos, int data)
{
if(ypos>=height||xpos>=height)
{
return;
}
else
{
myvector[xpos][ypos]=data;
}
}
AVectorclass *avc;
void initvector()
{
avc=new AVectorclass();
}
void setvalueof(int xpos,int ypos,int data)
{
avc->setvalueof(xpos+1,ypos+1,data);
}
void printvec()
{
avc->printvec();
}
void readfile(string astr)
{
avc->readfile(astr);
}
void findsol()
{
avc->thesolution();
}
Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.