Robot tracing program for CS Principles

Hi folks!

We working to create an AP CS Principles course based on MakeCode Arcade. In one of the units of this course, students need to complete a bunch of Robot Tracing exercises like this:

The Robot is represented as a triangle, the grid is a 7 x 7 matrix, and there are only 3 functions - Move Forward (1), Turn Right, and Turn Left.

If anyone has some time, I would be eternally grateful if you want to try implementing this in MakeCode Arcade (maybe as an extension with custom blocks?) Would love to include it in the CSP course!

  • Jacqueline
4 Likes

What is this:
image
and this:
image
supposed to do?

1 Like

n = 1 and n = n +1
it’s just the weird notation that the CS Principles course uses to try and be language agnostic…

2 Likes

Seemed like a fun project. I put together a very simple implementation over lunch:

You’ll notice there’s a new RoboDrawing category that has the three blocks you mentioned plus a reset function (which is also required to initialize the sprite and grid).

Right now the sprite just follows instructions blindly; it doesn’t verify that it doesn’t move outside the bounds of the grid or anything…

… also I didn’t spend much time coming up with good names for the blocks or adding documentation.

Feel free to modify/improve the code any way you like.

4 Likes

Wow!!! Jacob, I love this, it’s perfect! Thanks so much for doing this. Will get this included in the course curriculum - lots of kids will be playing this! Do you want me to add a credit/link to you below the game?

3 Likes

Ha. :blush:

No, no credit necessary. Glad to hear it might be useful!

2 Likes

Hey Jacob,
Quick question - would it be possible for the Reset function to take a coordinate value? So students could place the robot on any of the tiles?

1 Like

@jacqueline.russell I was interested in seeing some additional exercises of this type, so I hunted around a bit. I found a few in this code.org curriculum: https://curriculum.code.org/csp-20/unit5/5/.

Those examples appear to use a different grid size, starting location for the robot, and starting orientation of the robot. (It also looks like there may be obstacles and an additional conditional instruction later on…)

Do any of your curriculum’s exercises involve different grid sizes or starting configurations (position/orientation)?

Ha; yes. I just posted this as a question but it’s awaiting moderation. :sweat_smile:

@jacqueline.russell Here is an update to the robot drawing with the ability to customize the starting location and direction:

I also started doing some questionable things in the design of the JavaScript API to enable a blocks convenience: the turn blocks now allow you to pick the other turn direction with a drop-down. (I wanted it to work kind of like the Math operators, where +, -, ✖️ and ➗ are all listed, but if you pick the wrong one, you can swap over to another.)

… but I really don’t like the JS that it creates. Is it a priority that the generated JS be reasonable? Will the students be looking at that code?

I can roll back that change if it’d be better to force them to swap blocks to change turning directions.

2 Likes

Wow! Even better Jacob! This is perfect! No, students won’t be looking at the JavaScript - it’s all going to be block-based, so no worries there. Thank you so much!!!

1 Like

We’ve built a similar project for hour of code campaign( but no i18n (yet)), same purpose with some features for new coders.
a) Navigating mode, in which students can navigate levels and draw flowcharts on paper or planning their programs (simulator automatically restart after changes detected)
b) Summary after running all levels;
c) Barriers like walls / boulders, context for introducing conditionals (if…then…)

Extension instructions:

4 Likes

Oh Wow! Looks very slick!

Good morning!

This MakeCode extension is great! However, the AP Computer Science Principles curriculum has one more function that goes along with these three basic robot movement commands. It is: CAN_MOVE(direction). The direction argument can be left, right, forward, or backward. All 4 functions are used on a grid that is a variable size and has open squares (white), blocked off squares (black) and a goal square (gray).
Example grid and code:

REPEAT UNTIL (Goal_Reached ())
{
IF (CAN_MOVE (right))
{
ROTATE_RIGHT ()
}
ELSE
{
IF (CAN_MOVE (left) )
{
ROTATE_LEFT ()
}
}
IF (CAN_MOVE (forward) )
{
MOVE_FORWARD ()
}
}

I copied your repository and tried to change it to add the function and have a way to modify the grid size and change the squares to different types. I gave up after a while. :melting_face: Any suggestions on how to make this possible?

Thanks!

1 Like

@jacob_c’s last post was in 2021, so you probably won’t get a response, but I could probably take a stab at it!

1 Like

We’ve actually updated this extension since Jacob’s original. Sample project: https://makecode.com/_Lh7DWVW4mYzk, and extension here: https://github.com/riknoll/arcade-robot-csp. This new one does have some advanced blocks where you can set obstacles and check whether the robot can move to a space -

1 Like

I have “Robo can move [relative direction]” (forward, left, etc) working so I’ll post that soon. I’ve added a lot more blocks too!

Ok! Here it is:

You can import it by putting that link into the extensions search bar or by searching WoofWoofCodes/pxt-robo
Here is a small example project:

As you can see in the code, there are a few new blocks. Most are self explanatory. When creating a grid with walls using the “set grid image (image)” block, placing the color green will place a goal tile, and any other color will place a wall.
If you have any questions, don’t hesitate to ask! I can always edit the extension.

1 Like

Oh wow!!! Super cool extension - love it :heart: Thanks for providing this @WoofWoof !

1 Like