Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion

I had a crazy idea recently for a new game - a game that defines an entire new *genre* of computer game, and a new style of programming computer games. Whether or not this idea will go on to change the way all computer games are written, I will let history decide.

It's such a simple idea that I don't know how it couldn't have possibly existed earlier. It doesn't require massive graphic capabilities, no CUDA NUMA GPGPGPU and the like -- it's an idea so profoundly simple that you'll be scraping your jaw off the floor with a spoon before you finish reading this blog post.

You run the 'game' and it sets up a directory structure to represent every possible state of the game. To play the game, you inspect the current folder, look at the currently available sub folders, and choose which one to navigate into. Each sub folder you see represents the next possible state of the game.

There is no executable program running when you are playing. The game is just your act of navigating the folder structure. It's a clever form of madness!

Here's some screenshots that show me playing the game, in a command prompt.

I've changed my prompt to just a 'greater than' sign, by typing 'prompt $g', to make it cleaner. Old-school DOS wizards do this kind of thing all the time. Hipster kids, try and keep up.

First I type 'dir /b' to get a clean view of the current folder.

There is only one folder, '__PLAY HANGMAN__' so I navigate into it by typing  'cd[TAB][Enter]'. The game has begun.


Looking in that folder I see the empty scaffold, three underscores (representing a 3 letter word) and the available letters listed down the left hand side. We're playing with a reduced alphabet to keep the number of permutations within a reasonable amount.


My first guess is the letter 'A'. To make this guess I type 'cd A[tab]'. When I type 'dir /b' to inspect the new state of the game I see that it was a good guess, as one of the letters of the word has been filled in. Also there is an 'x' next to the 'A' indicating that that letter has been guessed. That's all there is to it. Hear that pop? That was your cerebellum exploding through your temporal lobe.


If I try guessing 'A' again, all I find is a folder containing a file named 'You have already guessed that letter.' To undo my mistake I back out by typing 'cd ..' (You could, theoretically use this technique to undo any move, but that would be unsportsmanlike.)


A couple of moves later and I've guessed every letter:


The word is 'CAB'. There's no particular fanfare. Just the word 'WIN' declaring my victory.

Okay, now you've seen the whole thing I hope you're aching to not just download the game, but to write your own entry into this brave new genre. You could do for Gehtto-Folder-Games what John Carmack did for first person shooters!

I'd love to see an implementation of tic-tac-toe, aka, naughts and crosses. Also, hangman could be minified by using junctions (i.e. symbolic links) -- I'd love to see that implemented. The possibilities for new games are pretty much endless. Maybe six or seven.

Okay let me level with you. The mathematics of this idea were just ridiculous. For a full 26 character alphabet, I would've killed my little computer. (Care to accurately calculate how many folders are created for the given alphabet?) It's all based around N-factorial where N is the size of the alphabet. Factorial is not something you want to see in the real world.

I'm on holiday at the moment, so the only computer available to write it on was my dell mini, which doesn't have any serious coding environment. So rather than write it as a console app in visual studio (or even a powershell app) I wrote a javascript page that generates a batch file. It's very niche.

This also turned into an opportunity to learn the ins and outs of getting recursion wrong with javascript. The most common mistake you make with recursion in javascript, it turns out, is forgetting to declare a local variable. This means that the variable becomes global and your recursion goes nuts. Don't make that mistake. When your code is creating subfolders all over your hard drive it's a particularly painful mistake. It took me considerably less time to write the program than it did to debug it, and (considerably*considerably) less time to debug than the time to clean up all the folders left in unexpected places.

But the funnest bit was the ascii sprite code.

I had one array that showed the final hanged man:

var hangyPicture = [
'   _______   ',
'   I     I   ',
'   I     O   ',
'   I   --I-- ',
'   I    I I  ',
'   I         ',
'--===--      '];

(Side point... why wasn't my ascii art better than this? Because | and \ are not valid in folder names.)

And I had another array that showed how many misses were required before a given character of the hangyPicture was shown:

var hangyMask = [
'             ',
'             ',
'         1   ',
'       33233 ',
'        4 4  ',
'             ',
'             '];

Then, with those two arrays in place, I can work out the names of the folders to create. I walk through the mask, one character at a time, and compare the digit I find to the current number of missed guesses. If the digit I find is less than (or equal to) the current number of missed guesses, then I include that character in the folder name, otherwise I mask it out with a space. Ah, I give in -- it's easier to just show the code:

for (var h in hangyPicture) {
  // use hangyMask[h] and numberOfMisses to mask chars out of hangyPictures[h] 
  for(var i = 0; i < hangyMask[h].length; i++) {
    if (hangyMask[h][i] == ' ' || hangyMask[h][i] <= numberOfMisses) {
      folders[h] += hangyPicture[h][i];
    } else {
      folders[h] += ' ';
    }
  }
}

Okay. Now you've been enlightened with the future of ultra-ghetto folder-based gaming, go ahead and make your own. I can wait.


Here's the code


The accompanying program is a piece of javascript that creates a windows batch file. You run the batch file.





'Doekman' on Sun, 08 Jan 2012 08:26:25 GMT, sez:

Fabulous. Always resist the urge of using the CALL statement (i.e.: functions are for nitwits).



'Andy Brice' on Mon, 09 Jan 2012 08:24:08 GMT, sez:

You are coding Java on holiday?



'lisperati' on Sat, 09 Feb 2013 11:31:23 GMT, sez:

Im surprised you used javascript instead of lisp for this program as recursion is built into lisp which would not only make the program shorter but easier to formulate.

Also ive dreamed about making the same idea as a chess game but realised it would require so many different choices as individual files it was insane, but and he is the but, it could be made as a datafile instead and displayed as each move was made. The benefit of this is that the computers doesnt have to be a chess genius to win, but it just traces the path to victory no matter what the user does to try to thwart it. Thus the computer could theoretically win against any player no matter how good.

Cheers Lisperati




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

The Canine Pyramid The Canine Pyramid
Humans: A Tragedy. Humans: A Tragedy.
ACK! ACK!
OfficeQuest... Gamification for the Office Suite OfficeQuest... Gamification for the Office Suite
New product launch: NimbleSET New product launch: NimbleSET
Programming The Robot from Diary of a Wimpy Kid Programming The Robot from Diary of a Wimpy Kid
Happy new year 2014 Happy new year 2014
Downtime as a service Downtime as a service
The Shape of Your Irrationality The Shape of Your Irrationality
This is why I don't go to nice restaurants any more. This is why I don't go to nice restaurants any more.
A flowchart of what programmers do at work all day A flowchart of what programmers do at work all day
The Telepresent Man. The Telepresent Man.
Interview with an Ex-Microsoftie. Interview with an Ex-Microsoftie.
CRUMBS! Commandline navigation tool for Powershell CRUMBS! Commandline navigation tool for Powershell
Little tool for making Amazon affiliate links Little tool for making Amazon affiliate links
Extracting a Trello board as markdown Extracting a Trello board as markdown
hgs: Manage Lots of Mercurial Projects Simultaneously hgs: Manage Lots of Mercurial Projects Simultaneously
You Must Get It! You Must Get It!
AddDays: A Very Simple Date Calculator AddDays: A Very Simple Date Calculator
Google caught in a lie. Google caught in a lie.
NimbleText 2.0: More Than Twice The Price! NimbleText 2.0: More Than Twice The Price!
A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker



[powered by Google] 

How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

InfoText - amazing search for SharePoint
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy