I have this feeling the code I'm working on below won't be noticed for what it is. It's probably as good as telling you how it works. It guesses, then once it gets acceleration sense it will save guessed actions and are linked to saved sense, then sensing acceleration again matches mem sense linking to actions to initiate, it crawls forward, into wall, after a while body gives pain which links to actions&sense in latest memory, then this stops actions since neg senses label actions as -, then it guesses and turns around from wall, eventually so much pain it stops totaly, enough to get lots of energy and go right back to crawl actions initiated once see open space, then when sees next wall it matches mem of wall which links to neg labeled actions and links to good turn around, ends up different places since room isnt total open square walled nor where it went in its direction ex crawled at angle, now by pain again or repeatitive sense/action it goes to guess mode and deviates off maybe by new saved crawl actions but without the sammmme sense it was getting that was repetitive, it now crawls the house avoiding walls.
Code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <ctime>
using namespace std;
static int x = 0;
static int y = 0;
int legnum(int legnumber)
{
if (legnumber < 2000)
return 1;
else if (legnumber < 15800)
return 2;
else if (legnumber < 45000)
return 3;
else if (legnumber < 60000)
return 4;
}
int legs(int leg)
{
static int doItAgain = 0;
++doItAgain;
if (doItAgain == 5)
doItAgain = doItAgain - 4;
if (doItAgain == 1)
cout << "leg 1 ";
else if (doItAgain == 2)
cout << "leg 2 ";
else if (doItAgain == 3)
cout << "leg 3 ";
else if (doItAgain == 4)
cout << "leg 4 ";
if (leg < 2000)
cout << "moved left" << endl;
else if (leg < 15800)
cout << "moved forward" << endl;
else if (leg < 45000)
cout << "moved backward" << endl;
else if (leg < 60000)
cout << "moved right" << endl;
return 0;
}
int main()
{
tryAgain:
srand( time(0));
int guess1 = rand();
int guess2 = rand();
int guess3 = rand();
int guess4 = rand();
int leg1 = guess1;
int leg2 = guess2;
int leg3 = guess3;
int leg4 = guess4;
leg1 = legnum(leg1);
leg2 = legnum(leg2);
leg3 = legnum(leg3);
leg4 = legnum(leg4);
legs(guess1);
legs(guess2);
legs(guess3);
legs(guess4);
if (x == 8 && leg2 == 4)
goto tryAgain;
if (x == -8 && leg2 == 1)
goto tryAgain;
if (y == 8 && leg2 == 2)
goto tryAgain;
if (y == -8 && leg2 == 3)
goto tryAgain;
if (leg2 == leg3 && leg2 == leg4)
cout << "Robot moved forward and got acceleration sense by accelometer, which is the trigger to save actions just guessed. The sense instantly matches a close match in memory and links to and initiates the saved actions, +labeled actions are done." << endl;
else
goto tryAgain;
again:
if (leg2 == 1)
x = --x;
else if (leg2 == 2)
y = ++y;
else if (leg2 == 3)
y = --y;
else if (leg2 == 4)
x = ++x;
cout << "Currently at tile " << x << " " << y << "." << endl;
if (x == 8 || x == -8 || y == 8 || y == -8)
cout << "Robot gently walks into wall. After a while has passed, its body sends pain, and it goes to guess mode" << endl;
if (x == 8 || x == -8 || y == 8 || y == -8)
{
cout << "Enter a number to continue." << endl;
int CONTINUE;
cin >> CONTINUE;
}
if (x == 8 || x == -8 || y == 8 || y == -8)
goto tryAgain;
cout << "Enter a number to continue." << endl;
int CONTINUE2;
cin >> CONTINUE2;
cout << "Robot moved forward again" << endl;
goto again;
goto tryAgain;
return 0;
}