Jump to content
  • entries
    33
  • comments
    78
  • views
    61,769

The Game of REVERSE


ubikuberalles

916 views

For my next JavaScript project I decided to convert an old BASIC program I got from David Ahl's book BASIC computer games. It's a game called REVERSE and I first got it working on my Altair computer nearly 30 years ago. It was a text game but I was able to create a non-text version of the game (just use your mouse to play - no typing needed) in JavaScript. Here it is. I was able to complete a game in only 4 moves. Let's see if you can match or beat that. I hope you enjoy it.

 

With this program I learned a couple things about Geocities and JavaScript. I originally wrote the REVERSE program in the file reverse.js and then had the reverse.html file reference it in a SCRIPT tag. It didn't work. It works when the files are on my PC but not when the files are in the Geocities directory. To fix the problem I just pasted the contents of reverse.js into reverse.html. That's rather annoying and it would make it impossible for me to store JavaScript libraries on Geocities. I'll need to find another web site to store my JavaScript programs, especially if I am going to write more complicated programs that require program libraries.

 

I'm not sure what I want to do next. I'm not ready to do a mad libs game, like PDF asked (I'll need a couple Mad Lib scripts before I can start) but I'll give it a try in the near future. Time to look through Dave Ahl's book again. :)

5 Comments


Recommended Comments

Cool!

 

Hey, this game is on the RCA Studio II! It was one of the few on the system that I actually enjoyed.

 

Your port is much better.

 

:)

Link to comment

It's pretty obvious any position can be reached in 15 operations (two steps each for the 9th, 8th, 7th, 6th, 5th, 4th, and 3rd, plus one for the 2nd). Not quite so clear what optimizations are possible beyond that. I did once manage to solve your puzzle in 4 steps, but since 9^4 is much less than 9!, that's clearly not possible in most cases.

 

Any idea what the distribution of minimum solution length looks like?

Link to comment

Cool!

 

Hey, this game is on the RCA Studio II! It was one of the few on the system that I actually enjoyed.

 

Your port is much better.

 

:)

 

Thanks Mezrabad! I'm glad you enjoyed it. Despite its simple nature, the game can be a little addicting. Every time I start up the game I find myself playing more than just a few games. I don't know who invented the game of Reverse but it's a nice game for a demonstration project.

 

@supercat: I have no idea what the minimum solution length could be on this game. I've never done an analysis of the problem (don't know how, really). I did happen to find one article discussing an algortihm for solving the problem but I didn't read it thorughly and so I don't know if they gave a minimum solution length in detail. I suppose you could write a program that determines the minimum solution for a specific combination by building a minimum length spanning tree (I think that's the right name for it). Each node of the tree would represent the current state of the game while each branch would represent a possible move. Once the tree is built you could find the minimum solution by getting to the solution node with the minimum number of hops. It would be a nice feature of the game to use this tree to calculate the minimum moves and challenge the player to meet (or even beat) that number.

 

Although the number of combinations possible in the game is 9! it is, in fact, only 9!-1 in my implementation of the program. When the game is initiated I make sure the winning combination won't show up (thus, not allowing someone to win in zero moves). I suppose I could add another snippet of code that would also disallow a solution in one or two moves (in fact you could probably find a combination of numbers that only allows the maximum number of moves), but I think I'm done with the program for now.

Link to comment
Any idea what the distribution of minimum solution length looks like?

 

Minimum solution length is 1 swap, no?

 

That'd be 1/(7!*9) I think.

 

Also 4 swaps should result in less than 8^4 combinations, not 9^4 :)

Link to comment
@supercat: I have no idea what the minimum solution length could be on this game. I've never done an analysis of the problem (don't know how, really). I did happen to find one article discussing an algortihm for solving the problem but I didn't read it thorughly and so I don't know if they gave a minimum solution length in detail. I suppose you could write a program that determines the minimum solution for a specific combination by building a minimum length spanning tree (I think that's the right name for it). Each node of the tree would represent the current state of the game while each branch would represent a possible move. Once the tree is built you could find the minimum solution by getting to the solution node with the minimum number of hops. It would be a nice feature of the game to use this tree to calculate the minimum moves and challenge the player to meet (or even beat) that number.

 

There are 9! possible positions. Since that's only 362,880 a modern computer would have no trouble enumerating them. It would then be a simple matter to have a program identify all the positions reachable in zero moves (initial seed), one move, two moves, etc. Since the maximum is 15 moves, it would be necessary to make at most 15 passes through a 360,000-item list. A trivial level of computation.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...