I'm a beginning CS student and would love for some help checking REALLY SIMPLY pseudo-code. Would you use a function? How would I write it?
Here is the problem:
Write an algorithm for playing a robotic version of the "treasure hunt" game. The game involves robots receiving clues that guide them to other clues until they eventually reach a "treasure".
Clues are represented by colors of tiles and each clue just requires the robot to move one tile in a direction (left, right, forward). After making a move, the robot re-examines the color of the tile it is standing on to figure out the next move, etc.
The rules for the tile colors are:
- White tile = next clue is the tile directly in front of the robot
- Blue tile = next clue is the tile to the robot's left
- Green tile = next clue is the tile to the robot's right
- Black tile = robot moves back TWO tiles then re-examines clues based on its new heading
- Yellow tile = treasure and game is over
The algorithm rules:
- The robot can only move forward, turn left, or turn right
- The robot is able to read the color of the tile it is standing on
Here is my pseudo-code:
//assign movements and actions to variables
whiteTile = step forward one space
blueTile = turn left and step forward one space
greenTile = turn right and step forward one space
blackTile = step backwards two spaces without changing directions
yellowTile = treasure found and game over
tileColor = check color of tile
//initiate while loop to run continously until robot reaches yellow tile
While tile under feet does not equal yellowTile
// initiates the movements of the robot to start if loop
Check color of tile
// this if loop should run continously as long as tileColor isn’t yellow
if tile color does not equal yellowTile
output(tileColor)
check color of tile
// once robot is on top of yellow tile, it exits the while loop and game is over
output “Game over, you win!”
Aucun commentaire:
Enregistrer un commentaire