Programming a robot in C++

Hello, I'm back with another question.
I have an assignment that is about programming a robot called Shakey.
Part of the assignment is right here:

"History
Much of this material on Shakey was inspired by Karel the Robot. The definitive source for
information about Karel is the book Karel the Robot, a gentle introduction to the art of programming,
by Richard E. Pattis, second edition with revisions by Jim Roberts and Mark Stehlik, published by
John Wiley and Sons, 1995.
There is also an object-oriented version called Karel++. Karel++ is a C++ like language specifically designed to control robots. Karel and the Karel++ language was the pre-basis research for the Mars
and Lunar robots programs.
The Assignment
In this assignment Shakey will not be required to memorize commands. We will enhance Shakey’s intelligence in the Advance C++ session.
Shakey is a peaceful robot and will not be challenged by the evil dominions of the universe. Shakey does not fly or hover. Shakey is simple robot about the size of R2D2 whom is dependent upon your commands to move about within the enclosed fenced area.

Shakey understands the following six commands:
1. step: When Shakey executes a step instruction, he moves forward one square on his grid,
continuing to face in the same direction as before. Shakey's program will complain if he is ever
directed to step into a wall. He may occupy the same square as an item. He cannot occupy the
same square where there is a wall. The walls are impenetrable immovable objects. Shakey
cannot break through walls.
2. left: Shakey executes a left instruction by pivoting 90° to the left, remaining on the same
square.
3. right: Shakey executes a right instruction by pivoting 90° to the right, remaining on the same
square.
4. pickup: Shakey picks up an item from the square he is standing on. If he executes a pickup
instruction and the square he is standing on does not contain an item, then his program should
issue a warning.
5. drop: Shakey places one item on the currently occupied square. If he is not carrying any
items, or if the current square already contains an item, then his program issue a warning.
6. home: Shakey moves directly to his home position. He does not pass go... he does not collect 200 dollars. (Ordinarily, Shakey's home position is in the upper left hand corner of his grid,
facing north. (0,0))
There is no limit to the number of items that Shakey can carry at one time. Unless otherwise
specified, Shakey is working as a mailman and the objects he drops and picks up could be letters.
These six commands constitute the core of Shakey's language. Later, you will see how to extend the language by using these six commands as building blocks. Because they form the foundation of the
language, they are sometimes called primitives. When a Shakey program is ran, it will accept a sequence of Shakey commands; he performs each command, one after the other, in the order given.
Each command for Shakey should be a function call.
Provide a prompt to the user to issue the basic commands; all command should be lower cased".

I have some of the code that is supposed to be a "garden" for the robot to walk around, but I am not sure how to make it move, turn, drop or pick up things>
Can someone help me?

#include <iostream>
#include <iterator>
using namespace std;
#define X 10
#define Y 10

char garden[X][Y];
void displayGarden();
void initGarden();
int printMenu();
int a;
int x, y;

int main()
{
initGarden();
do
{
a = printMenu();
switch(a)
{
case 1: displayGarden();
cout << "Shakey is at home!" << endl;
case 2:
break;
default:
cout << endl;
}
} while(a != 0);
}
void initGarden()
{
x , y = 0;
for(int i=0; i < X; i++)
for(int j=0; j < Y; j++)
garden[i][j] = '=';
}
void displayGarden()
{
char current;
for(int i=0; i < X; i++)
for(int j=0; j < Y; j++)
{
if(j == 0)
{
cout << "||";
}
if(i == x && j == y)
{
cout << "S";
}
else
{
cout << garden[i][j];
}
if(j == 4)
{
cout << "||" << endl;
}
}
}
int printMenu()
{
int answer;
cout << endl;
cout << "Please Choose A Number: " << endl << endl;
cout << " 1: Display Garden" << endl;
cout << " 2: Move Right By One" << endl;
cout << " 3: Move Left By One" << endl;
cout << " 4: Move Down By One" << endl;
cout << " 5: Move Up By One" << endl;
cout << " 6: Turn 360 Degrees" << endl;
cout << " 7: Pick Up Item" << endl;
cout << " 8: Drop Item" << endl;
cout << " 0: Exit" << endl;
cout << endl;
cout << "You Chose: ";
cin >> answer;
cout << endl;
return answer;
}
I created a similar project in a class I had, except it was a racetrack and the robots were cars, and we used SDL, but it is the same basic concept, so you can look at it and see how I made the robots move and interact with their environment. Go to this link to look at the source code if you want.
https://fossil.cs.sunyit.edu/cgi-bin/fossil/2014_fall___miniat_racer/index

The code is unfinished, but it works and the robots move forward or backward and turn left or right.

They didn't have to pick anything up though. For that, I would probably create an "object" object and give a boolean value for isPickedUp. Then when you make the robot move, check that boolean value of the object and make it move if isPickedUp is true. And for dropped just set isPickedUp to false.
Topic archived. No new replies allowed.