Code:
/*****************************************/
/* */
/* */
/* AI Problem Solving */
/* Created by: */
/* Zachary Carlyon */
/* */
/*****************************************/
//This program is made to run through a problem.
//The problem is your have 6 squares, 3 rows and 2 collumns.
//Inbetween each square and on the outside are streets, with parking meeters in which you must "check". You need to find the quickest route
//Some streets have 2 sides of parking meeters in which you must go through twice to check both sides.
//You cannot go on a street more than once, except for the streets with parking meeters in which you must go through only twice.
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
//int directionfunct(int *x, int *y, int coords[12][13], int *letters, int ans, int cx, int cy, int *j, int answer, int ax, int ay, int attempt);
int directionfunct(int &x, int &y, int coords[][13], int &letters, int ans,int cx, int cy, int j, int answer[12], int ax, int ay, int attempt);
//int startingpoint(int *x, int *y, int attempt);
int startingpoint(int &x,int &y);
int main(int argc, int* argv[])
{
int answer[12];
int coords[12][13];
int letters;
int i,x,y,cx,cy,ax,ay,attempt,ans;
//int *j;
int j;
answer[1] = 1;
cx = 0;
cy = 0;
j = 0;
attempt = 12;
do
{
if(attempt == 12)
{
coords[1][2] = 1;
coords[1][5] = 1;
coords[2][3] = 1;
coords[2][6] = 1;
coords[3][4] = 1;
coords[3][7] = 2;
coords[4][8] = 1;
coords[5][9] = 1;
coords[5][6] = 2;
coords[6][7] = 2;
coords[6][10] = 2;
coords[7][8] = 2;
coords[7][11] = 2;
coords[8][12] =1;
coords[9][10] =1;
coords[10][11] = 1;
coords[11][12] = 1;
}
//startingpoint(&x, &y, attempt);
startingpoint(x, y);
//directionfunct(&x, &y, coords, &letters, ans, cx, cy, j, answer[12], ax, ay, attempt);
directionfunct(x, y, coords, letters, ans, cx, cy, j, answer, ax, ay, attempt);
}while(letters != 12);
for(i = 0;i < 13; i++)
{
printf("%d/n",answer[ans]);
ans++;
}
return 0;
}
//directionfunct() is what makes it keep moving and not move into a space that is already used.
//points[][] is the current point it is at, nextdir[][] is the next point it will move too.
//int directionfunct(int x, int y, int coords[][13], int letters, int ans,int cx, int cy, int j,
//int answer[12], int ax, int ay, int attempt)
int directionfunct(int &x, int &y, int coords[][13], int &letters, int ans,int cx, int cy, int j, int answer[12], int ax, int ay, int attempt)
{
int direction,done;
int points[3][4];
int nextpoint[3][4];
int nextdir;
ans = 0;
x = ax;
y = ay;
done = 1;
points[1][1] = 1;
points[1][2] = 2;
points[1][3] = 3;
points[1][4] = 4;
points[2][1] = 5;
points[2][2] = 6;
points[2][3] = 7;
points[2][4] = 8;
points[3][1] = 9;
points[3][2] = 10;
points[3][3] = 11;
points[3][4] = 12;
nextpoint[1][1] = 1;
nextpoint[1][2] = 2;
nextpoint[1][3] = 3;
nextpoint[1][4] = 4;
nextpoint[2][1] = 5;
nextpoint[2][2] = 6;
nextpoint[2][3] = 7;
nextpoint[2][4] = 8;
nextpoint[3][1] = 9;
nextpoint[3][2] = 10;
nextpoint[3][3] = 11;
nextpoint[3][4] = 12;
if(x == 0 && y == 0)
{
ax = 1;
ay = 1;
return ax, ay;
}
direction = (rand()%4)+1;
while(x !=4)
{
if(direction == 1)
{
x++;
//if(coords[cx][cy] = 0)
if(coords[cx][cy] == 0)
{
x--;
done--;
}
}
}
while(x !=1)
{
if(direction == 2)
{
x--;
//if(coords[cx][cy] = 0)
if(coords[cx][cy] == 0)
{
x++;
done--;
}
}
}
while(y !=1)
{
if(direction == 3)
{
y++;
if(coords[cx][cy] == 0)
{
y--;
done--;
}
}
}
while(y !=3)
{
if(direction == 4)
{
y--;
if(coords[cx][cy] == 0)
{
y++;
done--;
}
}
}
nextdir = (rand()%4+1);
while(ax !=4)
{
if(direction == 1)
{
ax++;
if(coords[cx][cy] == 0)
{
ax--;
done--;
}
}
}
while(ax !=1)
{
if(direction == 2)
{
ax--;
if(coords[cx][cy] == 0)
{
ax++;
done--;
}
}
}
while(ay !=1)
{
if(nextdir == 3)
{
ay++;
if(coords[cx][cy] == 0)
{
ay--;
done--;
}
}
}
while(ay !=3)
{
if(nextdir == 4)
{
ay--;
if(coords[cx][cy] == 0)
{
ay++;
done--;
}
}
}
cx = points[x][y];
cy = nextpoint[ax][ay];
letters++;
ans++;
j = points[x][y];
answer[ans] = j;
letters++;
attempt--;
while(done != 0)
{
coords[cx][cy]--;
}
return x,y,coords[cx][cy];
}
//startingpoint() creates a random starting point;
//int startingpoint(int x,int y, int attempt)
int startingpoint(int &x,int &y)
{
//do
//{
x = (rand()%3)+1;
y = (rand()%4)+1;
//}while(attempt == 12);
//return x,y;
}