Tuesday, July 24, 2012

Adventure of the Week: Journey to the Center of the Earth (1978)

I'm a little bit busy this week, so for the sake of tight deadlines, we're tackling another Greg Hassett adventure for the TRS-80 -- Journey to the Center of the Earth, published in 1978, which I believe is his second published game after Enchanted Island.  No publisher is credited, but it's likely this one was released by Mad Hatter Software or Hassett's own Adventure World; it was also published in type-in form in 1981, in Bob Liddil's Captain 80 Book of BASIC Adventures, and also appeared on the Commodore 64 a few years later.


Hassett's style was still developing -- he was only twelve or thirteen years old at the time -- and so we see that spelling and grammar are again an issue, and the map is rather loosely and randomly constructed.  If we die, the program just ends; there's no opportunity to retry.  And the BASIC-language parser is surprisingly fast, but limited -- for instance, INV and INVENT don't work, we must spell out INVENTORY, and some words are very situation-specific, requiring a fair amount of guessing.  The name borrows from Jules Verne's classic novel, but like Hassett's later The House of Seven Gables, the game is a treasure hunt that borrows the basic concept but otherwise bears no substantial resemblance to the book.



I always urge interested readers to try these games out before proceeding here; Journey to the Center of the Earth is not a particularly difficult game to finish, though the map is fairly large and it's not always obvious which items are score-worthy treasures and which are just items.  As usual, I will be giving away most of the puzzle and plot details as I encountered them, so as you proceed beyond this point, be advised there are...

***** SPOILERS AHEAD! *****

The game begins by prompting "WHAT IS YOUR NAME?"  -- I went with GUYBRUSH -- but I never saw the game make use of this information; it seems to be an unfinished idea, and does not appear in Hassett's other games.  I can only speculate that this is here to confuse the player with a later "WHO GOES THERE?" puzzle -- our entry here is not useful as a password.





We begin in a ship with nothing in inventory, apparently arriving at the center of the Earth rather woefully undersupplied.  This adventure won't be too serious in tone, as the ship's computer screen reads: SHIP WILL NOT FUNCTION -- FRIBULATING GONKULATOR IS BURNED OUT.  So presumably we will to have to get it refribulated so it can gonkulate, or gonkulate it for the sake of fribulation.

North of the ship, we suddenly find ourselves in a COBBLESTONE HALLWAY, with a chirping that reportedly SOUNDS LIKE BUGS.  Further north is a room with rubies in its walls, and there's a LARGE RUBY we can take.   But GADZOOKS!!! A GAINT [sic] BUG JUST WALKED IN TO KILL ME!  Hassett's early games never felt bad about telegraphing a creature's intentions... and whoops, maybe I'm misunderstanding and that's not a misspelling, as shortly I'M BEING DEVOURED BY A GAINT BUG!!  And then I'M DYING...DYING...DEAD, in rather an overdramatic (not to say impossibly uttered) manner.

So we don't want to run into any Gaint Bugs, at least not yet.  But they show up randomly, and all over the place, so we're going to have to figure out a solution before too long.

Over to the west is A ROOM WITH MANY ANIMALS... until WAIT! THEY'VE ALL RAN [sic] AWAY.  All that remains is A PARROT IN A CAGE.  We can't GET CAGE or OPEN CAGE, as it's not a recognized noun, but we can GET PARROT and the cage comes along.

South of the ship is a DUSTY PLACE containing A SET OF KEYS.  Past this, as the topography becomes increasingly random, we find A HUGE ICE CAVERN, leading to A ROOM WITH TRACES OF SLIME ON THE FLOORS AND WALLS.

The slime room leads to AL'S DINER, apparently of unlicensed Happy Days fame, where there's a COKE MACHINE, joyfully and explicitly unlicensed with an ENJOY COCA-COLA banner.  Presumably we will need a quarter to avail ourselves of its carbonated bounty.  There's also some FOOD here.  I never found a need to eat or drink in-game, though the game will let us imbibe and consume these, or try to feed various creatures.


South of the slime room is the source of the slime - the HYDRA ROOM, occupied by a nine-headed hydra.  It blocks our way south and west, but we can explore a TORTURE CHAMBER to the east (where THERE IS [sic] SOME HUMAN SKELETONS and a giant bug asleep.)  Trying to KILL BUG indicates that I CAN'T KILL ANYTHING. I'M TOO WEAK. BUT MAYBE IF YOU WERE A BIT MORE SPECIFIC... though this actually a lie, as the game will let us KILL things in the right context.

The HUGE PIT west of the slime room contains a quarter and a cigarette lighter.  We can't BUY COKE, but we can INSERT QUARTER to get a bottle back at Al's Diner.  We can't SHAKE COKE or SPRAY COKE or even OPEN COKE, so that's not going to be a novel attack.


A SMALL ROOM west of our starting point contains a GOLD NUGGET, and a scribbling reading HAR HAR HAR! YOU'LL NEVER MAKE IT! >> ARBADAC ARBA.  A 35,000 CARAT DIAMOND (could a human being actually lift that? We can carry it, anyway) lies in a low crawl space south of this room, and going east from that room leads into the traditional MAZE OF TWISTY LITTLE PASSAGES a la the classic Colossal Cave Adventure.  The maze contains a MAGIC WAND.


One exit from the maze leads back to the ruby room -- and with no giant bug about at the moment, we can go north to find ourselves IN A DARK ROOM.  And I THINK I HEAR GRUNTS AND GROANS NEARBY.  Ahem... I never found out what this was referring to, and that's probably a good thing.  East of this area is another maze.

North of the dark room is the SOUTH SIDE OF A CHASM, and a SHINY SWORD, with molten lava below.   The game keeps us from walking blithely into the molten lava, but we will probably want to find a way across.

We seem to score 10 or 15 points per treasure, out of a maximum of 175, but they do vary.  We have to drop them in the ship to earn points, otherwise we remain at 0 with a BOY, YOU STINK! assessment from Mr. Hassett.

Hassett's mazes are usually pretty straightforward -- each room generally has multiple exits that lead back to the same place, with one that goes to a new area and one (usually) that goes back to a previous one, so they are not hard to map using the traditional item-drop method.

The "secret passage" maze leads to THE TROLL'S PALACE, with gold bars and a diamond necklace. With 5 treasures claimed, I have 80 of 175 points.  I am hoping the sword will help deal with the hydra or any giant bugs I encounter, but in a dark room where THERE ARE GIANT [sc!] BUGS ALL AROUND ME! we still can't KILL them, though at least we can just exit the room without being harassed or killed.

Ah, yes, when a giant bug arrives specifically to kill us, we can use the sword to KILL BUG -- DING! DONG! THE BUG IS DEAD, THE BUG IS DEAD!!!  Several of the author's works contained Wizard of Oz references.

How can we cross the lava chasm?  POUR COKE and OPEN COKE and THROW BOTTLE don't do anything -- not that I should have realistically expected a cold soda to cool down molten lava.  But we can WAVE WAND to magically transport ourselves to the north side of the chasm.  It leads to a wooden platform and a sign warning us about the rickety wooden bridge, but we can ignore the sign and travel to the TROLL'S PLACE. (Which turns out -- [sic] -- to be the Troll's Palace again, but by a different entrance and with more resistance from the resident troll, who throws an axe at us if we try to enter without dealing with him.)


The axe-throwing troll is another homage to the classic Crowther/Woods adventure, but his axe is consistently fatal, so we don't want this to happen.  We can't answer the Troll's "WHO DARES TO ENTER MY PALACE???", it seems, nor can we KILL TROLL or exit the room without being killed by his axe.  So is this a red herring?  Are we just supposed to get into the palace via the maze?

What about the hydra?  We can FEED HYDRA, which turns him into A GIANT HYDRA RUBBING HIS STOMACH, but he still won't let us past.  HELP is actually helpful here, suggesting CIGAR? CIGARETTE? TIPPARILLO [sic]?  We can't USE LIGHTER or LIGHT LIGHTER, but we can BURN HYDRA and THE HYDRA CRUMBLES TO THE GROUND DEAD.  With this surprisingly flammable creature dispatched, we can get an emerald from the CLAM ROOM and a MING VASE from the DRAGON ROOM.  We've got 7 treasures and 105 points now.

Past the Dragon Room, we can get some silver bars in a MAMMOTH GARDEN.  The VELVET ROOM contains some tools (not described further and treated as a set).  There's a TREASURE ROOM where MANY DWARVES GUARD SOME PRETTY SCRAWNY TREASURE that's not further described and cannot be obtained, and an ARABIAN ROOM with an oil slick, in a bit of 1970s pop culture xenostereotyping.  But we can't BURN SLICK, as oddly enough IT DOESN'T BURN.

The oil slick is meant to be a hint leading us south to MAC'S EARTHDIGGER BODY SHOP, which contains a new fribulating gronkulator!  This is a little clearer now -- we are near the center of the earth because our "ship" is a digging contraption of some kind.  But we can't GET FRIBULATING GONKULATOR because the parser doesn't recognize any variant of it???  We have tools, so maybe we can FIX FROBULATING GONKULATOR... but I CAN'T.   Oh, wait, I have been mistyping, calling it a GRONKULATOR [mic] instead of a GONKULATOR!  We can GET GONKULATOR.

Now can we install it in the ship?  We can't REPLACE or INSTALL it; if we try to FIX it here, the parser says I THINK I HAVE TO DROP IT FIRST, but DROP GONKULATOR doesn't work?  Ack, I keep typing GRONKULATOR!

And as soon as we DROP and then FIX GONKULATOR, the game is over!?!  I am 5 points short, though, with 170 of the 175 points, so let's see what I've missed.

Aha!  If we return to the dangerous TROLL'S PALACE entrance with the parrot in hand, the parrot chants, "SIR ALEXANDER...SIR ALEXANDER!"  But SAY SIR ALEXANDER doesn't solve the problem?  A simple SIR ALEXANDER works, and THE TROLL SCURRIES AWAY IN FEAR without tossing an axe in our direction.  But this is just another way into the Troll's Palace, where we have already been, and we don't get any points for doing it. 

I had to look at the BASIC code to see that DROP PARROT at the climax counts as a 5-point treasure, earning us the rank of ADVENTURER GRANDMASTER:


Hooray!  We're the Adventurer Grandmaster of Adventurerdom!




I'm getting close to exhausting Mr. Hassett's sizeable body of work, but there are still a couple of his games I haven't tackled.  We'll get around to them in due course, I am sure; somehow I missed the existence of his games back in the TRS-80 era, so I've been enjoying discovering them, three decades later.

Monday, July 23, 2012

Let's Make Us A Game II-2: The AI Opponent

The rudiments of Tic-Tac-Toe Bastard are developing nicely.  My goals in this installment are to implement some basic UI elements, and try to get the artificial intelligence opponent working.  I'm sticking to text mode for now -- it's faster to play and debug, and once the core of the game is functioning we can start dressing it up with graphics, sound and a mouse interface.

The latest version of the code, below the fold, adds a couple of general gameplay features:


-- As the game starts up, the human player is allowed to select a difficulty level from 1 to 9 via the keyboard.  In the final version, this will be replaced with a GUI (graphical user interface) slider labeled more abstractly from "EASY" to "HARD" that can be changed on the fly (I think).  While the values from 1-9 will affect our AI algorithm directly, there aren't necessarily any visible differences between levels 3 and 4 or 8 and 9, so I'm cheating a bit here, using this approach to hide those sloppy details from the user.

-- There's also a simulated coin flip at the start of the game to determine who goes first; this has an impact on how the game plays out, so I want to make sure neither side has an unfair advantage.  I just use the results to reorder the PLAYERS array, and then the game proceeds as usual.  I did run into one technical glitch here -- every coin-flip was always coming up as a 1, even though I am seeding the pseudorandom number generator based on the system time!  It turns out that the math.randomseed() and math.random() functions are not initially very random on some platforms, the PC included; calling the math.random() function a second time produces the intended result.

To get the coin flip to work as expected, I had to fix a bug in the main game loop.  There were places it was using the bare index i instead of the PLAYERS[i] identification, which caused some confusion about who was who.  I also added some utility functions to represent the current player ID as a string -- "P" and "C" for our text-mode grid display, and "PLAYER" and "COMPUTER" for other uses, like the GAME OVER message.  This was more readable than the sequential identifiers "1" and "2", especially after I added the coin flip, and while this logic won't survive the text-mode phase of development, similar code will ensure that our graphical identifiers are correct later on. 

Almost all of my initial design elements are defined now, but I have not yet added a general tally for a series of Player vs. CPU matches -- the main game loop accommodates a single match only.  But that won't be hard to fix later -- we'll just have to wrap this game loop inside a larger loop.  Right now I'm interested in debugging the basic structure of the game.

Adding support for the human player's input was not difficult -- similar to the difficulty handler at startup, we just need a routine that prompts the user for a cell number from 1 to 9, and checks to make sure that A) the input is a valid number and B) that cell is not already occupied.  I'm being lazy here -- if either test fails, the user is given the same "That square is already occupied" message.  And I'm not going to correct this, because when we move into graphical, mouse-oriented mode, we simply won't allow the user to click on a square that's already occupied, and there's no way for the user to click on a nonexistent or invalid square.  An updated version of this routine will always return a valid square.


Getting the computer AI opponent working was more of a struggle than I expected.  The fact is that Tic-Tac-Toe on a 3 x 3 grid is not a very sophisticated strategic challenge, and two players can easily fight each other to a draw.  But human beings think intuitively, and computers have to create the appearance of intuition by using math and logic.  Tic-Tac-Toe is very simple compared to chess or even checkers, but I wanted to use similar principles to develop a routine that worked honestly, without using a lot of heuristic shortcuts.  I wanted the routine to be extensible to more complex challenges, like a 5 x 5 grid, and I wanted it to play naturally, determining its moves on the fly and ideally a little bit unpredictably.

This was my initial AI concept -- when it's the computer's turn, I want it to:

-- Look at each empty square on the grid, and calculate a "win probability" score for that square
-- Pick randomly from the possible moves with the highest (same) score

Getting the scoreMove function that calculates the "win probability" working was the tricky part.  I was able to create a hypothetical "next state" of the grid including the new move under consideration, and then reuse my checkVictory function from our previous installment to handle the obvious case -- if a particular move wins the game, then it should be assigned the highest possible score.  This worked immediately -- I let the computer pick randomly (and played poorly myself) until the CPU saw an opening, at which point it would successfully make the winning move.  So far, so good.

Dealing with non-final situations allowed Tic-Tac-Toe Bastard to earn its name as far as my efforts were concerned.  What I intended to do was to recurse over possible present and future moves to come up with a probabilistic score -- in other words, consider how the game could play out if a particular move was made, and then the player made one of the available next moves, and then the computer made the next available move, ending up with a higher score for the move presently at hand based on its likelihood of leading to eventual victory.  This is the classical approach to solving these kinds of problems -- the computer "looks ahead" at all possible sequences, and chooses the move that's most likely to help it win.  This takes some time and has historically been the primary obstacle to really smart AI chess play -- even for a simple game like 3 x 3 Tic-Tac-Toe, there are more than 50,000 possible sequences to consider after the first move is made.

Before I could find out if my basic approach was working, I had to resolve a couple of issues I hadn't considered.  One fix was to add a check to see if the grid is full before proceeding with deeper hypothetical iterations -- I was getting strange errors and invalid scores deep in the analysis, because the system was trying to consider a move when none were available.  This also sped up the algorithm by stopping it when it could no longer do anything useful, and pointed me to a good way to handle the difficulty setting:  the algorithm intentionally stops looking farther into the future if it's already gone through a certain number of levels.  Lowering the look-ahead to 1 essentially makes its moves random, while setting it to 8 or 9 allows it to consider all possible outcomes (depending on who goes first.)  I also added logic in the main game loop to see if the grid has filled up and the players have battled to a draw, so the game can end neatly if nobody wins.

I also made one heuristic compromise.  I realized that if the computer wins the coin flip and goes first, it might as well pick a square totally at random -- letting it consider all 9 possibilities takes considerable CPU time and always comes up with identical scores for each square.  Adding that shortcut sped up the first step (and ultimately obviated any visible difficulty difference between levels 8 and 9, and 7-9 are also the same if the player goes first.)

But my algorithm still wasn't working -- the computer still wasn't making very good choices.  What I was trying to do was calculate the probability of a win by building up a score, adding a portion of the next move's predicted score to reflect the growing uncertainty of each future state, as we can't predict what the player will do.  (Using the computer's algorithm for this prediction suggests that the player will play the same way, which is unlikely but the best available option.)  I was getting scores back from the scoreMove function, but they weren't proving very useful.

So I stepped back and considered this basic scenario for debugging -- if the player marks the upper left-hand corner, marked with a P below, then the computer should see that it has two moves which are least likely to be helpful to its cause, marked with 0, because they don't block the player's potential winning sequences at all:

P |    |
---------
   |    | 0
---------
   | 0 |

Whatever the score assigned (I realized that a true "probability" was not really necessary or possible, I just needed a means of ranking the possible moves), those two squares should be assigned the lowest score -- they don't block the player at all.  Similar patterns should be apparent if we mark any of the four corners.

With this simple check at hand, I found out that my approach was picking the worst moves as the best moves -- in effect, pushing the player toward victory by blocking off the moves that were least likely to help him or her win!  The problem was that, in considering what the player might do after the CPU made a move, I was starting from zero and adding to the potential score, treating the player win as an improvement.  So the recursion code was working, it was just not acting in the CPU's best interest; it had become very good at helping the player win.

So I changed the logic to start the score at a value of 8 (my "this move wins" value being 16, and "impossible moves" left at 0) and then subtract half the score calculated for the other player's next possible move.  The math here isn't precise -- I could have used any sub-1.0 multiplier to reflect future uncertainty as we look deeper, and with 0.5 sometimes the numbers go negative.  But the ranking still works -- now I was seeing the weakest scores for the two useless moves, and the computer is now putting up a proper fight if we let it look ahead to the maximum.  Even better, if we use a low difficulty setting, it has less information to work with because it doesn't look as far ahead, and therefore it makes poorer but still rational choices; it's a clean way to limit its "intellect", though I may try to rescale the difficulty values for more accuracy now that I know more about how it's actually working.

The final test was to have my wife play a few rounds -- she beat it handily on easy, and played to a draw on the harder difficulty settings.  It never beat her, though she was impressed that it was making smart moves, so I think I've accomplished what I wanted to.  This does, however, suggest that I should try to make the engine more flexible, so I can up the ante to make this more like a playable game -- a 5 x 5 or 7 x 7 grid should put up more of a challenge for a human player, while my existing algorithm will be slowed down (and may need to have limited look-ahead to keep performance reasonable) but should still be effective.

Next time, I plan to start wiring in some graphics.  The latest code is below the fold:


Sunday, July 22, 2012

Cover to Cover: Jaguar EGM Promo (pp. 8-9)

We're paging through Atari's 1994 promo insert for the company's Jaguar console, published with an issue of Electronic Gaming Monthly magazine.

Page 8 features the Jaguar's most indelible exclusive -- Jeff Minter's Tempest 2000, a throbbing techno reimagining of the classic Atari coin-op designed by Dave Theurer.  Minter reportedly didn't have access to an actual Tempest machine during the game's development, so he was going on memory, but the resulting game remains technically impressive and highly playable, with an excellent soundtrack.  It was hard to promote this kind of experience in a print ad -- still shots tend to look bare and simplistic -- but Atari did its best:


Page 9 gets us past the big titles and into the second-tier games, with half-pages devoted to id's Wolfenstein 3D and the freewheeling polygonal racer Club Drive.  I confess to playing through the Jaguar version of Wolfenstein 3D before I ever went back and played through the PC version, and it's actually quite a bit different from the original, with different levels and some additional weaponry, though the basic technology remains the same.  id intended this port as a test before tackling DOOM, but Atari was impressed (and desperate for software) enough to urge release of Wolfenstein 3D as well.



Club Drive was meant to be a 3-D Micro Machines sort of game, with a style reminiscent of Atari Games' Hard Drivin', but the game was not well received by critics or players.  The untextured polygon graphics were already starting to look outdated, and the engine didn't use the complicated Jaguar hardware very efficiently.  As a result, the game was sluggish, with imprecise controls, and the handful of imaginative racing environments were not enough to make it playable or successful.

Next weekend, we'll continue...


Friday, July 20, 2012

East Vs. West: Magical Saurus Tour (1990)

One of the more unusual PC Engine titles to make it from Japan to the United States, Magical Saurus Tour (known here as Magical Dinosaur Tour) was published in 1990 by Victor Musical Industries on the console's original 1.0 CD-ROM System Card.  I had a copy of the American version back in the day, but no longer own it, so I will have to go on memories and research for comparison purposes.  The Japanese title screen calls the Toho kaiju movies to mind -- if you don't speak Japanese, you can easily imagine this says something about King Ghidorah:



This was a surprising choice for NEC to import, although the company did make a lot of strange decisions when it came to populating the US TurboGrafx library; the rich, high-quality Japanese PC Engine software lineup was barely in evidence on our shores.  Magical Saurus Tour seems an especially odd choice, however, because of the amount of translation and voice-over recording the localization required (no word on whether the Beatles had to approve the title.)  My only hypothesis is that NEC felt the expensive CD-ROM accessory might be an easier sell if there was some educational content available.

By the standards of the day, Magical Saurus Tour does a pretty good job at delivering on the cover's English-text promise: "A NEW PICTORIAL ENCYCLOPEDIA OF DINOSAURS."  It's a CD-ROM encyclopedia, of the sort usually devoted to anime fandom, and it's pretty comprehensive.  While the text could have used substantial fleshing out, this was designed to be read on a TV screen with a gamepad; the primary attraction may be the full-color artwork, most of which matches the best scientific anatomical modeling available at the time.  And it's not limited to the obvious, well-known saurians of later Jurassic Park fame; it takes the task seriously, covering more obscure creatures like Metriorhyncus:


And Archaeopteryx, the first known dinosaur-bird species (probably a relative but not a direct ancestor of modern birds; more recent finds are indicating that feathers were much more common than believed in 1990):


And Deinonychus, a member of the raptor family:



My only complaint about Magical Dinosaur Tour was the limited text -- we only get a few screens of large-print text, though the Japanese version likely crams more content into the limited space (if I could read it!)


These individual dinosaur pages can be accessed by a number of pathways, lending significant organizational value to the encyclopedia.  There's an alphabetic index, of course, as well as an evolutionary timeline tree, allowing users to see how various families of dinosaurs changed over geologic time:


There's also a time-shifting geographical map, showing the regions of the earth as portions of the Earth's original single continent moved (borne by the tectonic plates of the Earth's crust) into its modern configuration, and allowing the user to examine the dinosaurs that inhabited each region:


And a sightseeing tour allows users to view the dinos in approximations of their contemporary habitats, with some limited animation depicting hypothetical behaviors derived from anatomy and observations of similar creatures in our time.  These hard-headed little guys are battling for dominance:


There are also some entertaining bits of trivia, like a "Best of Three" awards ceremony (Biggest Dinosaur? Tyrannosaurus!) and other notes with fanciful illustrations:


The science is respected, and so are users, as then-current uncertainties are documented in these sections --- my own knowledge had become outdated in 1990, and I remember learning about the whole "Brontosaurus" mix-up from the American version.  (In short, an Apatosaurus had had a reconstructed, semi-hypothetical head stuck on it for a museum display; further analysis established that this was in error, and both skeletons represented the Apatosaur.)

There a poignant end-of-the-dinosaurs section that presents various hypotheses about the demise of the thunder lizards, and the subsequent rise of the mammals, as depicted in this asteroid-induced winter image:


Magical Saurus Tour isn't a game, but a high-tech reference work circa the pre-Internet era.  I can't really recommend it in either its Japanese or American forms for a 2012 audience; the information presented is too limited in the age of Wikipedia and Walking with Dinosaurs.  But it was a credible attempt to document our understanding of these fascinating creatures circa the late 1980s, and remains a unique entry in the PC Engine/TurboGrafx-CD library.



This one wasn't a huge seller in the US, but is also not much in demand so it's generally inexpensive.  You may be able to purchase the Japanese version here:

 Magical Saurus Tour PC-Engine CD

or the American one here:




Thursday, July 19, 2012

The LoadDown -- 07/19/2012

The weather is hot here in Michigan, USA -- it's a good time to stay inside and play video games.  You don't even have to go outside to buy them!

WiiWare --  Nothing at all on the Wii or the Virtual Console this week.

DSiWare -- Two new titles for DSi and 3DS:  Rabi Laby 2 is yet another game inspired by v. dentata Alice in Wonderland, a sequel to the original Rabbit Labyrinth, again sending Alice and her pet rabbit through a series of dangerous puzzles which they must overcome with teamwork.  Petit Computer is an odd but interestingly retro idea -- it presents a virtual, BASIC-driven computer that lets users create their own programs and games; the sprite capabilities are a bit beyond what most actual 8-bit computers could handle, but otherwise it seems like a forgotten 80s platform.  I'm not sure about typing in programs using the stylus on a virtual keyboard, though, and I doubt we'll see any magazines full of type-in listings for this quirky throwback.

3DS eShop --  New titles here, plus a few old ones.  The Phantom Thief Stina and 30 Jewels is an action/strategy game -- players can play as the jewel thief Stina or security chief Sara, as Stina tries to steal jewels while avoiding security droids; it sounds like a stealthier game than it is but is a fresh idea for a real-time strategy title.  Nikoli just keeps pumping out new, vaguely dissimilar puzzle titles, with Masyu by Nikoli, kind of a pipe-fitting Sudoku variant  And Nintendo's 8-Bit Summer continues with the Game Boy sequel, Kid Icarus: Of Myths and Monsters, and Tumble Pop, which borrows from Ghostbusters a bit as its boy hero sucks up various monsters with his backpack vacuum weapon.

XBox Live Arcade -- Two new games in the past week.  Tony Hawk's Pro Skater HD brings the original skateboarding game up to speed graphically, while inadvertently highlighting how stagnant the long-running series has become.  Dungeon Fighter Live: Fall of Hendon Myre brings the popular Korean PC title Dungeon Fighter Online's multiplayer dungeoneering and light RPG elements to XBLA, though the 2-D gameplay resembles Golden Axe more than Rogue or Dungeon Master.  The subtitle implies there will be more of these released as time goes on.

PS3 on PSN -- One new game arrives this week: Dyad, a psychedelic, symbolic, fluid arcade sort-of-racing game with musical elements -- it calls late Jeff Minter and SEGA's Rez to mind, but is definitely its own critter.  Sony's always been a little more adventurous with its online content than other platforms, and PS3 owners will want to check this one out.

PSOne Classics -- Nothing new here this week.

Notable on Steam -- New releases are nonexistent while the Steam Summer Sale is going on, but there are good deals on PC games new and old afoot.  My backlog is growing, but I'm not really complaining.

Wednesday, July 18, 2012

Let's Make Us A Game II-1: Basic Logic



Before I get into anything fancy with my Tic-Tac-Toe Bastard game, I'm going to sit down and work through some basic game logic. I want to code the foundations in pure Lua with text output to the console, to get a bare-bones version of the game working for faster and easier debugging.  We should be able to reuse a lot of this material as we layer graphics, sound and GUI elements into the build later on, but there's quite a bit of groundwork we can do first and it's good to keep things simple while we create the core.

We'll represent the tic-tac-toe grid using a simple 9-cell table structure.  While our visual representation is a 3 x 3 grid, we really don't need to make the table that complicated; we'll just lay out the 9 cells in a single row, numbered as follows, and display the grid to the user in the expected manner:

1 | 2 | 3
---------
4 | 5 | 6
---------
7 | 8 | 9

(Note that Lua, unlike many computer languages, natively starts numbering at 1 -- this makes intuitive sense, but it takes some getting used to for programmers used to counting from 0!)

Each of these cells will start in an empty state, and will be marked by either the player or the CPU as the game progresses.  For readability, we'll declare three useful constants at the top of the routine -- the numeric values really don't matter, as long as they are unique:

EMPTY_ID = 0;
MY_ID = 1;
CPU_ID = 2;


Now we'll declare and initialize the tic-tac-toe grid accordingly:


gGrid = { EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID, EMPTY_ID };

With this structure and the constants we've set up, all we need to do to record a player's move is set an element of the gGrid array to either MY_ID or the CPU_ID.


One of the logic challenges we need to deal with is recognizing when somebody has won the game.  We could do this heuristically, searching through the grid for patterns indicating a win, but there are a finite number of combinations to consider.  Our code will run faster and more simply if we just define all of the winning combinations in a table of tables, like so:


POSSIBLE_WINS = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9},
                  {1, 4, 7}, {2, 5, 8}, {3, 6, 9},
                  {1, 5, 9}, {7, 5, 3} };


(We could also use this approach to impose rule variations on the player -- an "only verticals win!" round, for example, although that seems unlikely to be much fun in a game of Tic-Tac-Toe, so we probably won't do that.)

For reasons that may (or may not) become clear later, I'm going to treat the human player and the CPU as "players" by setting up another table:

   PLAYERS = { MY_ID, CPU_ID };


This approach makes the main game loop simpler -- we just need to loop through the players, giving each one a turn until somebody wins.  (This will also simplify our lives later on if we decide to add a player-vs.-player option, or a CPU-vs.-CPU exhibition mode, or even an online mode or a more-than-two-players mode.)


We will still need to distinguish between the human player and the CPU at another level -- when the main game loop looks for input from the current player, we'll want to solicit interactive input from a human player and call upon an algorithm for the CPU's move.  But the main game loop can just solicit a move from the current "player", however that is defined, check for victory, and end the game if that player has won.


My initial scripting goal for this installment is to establish the Tic-Tac-Toe grid, mark it up, and verify that we can detect a victory condition and identify the winner.  So I'm not going to implement any real user or CPU action -- I'll just let the code select a random number from 1 to 9.  In fact, I'm not even going to check for duplicates, so our players can just mark right over each other.  I just want to set things up so that the game can run until somebody wins a single match.

My main game loop logic needs some work at this stage -- it always forces the first player listed in the PLAYERS table to go first, and it's not even really using the PLAYERS table correctly; it only works because our indices {1, 2} happen to match the PLAYER_ID and CPU_ID values.  If we wanted to mix up the play order we would have to fix that, so that then we could just restructure the PLAYERS table to reorder the participants.  My code also breaks out of the for-player loop using a "break" command, which is less than elegant.  And there are some conditions it doesn't catch, like playing to a draw, which is entirely possible.  But we'll have time to refine this in a future installment.

The checkVictory function accepts a grid and a player ID, and uses the POSSIBLE_WINS table to see if that ID has occupied a winning set of squares on the grid.  This routine will probably not change much as we develop the game.  (Note that I could reference the actual game grid directly as a global variable, but passing it in as a table keeps the local code clean, and the ability to handle multiple grid instances might prove very useful for our AI implementation later on.)

For now, I've defined a getMove function that takes an ID from the main loop, and then decides how to obtain move input.  Right now, the supporting getPlayerInput and getCPUInput functions do exactly the same thing, picking a random number from 1 to 9, but we'll change that later.


I've also written a throwaway utility function -- doPrintGrid renders the game grid to the Lua console, in a readable text format.  This routine is handy for now but will probably be discarded later in the development process.


All we can really do with this initial version is run the code and see whether it stops when victory is randomly achieved -- which it does!  The code so far is below the fold.


Tuesday, July 17, 2012

Adventure of the Week: The House of Seven Gables (1979)


It took me a while to track down Greg Hassett's The House of Seven Gables adventure for the TRS-80 -- some online archives have what appears to be a machine-language version, but that game is actually Bill Miller's House of Thirty Gables, in a very different style from Hassett's games.  Like Miller's game, this one bears remarkably little resemblance to the classic Nathaniel Hawthorne novel, House of the Seven Gables, aside from the fact that the house that serves as the game's setting does indeed feature a number of gables.  I knew this was the right code as soon as I saw the title screen: 




Like most of Hassett's early adventure games, this one is written in BASIC and has a rather limited vocabulary.  It still performs pretty well, and it's fun to play, if a little obtuse when it comes to scoring.  The game seems to be introductory in nature, given the copious hints available within the game itself; the source code was published in the Captain 80 Book of BASIC Adventures.  A version also exists for the Commodore 64.

As always, I encourage interested readers to try The House of Seven Gables before proceeding below.  It's a treasure hunt set in a mysterious house, and it's not a hard game to finish, really, though earning all of the points can be a challenge.  Beyond this point, in the interest of documenting my experience with this game, for those who have already played it or may never get to do so, be advised that there are comprehensive...

***** SPOILERS AHEAD! *****



The story begins outside of a house with, naturally, seven gables.  There's a doorbell and a compass we can take with us.  We can't TAKE COMPASS, but we can GET COMPASS, and we can't look at it, examine it, or read it.  So it may not be very useful, except that -- aha! -- we can't maneuver anywhere without it -- no exits are displayed, so we do need to keep it in hand.  Most adventure games take directional navigation for granted, so young Mr. Hassett deserves credit for turning this into a minor puzzle.

The game is very player-friendly -- if we try to go S, we are told THE DOOR IS LOCKED. I THINK I CAN GET BY IT, THOUGH.  And if we try and fail to OPEN DOOR, then we learn that MAYBE THESE PEOPLE (?) ARE FRIENDLY, SO TRY RINGING THE BELL.

Upon RINGing the BELL, we are swept inside and the entrance vanishes.  We are in a living room, with no objects visible, and can explore to the south, east and west.  The Dining Room contains an empty bucket and some silver candlesticks.  We don't seem to gain any SCORE points after we get the candlesticks, so maybe they are not a treasure.

The kitchen contains SOME FRESH GARLIC, a BANANA, and a SINK WITH A WORKING SPICKET [sic].  Mr. Hassett's spelling was often... inventive.  The spelling is the same in the listing in the Captain 80 book, although there the text is in mixed-case unlike this version; it may have been typed in by a TRS-80 owner without an uppercase kit installed, like many of us back in the day.

A door east of the dining room has no doorknob or keyhole, but again it is suggested that we can get by it.  KNOCK DOOR doesn't do the trick, though.  And HIT DOOR returns I DON'T WANT TO HIT THE DOO.  Neither do I, sorry for suggesting it!

The Guest Room right off of the living room leads to the first and second gables.  There's a BLACK CAT at the second -- if we try to GET him, he vanishes, SAYING "I WILL RETURN..."

South of the living room, in a dark closet, A HOLLOW VOICE SAYS: MIX THEM.  This is yet another early adventure game influenced by Scott Adams' approach.

Downstairs is a long east/west hallway.  At the east end is DRACULA'S CHAMBER.  We can try to OPEN COFFIN, but THE VAMPIRE WON'T LET ME!  He's listed as a MEAN LOOKING VAMPIRE, to boot.  Why aren't there ever any friendly vampires in these games?

The Barren Library contains a BOOK TITLED PRIMEVAL WITCHCRAFT; I don't think that word means what Mr. Hassett thinks it means.  The book is very short, reading NOTTUB SSERP, or PRESS BUTTON backwards.  But there's no button in the library.

This sort of thing occurs at random:



Ahem.  After self-consciously checking my attire, there's only one turn before THE GHOUL KILLS ME!  This was the first death I ran into; restoring, I made it past that room with no ghoul appearing, and found my way to a DUNGION [sic] where A CRUDE NOTE ON THE WALL READS: YOU CAN'T GET OUT WITHOUT KILLING ME FIRST! -- WITCHY-POO.  No wonder the Bay City Rollers couldn't get out of their Saturday morning contract with the Krofft brothers!  This isn't actually true, at least if we take it at face value, as while most paths return to this same location, we can just go S to exit the dungeon.  The dungeon entrance doesn't really lead to a maze, it seems, but there's a real maze nearby, also at the west end of the hallway, containing an AXE.

Randomly during our explorations, we may see that A GHOST POPS OUT AND SAYS: THROW ME SOME TREASURE!  He'll accept our gift if we THROW CANDLESTICKS, so apparently scoring is just deferred; clearly, we should avoid this situation if possible so we can earn all the available points.

The hallway maze leads to a MAD SCIENTIST'S LABORATORY where we can pick up some chemicals.  Presumably these are what we want to mix.  If we MIX CHEMICALS they turn into AN ORANGE BUBBLING LIQUID.  We can FILL BUCKET with water using the kitchen's spicket [sic], though this doesn't seem to be necessary for working with the chemicals.  And when we run into the GHOUL we can THROW CHEMICALS so that THE GHOUL MELTS TO NOTHING.  But eventually it comes back.  Fortunately, the chemicals also remain intact, we can just pick them up each time and reuse them later.

I did run into a small bug -- at a couple of points I tried to GET AXE after finding or dropping it, and was told I couldn't carry any more; but after an INV check, I was able to; some counter must get cleaned up when we take a look at our inventory.

Returning to the interior locked door with the axe, we can't SMASH DOOR but we can CHOP DOOR so that THE DOOR IS CHOPPED TO PEICES [sic].  This leads to a staircase, with A BEAUTIFUL ROSE at the top.  There's also a BROOM CLOSET, with some VALUABLE RECIPIES [sic] written IN WITCHISH.

The sixth gable contains a PAPER AIRPLANE; the third, a TEST TUBE OF FLUID (which is neither a TEST TUBE nor a TUBE, but FLUID per the game's dictionary.)

Another hallway south of a DILAPIDATED BEDROOM leads to a MAMOTH [sic] ART GALLERY where we can pick up a PRICELESS REMBRANT [sic].

At the eastern end of the hallway is A ROOM WITH A PEDESTAL IN THE MIDDLE, and we can see a button atop the pedestal.  Even if we haven't read the book in the library, it's tempting to PRESS BUTTON here (actually, PUSH BUTTON doesn't work so the book's clue is actually kind of helpful). 

This leads to the WITCH'S CHAMBER, where an UGLY WITCH has a POT OF WITCHES' BREW, in case there was any question; where the other witches are who are apparently responsible for the brew remains an open question.  The Books of Oz tell us what to do - THROW WATER and THE WITCH HAS VANISHED! HER HAT REMAINS.

With the witch's hat in hand, we can return to the LIVING ROOM.  And the entrance door has been reopened, so we can just go N.  And suddenly, we've won!  (So that's what the witch's note meant.  Odd of her to invite her own death that way.)



Except... I haven't done very well scorewise -- yes, that is actually a negative 70 points -- and there's no opportunity to continue.  It looks like we need to ignore the red herrings, and carry as many treasures as possible out the door as we take our one shot at exiting.  Basically, it appears we need to grab the compass, fill the bucket, mix the chemicals, kill the witch, collect all the valuable treasures and leave the house.

So what puzzles remain to be solved?  There are a number of objects we haven't experimented with yet.

We can EAT BANANA to be left with a BANANA PEEL.  It looks like a slip-and-fall may be in someone's future. But whose?  Random ghoul appearances continue to be a pain, as the creature can arrive long before we have an opportunity to acquire the chemicals.


We can SHOW GARLIC to send the vampire scurrying off, and claim a SULTON'S [sic] DAGGER from his coffin.  He shows up again at the top of the stairs, at which point we need to STAB VAMPIRE so that he dies and vanishes; why he was keeping this dangerous dagger in his own bed is another unanswerable question.

I also notice that my once-SHINY COMPASS has become A TARNISHED OLD COMPASS while playing, though this seems to have no bearing on our score at the end of the game.

The ghost will eventually kill us if we don't throw him a treasure when he demands it; I didn't find any solution to this, we just have to be quick about our business and hope the random number generator looks kindly upon us.

We can UNFOLD AIRPLANE to turn the paper airplane into A PIECE OF PAPER WITH WRITING ON IT.  It reads: "REMEMBER THE WIZARD OF OZ."  So we've already figured that out.

Down from the pedestal room is the Seventh Gable, with a DIAMOND in it; I had just missed exploring that direction, after seeing the button on the pedestal.  The WITCHY-POO note room is still not a maze, just a room whose exits all lead back to itself; it does not change state after the witch is dead, so the note refers only to our ability to leave the house itself.

It seems that if we are not efficient, our score drops dramatically.  I was down to -595 points at one point, and dropping by 25 points per turn!  I wish I knew what the object of the game was, or had some way to determine which items were the critical treasures!

Fortunately, Dorothy's walkthrough at CASA indicates that the AXE, HAT, REMBRANDT, ROSE, RECIPES and DIAMOND are the treasures, and that we don't need to carry them with us -- just drop them in the living room before we escape the house.  So playing quickly, we can pick up all the valuables and escape to a proper victory:




The House of Seven Gables is not a particularly difficult game; the biggest complications stem from all the red herrings (I never did find anything useful to do with the black cat) and a few random unsolvable situations that can present themselves at inopportune times.  I'm slowly working my way through the Greg Hassett oeuvre, and I enjoyed this one.