Tower of Hanoi. Looking for a simple way to add game constraints

Hi all. I’m working on an example minigame for Year 7 students…

It works, if you play by the rules, but it’s a computer game, so it needs constraints. I need to make it so that you can’t pick a lower disk and that you can’t stack a larger disk onto a smaller disk. A condition to check when the game has been won would also be nice.

I know that this isn’t much more difficult than a first year CS assignment, and I could probably solve it with arrays, or by taking advantage of TypeScript object properties (like size, etc) but I’m trying to keep my examples simple and easy for a Year 7 with no programming experience to understand.

Just looking for ideas! If you have suggestions, please throw them my way!

Kind regards,

@sety How about keeping a list for each stick, then naming the disks 1,2,3 and 4, assigning each disk to the corrosponding list (and removing it from the last one) if, by checking through a for loop from 4 to x with step -1 if the list already contains one of the items with name of the number using the “get item block”, with x indicating the disk that has been clicked? That way you always check if there is a smaller disk on the pole already. And if they do you simply block the action

@Luc Thanks mate. I’ve made some progress, but the interface is doing my head in.

I’m not a teacher, I’m just a technician. My job is to bridge the gap between teachers and technology. I don’t set the curriculum, but I’m starting to think it would be easier just to teach the kids how to use Unity.

@sety So i’m not sure how easy to understand this will be for year 7’s and it will definitely require some restructering and renaming… excuse my terrible naming covention :sweat_smile:.
But it should all work now, if there are things unclear about my code be sure to let me know!

Ps. I actually think I missed part of the instructions as its pretty easy to complete now… I pressume you’re not allowed to move them from post 1 to 3 and vice verca, but that should be pretty simple to implement now with the rest in place.

1 Like

@Luc that is amazing! Well done! I would be interested to see how you did it. It doesn’t seem to want to remix though.

Edit: I wasn’t logged in! Sorry! :sweat_smile:

1 Like

@Luc That’s really good! It’s similar to the direction I was taking but your code is much neater and easier to understand than mine is! I will certainly use this! Thanks again!

1 Like

Oh you can move from post 1 to post 3. The completed stack needs to be on post 3. You nailed it mate. :slight_smile:

1 Like

Aahhh I see, that makes much more sence. Glad to have helped and good luck with the rest!