Not exactly chess

Continuing from yesterday, I’ve been playing around with ideas about how to make original games that are like chess, but not exactly chess.

Today I sketched out a little interface, just to get a feel for what it might be like to create such games. It’s not finished yet (for one thing, you can’t yet play the game that you design), but noodling around with what I have so far should give you a sense of it.

As you can see in the image below, on the right are the different options for how a piece can move. You can mix and match such things as whether a piece can move by just one square or by any number of squares, or can travel in one, two, four or eight directions, or whether those directions are even or odd directions.

On the left side of the image, you can see the different kinds of pieces. Eventually I should provide a way for a piece to look like a king, queen, bishop, knight, martian, or Godric of Gryffindor, but for now the way the way a piece looks reflects the way it moves — just like the diagram in yesterday’s post.

The first six pieces on the left column are initialized to move like a pawn, knight, bishop, rook, queen and king, respectively. The last two pieces are something else entirely: one can move just one square at a time left or right, and the other slides any number of squares forward or back.

But the interface lets you redefine any piece to move in some other way. Click on the image below to link to the applet, and start designing your own game!



Making chess

Doug’s commented on my “Practicing chess” post, saying that he’d like to write a program to show where the “dangerous” moves are — the ones where your piece could be captured — started me thinking about the whole process of writing computer programs to implement games.

The thing about programming computers is that you always find yourself not just wanting to solve one problem, but rather to say “hmm, this is an interesting kind of problem. I wonder what general set of problems it falls into.” That’s also the thing about doing math, by the way.

So as I started thinking today about what Doug said, I found myself wondering “how could you make it possible for somebody to define the rules for a whole bunch of games — even their own original games?”

Thinking about it that way, I realized that defining the rules for chess isn’t all that complicated. There is “core chess”, which has almost ridiculously simple rules. And then there is “evolved chess” — those extra rules that got added over time to make the game more interesting. Evolved chess has added just the five following rules:

   — Pawns can move two spaces forward on their first move.
   — The en passant rule for pawns capturing pawns.
   — Pawns capture on the diagonal.
   — The “castling” move for a king and rook.
   — Promoting a pawn when it gets to the end of the board.

Except for the above few extra rules, chess has only the following few core rules for how its pieces move:

   –Which directions a piece can move.
   –Whether a piece moves (i) to the nearest space, or (ii) any distance.

That’s because chess pieces always move in some regular pattern of compass directions around a circle. For example, a Rook or Bishop can move in only four directions, whereas a Knight or King or Queen can move in eight directions, and a Pawn can only move in one direction.

The complete set of rules for core chess can be expressed as a simple table:

     Rook:    

4, even, any

     Bishop:    

4, odd, any

     Queen:    

8, even, any

     King:    

8, even, nearest

     Knight:    

8, odd, nearest

     Pawn:    

1, even, nearest

What the above table says is that the Rook moves in any of four even compass directions (North, East, West, South), to any distance. The Bishop moves in any of four odd compass directions (NE, NW, SW, SE), to any distance. The Queen moves in any of eight even compass directions (N, NE, E, SE, S, SW, W, SW) to any distance.

Meanwhile, the King moves in any of eight even compass directions to the nearest square. The Knight moves in any of eight odd compass directions (NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW) to the nearest square. The Pawn moves in only one compass direction (North) to the nearest square.

So if you wanted to give somebody a way to create their own original board game, you could mostly just let them fill out their own version of the above table, one for each kind of piece they want to have.

If we did that, then who knows? Maybe some natural game-making genius out there will come up with an original game that’s incredibly cool.

Face time

I was thinking today how nice it felt yesterday to create an “as simple as possible” program to practice chess.

And I started thinking that it might be nice to apply the same philosophy to an animation system. What would be the simplest possible tool to let people easily create animated stories about characters and relationships?

So today I wrote a little program, just a sketch really, of what something like that might look like. Click on the image below to try it out.



Practicing chess

There are hundreds of programs on-line for playing chess. But this afternoon a friend told me that she couldn’t find any on-line program that does a very simple thing: She would like to play practice games, moving all the pieces herself, while trying different variations.

I asked her why she doesn’t just use a real chess set. She told me that she can’t accurately remember all of the moves she’s made, so with a real chess set she couldn’t go forward and backward through her game.

It seems silly that there is nothing like that on-line (well, maybe there is, but neither she nor I could find it). So I told her I’d just write a little program to get the job done.

It wasn’t so hard because my program doesn’t actually need to know the rules of chess — my friend already knows the rules of chess. So the program is perfectly happy to let you make illegal moves. It really doesn’t care.

But whatever moves you make, the program lets you go forward and backward through your game to revisit your own game play, which is all my friend really wants. Besides, writing it was fun. 🙂

Click on the image below if you’d like to try out my rather minimalist chess practice program:



Prime directive

I was quite excited at the prospect that 2011 might be a prime number. I happened to be at my computer, but not on the internet, so I wrote a little computer program to run through the factors of 2011. If a number has no factors other than itself and 1, then it is prime.

Sure enough, my program told me that 2011 is indeed a prime year. Yay!

Of course the moment I got on-line, I could just Google it, using 2011 and prime as the search words. Sure enough, 2011 pops up on the very first hit (Wikipedia’s list of the first 1000 prime numbers).

The program was very simple (it took maybe 30 seconds to write), but I find it sad that I can’t easily share my joy of discovery, since unless you already know Java, the code I wrote will look to you like gobbledygook:

    for (int i = 1 ; i <= 2011 ; i++)        if (2011 % i == 0)            System.out.println(i);

If I translate this into a friendlier looking programming language, it might look like this:

    for every I from 1 through 2011
       if 2011 mod I is 0
          print I

That’s almost ok, except that people who don’t already know programming will get stuck at that second line. So let’s replace it with something even friendlier:

    for every I from 1 through 2011
       if 2011 is divisible by I
          print I

Ah, that’s more like it! Meanwhile, if you’re a more advanced programmer, you can peek to see how the computer is told what “is divisible by” means, again in this friendly computer language:

    A is divisible by B means
       the remainder of A divided by B is 0

Now we have something that anybody reading this blog can understand. And in my mind that was actually the program I wrote — except that as I typed the program, I automatically changed it into Java programming, sort of the way a pianist might transpose music from one key to another.

Maybe it would be a good idea to make it very easy to create these sorts of conversational programming Mad Libs (such as: “for every — from — to — ” or “the remainder of — divided by — “). Then it would be easy to write a program that anybody at all could read (or maybe even write), but which would still run on a computer.

Maybe we should hurry up and do that, while it’s still a prime numbered year. 🙂

Response to “A Mathematician’s Lament”

A poem in response to Paul Lockhart’s “A Mathematician’s Lament”, inspired by the mathematical doodles of Vi Hart.


Inside a box a triangle sits,
Somewhere, perhaps in your mind’s eye,
Wide as the box, and just as high.
In short, the triangle barely fits.

t0

What will the triangle’s area be?
A quarter of the box? Or maybe a third?
More than the box? No, that’s absurd.
Hmm, there’s a game here, you can see.

t1

A curious game — but how to play?
Maybe you should draw a line.
To split the triangle, that looks fine,
From top to bottom, all the way.

t2

Now two boxes sit astride
Where there had only been just one.
Twice the shapes means twice the fun!
And each contains more shapes inside.

t2b

The leftmost box is cut in half –
A line is slicing it in two.
Now equal shapes jump out at you.
It’s enough to make you laugh.

t3

For on the right it’s just the same.
Your triangle, you can say with pride,
Takes half the box’s space inside.
It seems that you have won the game!

t4

Candies all the way down

One problem with musical candy buttons is that sooner or later you run out of space to put all of the notes. Or, if you’re hungry, you might run out of notes altogether. Imagine you’re right in the middle of composing a delicious symphony in the key of Grape (I mean, um, in the key of B flat), and suddenly you run out candy buttons — or worse, you even run out places to put your candy buttons.

Never fear, there is a way out. In honor of the late, great Benoit Mandelbrot, I hereby introduce fractal musical candy buttons! I don’t have an interactive Java applet ready for you to play with quite yet. My eventual plan is to give you a way to zoom in and out, and otherwise navigate through the fractal score.

But I can show you a visualization of how such a space might look. Around the central tonic pitch (Peach), I’ve arranged half sized candy buttons representing the other six notes in the same key. Around each of these are still smaller candy buttons, and so on, ad infinitum.

Once I implement a way to let you zoom into this space, then there will be infinite melodies for you to explore, in an endless variety of colorful (and tasty) musical possibilities.

But that will probably have to wait until next year. 🙂



Candy button musical space

I thought it would be nice to give you a way to create your own original candy button musical space — something between a musical score and a musical instrument.

I’ve also started decorating the candy buttons, because everybody knows that low notes and high notes taste quite different, and you wouldn’t want to eat the wrong note! Candy buttons in the second octave now have little hearts painted on them. Candy buttons in the third octave have little painted stars.

As you can see in the image below, the top and right edges are all the flavors in the key of C major. The left and bottom edges are all the flavors in the key of C# major.

But you can try it for yourself. Click on the image to link to the on-line Java applet:



Counterpoint

Xiao’s helpful comments have encouraged me to iterate yesterday’s design. Rather than using words in the buttons of the latest little candy button music machine, I’ve adopted the philosophy of “less is more”, and have switched over to pictorial icons. This way the machine will be equally useful (or useless) everywhere in the world.

I also added a speed slider, so you can run the machine fast or slow or even backwards. As usual, you link to the applet by clicking on the image below.

Meanwhile, I’m thinking that making music with candy buttons would make for a very nice board game. The general idea might be that you have to play a melody to advance in the game — a kind of mash-up of Simon and Candy Land.