Chess math

If you’re like me, you may have said, “When would I ever need this in the real world?” sometime during grade school. While it may be true that you may not ever need that bit of information again, it doesn’t hurt to know about it.

For instance, a few months ago I started getting into chess again and decided that I wanted to attempt at making my own online chess software. One of the initial problems I faced was how to validate a whatever move a piece made. First I went through some ideas about coding a specific instruction set for each piece, however I happened upon a stroke of brilliance. Why not use math, specifically slopes, to validate a move?

There was one problem though, I could not for the life of me remember how to do slope equations. It’s just one of the many things that did not stick in grade school. (But remember, I knew about the idea!) So off I went in search of study guides and tutorials on slope equations.

As with much of my techno-research, I started out at Wikipedia which ended up answering my questions and taught me what I needed to know. I don’t care what other people may say, Wikipedia is an excellent starting point to finding anything really specific about a subject.

Enough blather, here’s some code. Note that there is still stuff to be done and some methods are stumps because either they need to be, or they’re just not done yet.

pieces.php This file holds the actual definitions for each chess piece.
class.piece.php This is the piece class file. Pieces.php depends on this.

As you can see, there aren’t really any comments on how the stuff works. But I’m sure those of you that care will be able to figure it out.

One Comment

  1. Posted May 13, 2007 at 9:26 am | Permalink

    Cool idea, and a great start! I look forward to following the progress!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*