How to replace random blocks with a different type of block
I have a student who has a room filled with one type of blocks making the walls. He wants to use the code builder to replace SOME of the blocks with a different kind, and have it be random.
My thought process for the pseudocode: When the word run is entered, replace pick random quartz blocks from coordinate XYZ to XYZ with brick.
I can't figure out the correct sequence of blocks to make this happen, however.
Any help is much appreciated!
-
Hi, Ashley. I'm excited to hear about all of this creative thinking! There are always many ways to accomplish something, so please allow me to ask a few questions. What kind of code have you been using so far? (MakeCode Python? Block code? Python Azure Notebooks? Chat commands?)
I agree that one way to choose blocks is to select them from actual blocks in the world. Another way is to have a list (or array) of block references (like their names or ids.) All of this will depend on what kind of code you are using.
Then the only thing will be how to write the code to choose where to randomly change blocks, and for which random block results.
FWIW my class is currently placing blocks using arrays of blocks. We are selecting the blocks based on a random number when we place them. It's just like building a regular wall, except that when you place the block, you choose which block to place. Your code will kind of go over the wall afterwards and "edit" the wall. Will I change this block? If so, how? At least, that is what seems most sensible from my view.
Let me know how I can help.
0 -
Thanks for the reply! We've been using Makecode. I wasn't sure if it was possible with the blocks, or only possible with written code instead.
0 -
It's possible either way, but you need to have a strategy. Does the agent have access to the whole wall? The have the agent move across the whole wall (use the same code that built the wall, but replace the line of code that places the block with a random number generation, and a conditional statement. If the random number is the desired value, break and replace with the new block, otherwise continue.)
0
Please sign in to leave a comment.
Comments
3 comments