Archive for November, 2007

List abbreviations

November 23, 2007

Since List is a basic and very usefull data structure of Lisp, so there are several ways to create lists. I whould like to discuss some subtle details of the subject.

Book “How to design programs” at Section 13 Intermezzo 2 says that
‘(1 2 3)
abbreviates to
(list 1 2 3)
but later it says that
‘(a b c)
abbreviates to
(list ‘a ‘b ‘c)
See the difference ? symbols are quoted, and numbers are not! Why that difference ?

It turns out that a single approach could be taken: to quote everything. It works, because quoting a number doesn’t produce a symbol, but a number itself, so (+ ‘1 ‘2) evaluates to 3.

More interesting issue is that ‘(a b c) is not perfectly the same as (list ‘a ‘b ‘c). In my interpreter, I’ve made it completelly different. For parser, first expression is a sequence of quote and a list of three elements, and second is a list of four elements.

Evaluation is also different. For first expression, quote allows evaluator to treat the following item as data, so a list of three symbols created by parser is simply re-used. Second expression is a procedure appliance, so first arguments are evaluated, then they are passed to list procedure, which returns a list of three elements. Then evaluator uses first expression in form returned by parser, it contains raw parser data: symbols and lists, and each time it evaluates symbol it first checks if symbol should be converted into number. This is a good test:
(symbol? (car ‘(1)))
evaluates to #f

My implementation handles this expression in following way: parser creates list for expression text, which consists of symbols and other lists. Then evaluator starts evaluating expressions. quote returns list generated by parser, which contains symbol “1″, then car extracts that symbol, and then procedure symbol? checks if it is a number.

Second approach, which is probably better, whould be to let parser recognize numbers. It should be more performant, then to convert symbol to number every time it is accessed. Third approach is to perform conversion once in evaluator, then replace symbol with number in that list. However, this last approach doesn’t eliminate checking if symbol is a number every time real symbol is accessed

So, I see three implementation strategies, which provide similar results:

  • Parser builds representation for expression from lists, symbols and numbers. Quote simply returns that list
  • Parser builds representation for expression from lists and symbols. Quote simply returns that list. Symbols are converted into numbers then they are accessed.
  • Parser builds representation for expression from lists and symbols. Quote treats lists in special way (recursively)

Unifying define-struct

November 16, 2007

My initial impression of Lisp in whole and Scheme in particular is that lists are used as general-purpose data structure. But sometimes it could be more convenient to access structure member by name, not just by “cddar”. Writing accessor functions manually is long and boring way. While reading HtDP I discovered “structures” – the thing I was looking for. Declaring structure automatically generates constructor and selector functions. However, structures are not portable between Scheme implementations. Compare:

Scheme implementation syntax
PLT (define-struct structname (field1 field2))
ChezScheme (define-structure (structname field1 field2))
Gambit (define structure name field1 field2)

So, writing portable code which uses structures was not possible for me.

Later I understood that “define-struct” is often mplemented using Scheme macro facility. It automatically generates code for constructor and selector functions which you otherwise whould write yourself, so it is just a “productivity feature” on top of Lisp basic primitives. But, since “define-struct” is a macro, then I also can use macros to make a common definition for “define-struct”!

I decided to use PLT syntax as common. After that I needed some macroses which will convert my common syntax to syntax which already implemented on each platform. Of course, PLT doesn’t require any special transformer. So, I’ve started to learn macro language. I can’t say I became a master, but my aim is achieved.

Here is a R5RS-style macro for ChezScheme, which works fine:

(define-syntax define-struct
  (syntax-rules ()
    ((define-struct name (fields …)) (define-structure (name fields …)))
  )
)

Unfortunatelly, my macro for Gambit is not working:

(define-syntax define-struct
  (syntax-rules ()
    ((define-struct name (fields …)) (define-structure name fields …))
  )
)

Problem with Gambit is that it doesn’t support define-syntax natively. You need to (load “syntax-case”). But then aboveshown macro is executed, it reports error which I don’t know how to fix.

Gambit also has Common Lisp-like macro facility called “define-macro”. After some time I came with following, which seems to work:

(define-macro (define-struct name fields)
  (cons ‘define-structure (cons name fields))
)

Now I have unified syntax, and can write code which will work on any of those implementations.

Ravenloft 2: Stone Prophet

November 12, 2007

This game is a sequel to “Ravenloft: Strahd’s possession”, and it doesn’t have any significant differences. Still, in 1996 it was a good game, so I’ve completed it then and also now to refresh my memories.

This time party is trapped in desert similar to ansient Egypt (but without a Nile) called Har’akir. Desert is big: developers were trying to create a big seamless world, and almost succeeded. A desert is surrounded by “wall of Ra”: area of very hot air which hurts party if they will try to escape. At the middle of desert there is a village of Muhar, where party can rest and store their equipment. Again, like in previous game, there are no money and shops. In the desert around a village there are numerous buildings and ruins left from the days then Har’akir as a powerfull kingdom. It was ruled by very powerfull pharaon named Ankepot who wanted to become immortal, but became crazy instead. He started a conflict with priests of Ra, and they killed him. Ankepot was turned into mummy, but he was so powerfull that even in his dreams we was sending disasters on land and priests of Ra. Finally, great priest of Ra was also turned into mummy, and Har’akir become a spiritual battlefield between pharaon and high priest, who send winds and diseases on people. As with other Ravenloft settings, land itself often lures new victims, who should work hard to find a way to escape. Local people don’t like aliens, so they will not be very helpful.

Second part is different from first part in that player can explore the land in any order he wants. However, all locations have to be explored to finish the game: a trick is called “collect all pieces of puzzle”. This trick is also used locally at many levels: collect pieces of dictionaly to be able to translate a prophecy, collect 8 tears of RA to get a key, collect serpent figures to open doors. Other levels are more linear: explore part of labyrinth and find a key which opens another part of labyrinth holding another key, and so on. Well, then I’ve said that all locations could be explored in any order I was wrong: some locations (sphynx, pharaon’s rest, royal burial hall and basement of temple of harwest) are opened with objects located in other locations. All places are labyrinths, so gameplay are almost the same as in previous game. It helps a little that labyrinths are smaller and corridors are more straight and wide, because they represent palaces and temples instead of mines and caves. Wall textures are more bright and have better resulution, with egyptian-style paintings everywhere. Improvements over previous game include: lightning in levels, windows, pits.

Main area is a one big desert. At the beginning I recommend to explore it by walking. Later party can find teleportation keys, which help to travel fast from one area to another. It is not easy to navigate being surrounded by sand, but automap can help. Desert is a good place to get initial experience: desert zombies and vultures are easy enemies. But be carefull with dust devils and manscorpions

There is a plot which guides players at the beginning through easy locations: go to blind women, then to temple of Nefertity, help injured women to get to village, explore the village to get equipment and a map, return to temple of Nefertity, then return to blind women, then go to obelisk. Obelisk is hard, so players can get easy experience in temple of harvest or in temple of Set. After Obelisk player can go anythere. I recommend to visit temple of Ra at the end, then player gets some rings of fire protection.

Switch-based puzzles do present, but are minor compared to item-based puzzles. There are many clues, so puzzle solving should not be complex. Sometimes you can get into a room which you are unable to exit because you don’t have a nesessary item. In this case, use teleportation key to get out.

This game was also a CD-rip, so I’ve missed most of video cutscenes. So, I don’t know that is hidden in bottle of thoughts, and what players learn in world of dead. However, this seems not very important, since I was able to complete the game.

A conclusion: game is better then it’s predessor: graphics is more beautifull, style is very good, plot is also better. However, it is still hack-n-slash RPG with maze-navigation. Recommended for fans of previous game

Some strategy hints:

  • Oinments help to cure poison and desease. Always have some of them!
  • Snakes usually attack in numbers. Use “burning hands”, “scorcher”, “ice storm” or other area-damage spells
  • Fire elementals are back, this time even more dangerous. They could be defeated with “cone of cold”, “ice storm”, “lightning”, “magic missile”
  • Party formation has changed: two members to the center are in front, two members who are to the edges are back

Ravenloft: Strahd’s possession

November 9, 2007

“Ravenloft” is a not-so-bad role-playing game I first completed in 1996 then again completed in 2007 to refresh my memories. By current standards it is not very good, and I whould not recommend playing it now.

Game was originally developed in 1994 and has strong similarities to “Eye of beholder”. It uses special VGA mode with doubled vertical resolution, so graphics is less blocky then of other games of that age. Graphics is a main appealling point of game: faces have striking style, inventory and some wall textures are drawn very beautifully. At the time that game was quite an advancement technically: first-point party-based RPG with smooth rotation, wide field of view and high resolution.

This game is placed in most-known scenario of Ravenloft setting: Barovia. It is ruled by count Strahd, who became vampire to be forever young and win the love of woman named Tatyana. However, she preferred Stahd’s younger brother, so Strahd has killed him. Then woman commited suicide by falling from castle walls. Because of Stahd’s bad deeds Barovia was taken from real world and turned into separate realm, with borders guarded by poisonous mists. Strahd has biggest power in his domain, but he wants to escape. Sometimes, by power of wizardry, people are able to get into Barovia or get out, but such cases are rare.

Game starts far away from Barovia, with party sent by Lord Dhelt to retrieve stolen amulet. Party succesfully defeats the thief and discover amulet along with some strange magical items. There is also a note which reveals that thief stole amulet because he thinks that it is an artifact which is able to defeat somebody called “Strahd”. Then mist comes and transfers party to some strange place, with all artifacts lost. It is unclear who are characters hidden by mists.

Party starts explorations inside dangerous forest. There are remains of house with cellar where party can safely rest. Forest is inhabited with goblins and worgs (big wolves). Here party can also pick up first NPC. Later party moves to big road, meets some brigands and finally comes to village of Barovia. Everything is dangerous and dark, there are very few helpful people, brigands roam village at night. This game doesn’t have any consept of “money”, there are no shops, so party should just keep only best items and throw away all ordinary weapons and armour. By talking with some NPC and reading some books/scripts party learns that evil lurk the land and it’s name is “Strahd”.

At village party should be carefull, because game contains a problem: if party is posessed with ghost of jeweller too early, then it will be impossible to complete the game. Village of Barovia is a good place to explore, just be carefull and save often.

Main friendly spot of village is a tavern. Party can safely rest there and get some information. There is also a house of burgomaster, who informs them that “Strahd” is a count who rules the land, and he wants to meet with party. By accepting the invitation party goes to castle, and surprizingly sees quite pleasant and peacefull man. He informs them that there is no simple exit from Barovia, and he himself is searching for teleport out. He provides party with location of one teleport and a key. Party goes to some caves, and there they meet cleric and fighter who must join. Caves are dull and boring labyrinth, where player must fight numerous skeletons and locate keys. Some areas are hidden behind false walls, there are also hard-to-find switches. Enemies are easily defeated using cleric’s spell “turn undead”. Finally party locates teleport, but it is a fake, and both fighter and cleric will leave the party. I’ve played a CD-ripped version, so I’ve missed some of game’s video sequences, and plot is not very clear for me.

Accepting an invitaton and exploring caves is a good idea, because skeletons are weak enemies good to increase party’s experience. Other areas are better to explore after that, then party becomes stronger.

After failure at caves party can use a key to church which they find in caves to continue their search for way out. Church is destroyed, but it is possible to rescue some priests, who tell that Strahd is evil. After exploring all possible areas, getting all possible experience and best weapons, party is left nothing then try to enter castle Ravenloft. At this point it is clear that Strahd is evil, and rules his land with iron fist. There are also traces of many mages who give clues on their attempts to destroy him or various ways to escape Barovia. It seems that thief was collecting amulets which were beleived to be a weapons against Strahd. Defeating of Strahd becomes party’s main quest.

At castle party is attacked by Strahd’s servants. This is a good place to explore. Bone golems seem hard, but they are easy victims to “turn undead” spell. At the top of one of castle’s towers party frees a wereraven, who in return helps them to meet with Barovia’s underground who fight against Strahd. They tell to party a secret of powerfull amulet called “symbol of ravenkind”. Theif was thinking that Lord Dhelt’s amulet was this symbol of ravenkind.

To get amulet party needs coins which could be used to by potion which allows to go past mists. After heavy fighting party gets an amulet, and now they can go and face Strahd directly. Then Strahd is defeated party can pick up Lord Dhelt’s amulet. It is not clear how Strahd got it. By coinsidence, amulet is a required item for returning home by using “trimia’s catalogue”.

Game has good atmosphere, dark and fearfull, with lots of undead enemies. There are not many cool weapons, but there is some cool armour. Gameplay is rather repetitive: most levels are mazes, which party has to fully explore in order to advance. Exploration often means looking for hidden buttons. Mazes are hard to navigate because they age big, and walls are dull. There are very few non-linearity, very few side-quests, very few gameplay except maze navigation and monster fighting. Plot is also not very rich. So, it was probably a good game for it’s time, but definetely not for now. It a hack-n-slash game in the same way as “Eye of Beholder”, with very little place for strategy and adventure.

Some strategy hints:

  • As I already mentioned, use cleric’s spell “turn undead” often. It’s very powerfull!
  • Some enemies reduce character’s levels. Be carefull, fight from distance, and save often
  • Projectile weapons can help. There are some magical arrows, sling and throwing knife
  • Fire monsters (elementals, dogs) are best defeated with non-fire magic, such as lighting or magic arrow
  • Use map. Mark locations of teleporters, it will help
  • I don’t know how to use “Rod of smiting”
  • Some races and classes have ability to detect secret walls
  • Use “detect magic”, then “impoved identity” to find out magical items
  • Party has up to four members, moving in square formation: two left characters in front, two right characters behind. Enemies who stand in front of you will attack only two first characters. At open areas all party members can hit. In houses/caves two rear (right) characters can hit only with spells or long-ranged weapons (spears, halberds, quarterstaves, two-handed swords, bows, slings), so they don’t need to carry shields. You can move characters to put well-defended close-range fighters in front, and magic-users to the back.
  • Some areas have “rotators”: your party instantly starts to face in opposite direction. Be carefull, in some mazes walls are so dull that it is hard to notice that your party was rotated

Hints for running this game:

  • This game works quite well under DosBox
  • I’ve played ripped version of game. It has some video sequences missing. Sometimes I even had error messages like “file not found”. These messages are caused by those missing video files. You can cheat by making a copy of existing video file under different name. Video files are named “cinexx.anm”. You can use this trick to see all available video sequences: just get to a place in game where some video should be shown, and then keep replacing original video file with other different videos
  • There are several patches for a game. Applying those patches restores copy-protection by asking words from manual. Cheating against this system is easy: all answers are located together with questions in file “code.2″

Sonic vs Donkey Kong

November 9, 2007

In this article I’ll compare my opinions about two very well-known 2D platform games for 16-bit consoles: “Sonic the hedgehog” and “Donkey Kong country”. Those games were released on different consoles (“Sonic” on Sega Genesis, “Donkey Kong” on SNES), but I don’t think that’s important, because both consoles have more-or-less comparable characteristics, so each game could be ported on another console. The reason why that has not happened is simple: Sega and Nintendo, producers of consoles, were making more money from consoles than from games, so they wanted those games to be exclusive to add more value to their consoles then to make profit from selling game ported to rival console. So, rivalry between consoles become rivalry between games. “Sonic” was developed by Sega itself, “Donkey Kong country” was developed by Rare, long-time partner of Nintendo. Both “Sonic” and “Donkey Kong” become “killer games”: games what made console worth buying. Producers of those games tried to make their best to produce true hit. The effect, in my opinion, was not an advantage of one console over another, but advantage of 16-bit consoles in general compared with 8-bit consoles.

Just to show that both consoles are quite equal in their technical capabilities, consider third-party games such as “Mortal Kombat”, “Flashback” or “Lost vikings” which were released on both consoles, and look almost the same.

Rivalry between consoles had one important reason: kids were allowed money to get only one console, so they should choose carefully. Fortunatelly, now we have emulators, and we can enjoy all good games which existed on both consoles. At 90ths I didn’t own neither Sega Genesis nor SNES, so I’m writing my impressions of playing those games in modern times.

So, let’s compare “Sonic” and “Donkey Kong country”. I’ll start with similarities. Both games are typical 2D platformers: main part of gameplay is walking and jumping in attempt to reach end of level and collect as much bonuses as possible. Typical obstacles are touch-to-die enemies (usually patrolling some area), walls and pits. Both games are similar in that they are “peaceful” games: playing characters don’t carry guns, they defeat enemies by jumping or rolling on them, or just avoid them. Sonic is even more peacefull because all enemies are robots, and defeating them is an act of good because it saves small animal imprisoned inside.

“Sonic” has cartoonish colourfull, bright and sharp graphics with animated backdrops. Graphics of “Donkey Kong country” is smoother and more volumetric, without animation in backdrops. Both games start in bright forest area to impress players from beginning, later stages are more ambient. In my opinion, “Sonic” tries to impress player with amount of colour and animation on screen, while “Donkey Kong country” – with pre-rendered graphics itself, which is more beautiful and stylish in my opinion.

Main difference is the essence of gameplay. Sonic has big levels and emphasizes speed. Levels are non-linear, so players can spend their time exploring them to get more bonuses. If player doesn’t want to collect all bonuses, he can, in most cases, quickly run through level, crashing through enemies and flying over dangerous areas. Sometimes speed is a key to reach some difficult-to-access areas, which hold more bonuses. Really challenging task is to hold overall layout of level in the head, because levels are big and complex. Trampolines can send you jumping really high. But actions of player are very limited: there are only direction buttons and single button for jumping. Levels are grouped by thee sharing the same gamepay and appearance.

Gameplay in “Donkey Kong countrly” is more carefull and “strategic”, and less-dependant on reflexes: levels are more enemy-packed, sometimes player needs to bounce of enemy to reach bonus or safe passage. There are two characters with slightly different abilities, and player can choose one which is more suitable for task. Many helpfull things are hidden, but there are lot of clues, so exploration is very rewarding. There are heplfull things like barrels which work slightly similar to weapons. Variations also include: swinging on ropes, jumping of fixed or rollable tires, swimming, shooting from barrels, moving inside mine-cart, climbing on ropes, riding on animal helpers, and more.

Both games try to increase replayability by usage of bonuses, secret rooms, secret shortcuts, mini-games. Approach taken by “Donkey Kong contry” is best: they have complex and connected world, and player can return to areas he already completed to get additional “lives” by collecting bonuses, so bonus-hunting, not important at the beginning then player just wants to advance further, becomes important later. Number of secrets in “Donkey Kong country” is much bigger than in “Sonic”.

So, my conclusion is: while Sonic looks impressive with brite and sharp graphics, amount of animation, level size and gamestyle consisting of quick running and far jumping, after some time it is felt as more repetitive, more stupid, more dull, more empty and more childish for me. “Donkey Kong country” tries to add essence by making gameplay more strategic, environment more stylish, smooth, volumetric and breathing, story more humorous. However, both games are great, and represent state-of-art in 2D “hop-and-bop” style platformers, and stull fun to play nowdays. Highly recommended!

PS: if you like really in-depth analisys of platform games, read this article