Playing Against the Computer


Background

The Pretzelves is a one- or two-player game for the Commodore 64 where two "Pretzelves" skates around an ice rink and collect presents in different colours (that magically appear on the ice for some short time) according to their respective "wish list" of colours. The presents must be thrown into the player's "Santa sack" to make it count. There is also a set of other items and obstacles that appear randomly on the ice. A more detailed text on this can be found here: Making the Pretzelves Come Alive

One or two players

When the idea for The Pretzelves first came up, the main focus was a two-player game with "skating elves throwing snowballs and catching Christmas presents," a game you could play with friends and have a nice time.

As the development progressed and the game idea got clearer, the question came up of what to do with those playing alone. One idea was to have a one-player mode where the player only competes against the clock was proposed, but as a programmer, there is a challenge in making a computer-controlled player that gives the human player(s) a nice, balanced, challenge.

The player controls are essentially divided into three steps:

  1. Get the player input (horizontal, vertical, and throw)
  2. Adjust the speed according to the player input and check for collisions with the ice rink boundaries (bounce player if hitting a "wall")
  3. Move the player according to its speed

This makes it easy to simply replace the first step from reading a joystick to getting the desired direction from an AI instead - the rest of the player movement will be handled in the same way regardless.

Enter AI

Since the computer player "wins" if the time runs out, the main goal could have been to just obstruct the opponent, but that would not make the game much fun. Instead, the following goals are used:

  1. Get the presents on the wish list into it's own Santa sack
  2. Hinder the opponent from getting its presents into its Santa Sack
  3. Put any power-ups or other items into the sack

States

To achieve this, the following states were initially implemented:

  1. Look for a present from the wish list on the ice (if more than one desired present is found, choose one randomly)
    1. If found, skate towards it
    2. If not found go for the opponent (if a desired present appears on the rink, the state may be changed to 1a instead)
  2. If the wanted present is picked up, head for the Santa sack and try to throw the present into the sack
  3. If any other object is picked up during skating towards the target (be it the present or the opponent), handle it according to type:
    1. Snowball or bomb -> Head towards the opponent and throw the item from a distance
    2. Clock, snail, or pretzel -> go to it's own Santa sack and try to throw it in
    3. Unwanted present -> just throw it away
  4. In later stages, if the opponent only has a few presents left on their wish list, the computer Pretzelf will very likely aim for the opponent instead of looking for a present (random)

The navigation is simply a target coordinate (the wanted present, the opponent, or a point near the own Santa sack) and adjusting the direction to go to that target. The only exception is the rink with an "island" in the middle, where the computer Pretzelf always tries to go the nearest way around the "island". 

Being too Good

These few states and in a way quite simple behavior turned out to make a formidable opponent, and it was really hard to win even on the very first level, so some dumbing down had to be done.

  1. Lower the top speed for the computer Pretzelf for the first levels
  2. Add a random offset to the target coordinates, the range of the random offset gets lower as the player reaches higher levels
  3. An idle state is added which means the computer Pretzelf will go to a random coordinate on the rink instead of hunting the player. The idle state is selected less frequently as the player reaches higher levels.

These additions made it possible to adjust the "cleverness" of the computer Pretzelf and make it, in a way, more human - we tend to make mistakes every now and then, and by adding the randomness this happens to the computer Pretzelf as well. 

In Summary

Adding a computer-controlled player is always a fun challenge, and the main work is to

a) Decide on a strategy for the computer-controlled player and (in this case) formulate a limited set of states that is manageable but still gives a decent amount of variation in behavior

b) Make the behavior "human" in some way. Adding randomness to some of the parameters controlling the player is one way that is feasible even in the limited world of old 8-bit computers.

Hopefully, this reading will give You an extra dimension for thought when playing the game.

Get The Pretzelves

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.