Adrian Herbez Rotating Header Image

algoclass: week 1

As I work my way through Stanford’s excellent online class on the design and analysis of algorithms, I’ve decided to up the ante a bit on the homework assignments- not only will I do the stated assignment, but I will also wrap it up in some manner of game or game-like interactive demo. This is the first such demo.

This week’s assignment was to implement merge sort and then to modify the merge sort implementation to count the number of inversions (or out-of-order numbers) in an array of integers. Inversions are useful, as they allow two lists to be compared, with the number of inversions functioning as a metric of how similar they are.

In this game, the goal is to guess the correct ordering of the eight colors. Each time the page starts, a random order is selected. To play, try to guess what it is by clicking on the color swatches to the left in an order of your choice. Once you’ve ordered the eight colors, you’ll see a small version of the order with a red/green bar at the bottom. The red/green bar corresponds to how far away you are (number of inversions / max possible number) from the correct order. The game (although a very hard, possibly unfun one) is to use the information about past guesses to inform your choices.

jsdemo: void

I finally got around to playing Bastion this weekend, thanks to the always-amazing Humble Bundle.

I thought that the way in which the ground rose up to meet the main character was particularly beautiful, and decided to try my hand at recreating it in javascript, and this was the result. The arrow keys move the character around in the world as ground tiles rise up to greet him, and objects (well, an object, a television) falls from the sky.

Click on the image to see if for yourself. Art for the character and the television came from opengameart.org.

jsdemo: Plants

I was at a really great open studios event in Hunter’s Point, and saw some beautiful paintings that included (amongst other things), undulating plant forms.

I thought it would be fun to try to recreate such things but via code, and animated.

To see it in action, click on the image.

Ludum Dare: Tiny World

I just participated in my first Ludum Dare competition, with the theme ‘Tiny World’. My game is a bit small, even by Ludum Dare standards, as I’m currently on vacation, so only had the plane ride, plus a bit of time here and there to work on it (not that I’m complaining 😉 ).

In the game, you take on the role of a planet builder, tasked with creating planets from matter floating through space. The game lies in rotating the planet so that the matter is evenly distributed, and rejecting matter of the wrong type (each level has different requirements for the planet).

To play the game, either click on the image, or go here.

Rule 30: the game

I recently bought a conus textile seashell to give to a young relative of mine that loves science. Conus Textile shells are really cool, because the pattern on their surface is almost identical to that created by a simple 1-dimensional cellular automata with 30 as the ruleset. But instead of just giving her the shell, I wanted to make her earn the gift through a game-like exploration of cellular automata, with the shell being the big reveal after she’s completed it.

This is a first pass at such a game. At the start, a single line with random state is presented to the player, along with a blank line. Mousing over any of the cells will highlight the three previous cells that determine the state of the mouse-over cell, and clicking on the cell will toggle its state. Once all of the cells in the new line are correct, a new line is added to the display. Over time, the distinctive pattern found with rule30, and on conus textile shells, will emerge.

Doods

This was a little, one-night experimental project that grew out of poking around with the excellent Flash Devekop IDE. The result was a proto-game where a bunch of little doods wander around the screen. I added a couple of rules that, while not really making it a game, do make for a fun little system to poke at, namely:

  • If a given dood happens to find himself close to the mouse pointer, he will stay near it
  • If the mouse moves too quickly, the doods will lose it and disperse
  • If the user clicks, all of the doods under the mouse will be frozen (stop moving) for a period of time. Frozen doods are blue
  • The more doods that get frozen, the longer the duration of the freeze

All in all, it means that there’s a kind of proto-game to be had in moving the mouse around the screen slowly to gather doods and then clicking to freeze them in place. Definitely not a game, but kinda fun to play with.

To play with it yourself, head here. Also note that the graphic for the dood came from the always-awesome Open Game Art site.

Collectible Dart Game: paper prototype

I was playing Magic: The Gathering recently with a friend at a local bar that so happens to have a dedicated darts room.

That got me thinking- why not have a collectible darts game? After some thought, I nailed down a rough draft of a design, with the following elements:

  • The collectible/swappable component is the fins of the dart (“flight”) on which is printed stats and abilities
  • The setting/theme of the game is future fantasy, with players competing to mine resources from a planet (the dartboard) by sending units down to the surface (throwing darts)
  • All units have:
    1. a mining stat, combined with the value of the section the dart hits to determine amount of resources gathered
    2. a combat stat, used to resolve combat between units
    3. [optionally] an activated ability of some kind, for example: [R] + 5 to mining, which would mean that if the dart lands inside a red section of the board, it earns 5 extra units of resources
  • Play proceeds with players alternating to throw darts
  • Combat is resolved at the end of a round, and the resource totals are added to each player’s running tally
  • The first player to gather a set number of resources (100?) wins

I’m still thinking through the combat system, but in the meantime I wanted to be able to generate some prototype pieces to start playtesting. As such, I wrote a small Python program that accepts a text file describing units and generates a printable PDF that can be used to make flights. I’ll likely be changing the design of the flights a bit (altering the shape and making them slightly bigger), but it’s a good start. To see the generated PDF, go here.

More fun with OpenSCAD

So I’ve been having a great time with OpenSCAD of late, and made a couple of small models:

  1. a parametric Lincoln Log-style building piece (with options for diameter, length, and number of slots)
  2. a die-like cube for tracking damage in World of Darkness pen-and-paper RPGs

I love OpenSCAD, and I also love thingiverse. To check out the models and download them for yourself, head over to my thinigiverse profile.

Binary rings (via OpenSCAD)

So a while ago, I started in on a project to create a tool for generating wearable ring models with text encoded in binary based on the ASCII values of each character. I put the project aside a while back, but recently I discovered OpenSCAD, a fantastic tool for programmatically defining 3d models.

OpenSCAD totally rocks, but is a little strange in that variables aren’t, strictly speaking variable, since you can’t change their value. As a result, instead of writing openSCAD directly, I created a Python script that takes a string as a command line argument and generates the OpenSCAD code to make a ring with that phrase around it. The above image encodes ‘OpenSCAD rocks my world’.

The next steps are to make the script take a ring size and thickness, and then I’ll likely be setting up shop on Shapeways to sell these.

Projection party game (Things)

This was a small project I put together for my girlfriend’s birthday party. She wanted to play a party game whereby:

  1. a topic is presented
  2. each player writes out a response
  3. all the responses are read aloud (with ensuing hilarity)
  4. everyone tries to guess who said what

I put together a web-based version of the game that we then projected onto the wall of her living room. The game is controlled by a strip of controls along the bottom of the page which, when presented fullscreen, is cut off by the way I had the projector set up.

The controls allow for a new entry to be entered, with both the name of the person that said it and what they said. Only the actual statement is shown, with the name being hidden. Once everyone has submitted their answer, the ‘Reveal N’ button steps through each answer, revealing who said what.

The topics come from a simple MySQL table, but new topics can also be entered on the fly via javascript (to allow for audience suggestions). If you would like to try it, head here, or click on the image above.