Help with "move in this square" block

hello. I am trying to make the "move in this square" block in Unit 5 lab 6, where you are tasked to switch a vacant square then broadcast that square number. I have tried but I am so confused how to get the tile to automatically switch the costume as well as broadcasting that square. This is what I have so far:

Hi, welcome to the forum!

You're not doing so badly, except for slightly misreading the directions. You say "switch to a vacant square then broadcast that square number." But if you look at the block picture in step 3, you see this:
when-receive-move
This script responds to a broadcast message. So, the broadcast has already happened before MOVE IN THIS SQUARE is called.

One bug: As I said before, the block


doesn't belong here. But when you do use it, it can't just broadcast a randomly chosen board position; it has to choose a random empty square.

Try not to get so bogged down in the coding details that you lose the big picture. The structure of the program relies on scripts in each clone. You already have the sprites positioned on the board, so when the user clicks somewhere in the board you know which square they're trying to play in. So the overall structure is

  1. Notice that the user has clicked on a square.
  2. If the square is free, change the sprite's costume and update the board.
  3. Check for win or tie.

If the computer strategy "clicks on" a square by broadcasting its number, you have to do this:

  1. Notice that the computer has "clicked" this square.
  2. If the square is free, change the sprite's costume and update the board.
  3. Check for win or tie.

This is pretty similar, right? It's just the first step that's different between the two cases. When you have two almost-the-same chunks of code in your project, you take out the common parts and put them in a procedure. So MOVE IN THIS SQUARE has to do steps 2 and 3 of this process.

You might feel like it shouldn't be that easy, there must be something missing. And there is; this script doesn't do the hard part, namely, decide which square the computer should pick. In the next two lab pages (3 and 4) you'll write a block NEXT MOVE FOR COMPUTER to do that.

You could improve your script by noting that the two branches of the IF (X'S TURN) are almost the same, and write a helper block that takes X or O as input.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.