Improving Upon Number Wizard

So, while working on my own projects at my own pace, I am also learning through a course on Udemy about the ends and outs of using Unity to develop games.  I recently just finished the section where we took a previous game we made in console only and gave it a User Interface.  That game was Number Wizard.

Number Wizard is a simple game.  You think of a number between 1 and 1000 and the computer gets 12 tries to guess it.  If it doesn’t guess it you win.

While the tutorial taught me a few things, like how to connect buttons to scripts and how to build scenes.  There was one thing I felt like they neglected on what would be a ‘final product’ of the game.  So I changed something and added something to the game and learned a lot in the process.

One of the major “bugs” of the game is that the way it was set up.  If your number was ‘500’ the computer would sometimes get stuck between 499 and 501.

“So your number is 499? No? 501 then? No? 499! No? Bah I give up, it’s impossible”.

Why did it do this?  Well it’s last guess becomes either you new maximum or minimum, and since it is picking a random number, including the max and min, it could randomly just go back and forth between the two.  So it wouldn’t always get stuck, but it would take it a few times bouncing around before it found your number, or sometimes it just wouldn’t find it at all.

So how did I fix it?  Well, before the old guess would become the new max or min, but we know we can rule out the old guess since the player did not say it was their number.  So if their number is higher, the min now becomes the old guess +1 and if the number is lower the max becomes the old guess -1. So now when the random number goes, it doesn’t include the old guess, it’s not an option.

This then lead to what I added to the game!  A tiny bit of AI (that’s artificial intelligence).  AI doesn’t have to be super complicated, and in fact this bit of AI is so simple, I only just realized that what I created was indeed AI.  Under certain circumstances the computer can tell you it’s got your number already or if you’ve made a mistake.

When I started thinking about using  the + and – 1 to the guess in order to rule out old numbers, I thought “What if min and max were equal, that would mean that number would have to be the correct number, the computer would automatically win.”  So I set that up.  If when you press “higher” or “lower” the max and min are equal.  You get taken to a different screen where the computer tells you that it figured it out already.

However, what if the user made a mistake.  They pressed up when they meant to press down.  What if they cheat and change their number in the middle of the game or they simply forgot their number.  Number Wizard can take care of that too.  If you tell Number Wizard to go higher or lower when you cant he will tell you that you made a mistake and claim victory for himself.

Making the “alternate computer win” screen was a challenge on it’s own.  Apparently in Unity your scripts and things get destroyed when you change scenes.  So I had to learn how to persist the Number Wizard script into the next scene to say that “this number is indeed your number”.  Also then using that script to display the number in a new scene other than the one it came from took some time to learn as well.

Overall I am happy with this game (mechanically speaking).  I took what they gave me for the lesson, refined it and added some stuff of my own.  I also learned a few new things that will help in my other projects for sure! When I get a site to put my games up on I will link it here.  Until next time!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s