Tag Archives: PowerShellGet

The 1 to 100 Game, Updated

Notes: Download link at the bottom of this post.

My just turned, five-year-old daughter was introduced to my PowerShell 1 to 100 game around two years ago. As I watched her play, I always thought I should make some changes to the game. Well today, I have a newer version, that I’d like to briefly share, and discuss.

First off, you may need to know how to play the 1 to 100 game. It was common in my household as a child, but it’s possible it wasn’t in everyone’s. It works this way: The computer — the function, more or less — chooses a random number between 1 and 100 and you have to try and guess the number. If you choose a number lower than the computer’s number, it will tell you to choose a higher number. If you choose a number higher than the computer’s number, it will tell you to choose a lower number. You continue to do this, until you guess the correct number.

What I always thought was necessary for this game was to make it possible to choose whether you even want to use 1 and 100. This 3.0 version of the function will allow you to choose the minimum and maximum numbers. That way, littler kids can play 1 to 10, or 1 to 20. Maybe your kiddo is learning their fifties: You could even play 50 to 59, if you desired. Maybe you have a little downtime while you’re waiting for a server restart; you can play it too. There’s some value here, but not perhaps the value you might typically expect with a PowerShell function. It does have an example of thrice nested Do-While loops. That’s how I pushed the previous version. Skip downloading this 2.0 version, and use the bottom link for version 3.0.

In the older version, it showed the aggregate totals by default. Now, you have to include the ShowTotals switch parameter, if you want to see that collected information. You probably do, if you’re going to play more than once or twice in a row. This information includes nuggets of information like how many games you’ve played, your total number of attempts to guess the right number across all games, and you average attempts per game. These totals have drastically improved, too. In fact, it’ll continue to show the previous totals, and the new totals, after each game. If this is confusing, then take a look at game play images further below, and try it out for yourself.

This first image, is a game from 1 to 10 that doesn’t include the ShowTotals parameter.

This next image is from two back-to-back games from 1 to 3, that does include the ShowTotals parameter.

So it’s been said, the function defaults to 1 and 100, if you don’t supply minimum and maximum numbers. Try it out when you have a minute, and definitely show it to your kiddos, too. If my daughter is any indication, your kids will enjoy it, as well. I should mention, that she was pestering me to update this function, after I first mentioned wanting to make some changes for her. A four-year-old pestering me to write PowerShell: I loved it.

On a final note, there is some redundant code in the function. Since this is just a game, and I have bigger projects, I’m leaving it as is for now. Maybe I’ll come back around some time and clean it up… we’ll see.

You can download it from the PowerShell Gallery, or better yet, from your PowerShell host application using PowerShellGet and the Install-Script function: Install-Script -Name Start-1to100Game3.0