Javascript Chess

I’ve been fiddling with Facebook lately. One of the first things I did was install the developer application so that I could have a go at building some new apps for it. I then read a Slashdot article about the daft terms of the Facebook developer licence and promptly removed it again.

However, I kept thinking - what applications could I write? Eventually I hit on two ideas. The first one is a Facebook version of “Janken”, or “Paper, Scissors, Stone” for anyone who didn’t waste their youth trying to beat “Alex Kidd in Miracle World”. The second idea is Facebook chess.

The Janken idea is pretty simple, and it works much like the various Poke applications. Anyone who has the application installed has a “Janken” box containing three new links added to their profile - “Paper”, “Scissors” and “Stone”. Click one of them and an alert is sent to the profile’s owner. The owner isn’t told which option was clicked; they are just told that someone has begun a Janken game. They then visit the profile of the other person and do the same on their profile. The system then works out who won, and adds a new message to each player’s profile: “A beat B at Janken: A’s X wraps/cuts/blunts B’s Y!”

The chess idea, as you’d expect, works like postal chess. Start a game, make a move, then wait for the next player to make their move. The app could keep a log of all moves and use AJAX for its interface, eliminating pesky postbacks.

A quick search through the Facebook apps reveals that someone’s already done chess (there are a few problems with it, but on the whole it does a good job), but no-one’s done Janken. I installed the dev app again and discovered that not only do the Facebook guys get to kick me off their server and keep my application should they so choose, but it seems that they also expect me to host the database for my app on my own server.

Deleted the dev app again and gave up on the idea.

The chess thing got me thinking, though, and an hour later I’ve got 80% of a chess engine running in 300 lines of Javascript:

JS Chess

Things left to do:

  • Pawn movement is incorrect
  • Pawn taking is incorrect
  • Castling not implemented
  • Check/checkmate not implemented