Algorithm help? :)
I am trying to write an algorithm where my robot can shift piles of beepers on the first row over one column. (disregard the second row, it is only there to serve as reference.)
Could anyone give me an idea of how this can be done please?
I understand that I would have to count the number of beepers on each pile and somehow keep track of them to move them over?
What's the exact way of moving? Is that a pile can move one column at a time to any direction?
You are moving to the East :)
So you are pushing each pile of beepers one tile to the right.
I have managed to achieve this task using 10 different variables (one for each row) since the grid is 10 by 10.
The steps are:
1. picks up and counts beepers in first column, assigns the number to variable "a"
2. moves to the second column
3. picks up and counts beepers in second column, assigns the number to variable "b"
4. drops the "a" amount of beepers in the second column
5. moves to the third column
6. picks up and counts beepers in the third column, assigns the number to variable "c"
7. drops the "b" amount of beepers in the third column.
...and so forth.
This way seems pretty tedious though, since I had to assign 10 different variables for each of the columns.
Are there any other ways? or are there any ways to reset each variable to zero so I can loop this instead of repeating the same steps over and over?
But in both figures you are in the same place, only the direction of it changed..
The picture shows the "Before" and "After" stages of the program.
Our main purpose is to push the "beepers" or those black dots with numbers (indicating how many of them are in a pile) on them, one tile to the right.
As you can see, in the first figure, the first and second row of beepers are aligned.
In the second figure, the robot have successfully moved the first row of beepers to the right (hence, the un-alignment). And returned to (1, 1)
As you said defining many variables is not a good idea. It assign you to do lots of work.
Originally Posted by Mirix
Can't we something like this, keep the record of each piles as a coordinate value, in a map or something relevant collection. Then you've use the x,y coordinate again to access the info.