Digging through old code: Chess program
There is a lot of waiting for parents at a chess tournament (see Eliminating Fire Alarm sound at Chess Tournament Awards Ceremony). I had my computer, and I was asked if I had a chess program on it.
The answer is a little bit complicated: I wrote one over 2 decades ago that still works on Windows XP.
I looked in a zip file of old programs that I wrote and I found the source code of my old moldy chess program dated 1984 for the original IBM PC In those DOS days, the OS didn’t do very much for the programmer.
I had to write my own mouse driver and pulldown menu system because this was way before Windows. I remember trying to decide what happens when a mouse click pulls down a menu and moves off the menu: should the menu close? Should there be a single mouse down to activate the menu and a single mouse up over the current item would choose that item?
I had to decode the serial inputs of the 1200 baud optical VisiOn mouse (with its own metal mouse pad).. I used my Heathkit Oscilloscope to look at the raw RS-232 serial signals coming from the mouse and figuring out what they meant.
My code wrote directly to the IBM PC CGA Graphics card. 0xB800 was the base address.
I used my cartoon animation program (I wrote a cartoon animation program around 1982 on an original 4.77 MHz IBM PC (it’s reincarnated in Visual FoxPro: start the Task Pane, Solution Sample, Forms, Form Graphics, Line Animation). You could draw a single picture, save it, draw another picture, save it, then choose to animate, which would morph one picture to the other using interpolation) to draw the chess pieces with the mouse and record the vectors that made up a chess piece.
In fact, here’s what my Pawns looked like in vector graphics:
struct dat {
char x0,y0,x1,y1;
} pawn[] = {
2, 22, 23, 22,
23, 22, 21, 20,
21, 20, 14, 19,
14, 19, 16, 16,
16, 16, 17, 12,
17, 12, 14, 8,
14, 8, 18, 6,
18, 6, 17, 5,
17, 5, 14, 4,
14, 4, 14, 3,
14, 3, 13, 2,
2, 22, 4, 20,
4, 20, 11, 19,
11, 19, 9, 16,
9, 16, 8, 12,
8, 12, 11, 8,
11, 8, 7, 6,
7, 6, 8, 5,
8, 5, 11, 4,
11, 4, 11, 3,
11, 3, 12, 2,
0, 0, 0, 0
I wrote my version of the Bresenham algorithm for drawing vectors.
It’s actually not too hard to write the chess program logic itself: you just need a move generator to create all possible moves, a position evaluator to give each position a score, and a tree pruning algorithm because the trees are so huge.
The program was written for a 4.77 MHz PC (see Why was the original IBM PC 4.77 Megahertz?), which had 256 k RAM and no hard disk. I remember trying to get each position to fit into exactly 16 bytes, so that memory management was simple: recall that with the 16 bit segmented architecture of the 8088 processor, a segment register pointed to 16 byte long segments.
Some of the more difficult chess issues:
- Detecting a 3 duplicate move draw
- Representing castling queenside and kingside
- Capturing En-Passant (only allowed on the very next move after the opponent moves a pawn)
- Changing the static board evaluator for beginning, middle, and end games. Control of center squares has less weight at the end game
- Bishop vs knight value in opening, middle, end games.
- When to prune the search tree: in some cases it would look a dozen moves ahead (a dozen levels down the tree).
The program was designed to “think” for about 3 minutes, then move. It would generate positions and use the static board evaluator to rate each position.
Interestingly enough, and a testament to Windows backward compatibility, I can run the same binary code on my machine today. It runs blazingly fast and finishes a 40 move game in about 3 seconds because the processor is way faster today (see My toys over the years) However, the pulldown menus and the mouse driver predate and are thus incompatible with Windows.
Comments
Anonymous
January 06, 2008
Hey nice site you have. Anyways I just thought I'd chat about some new chess software I found lately. Its called chess analysis pro 7000. Its very good in analyzing your chess games for blunders. It also trackes your chess ratings. I liked the little book that came with it too. Yes I'd recommend this item.Anonymous
April 22, 2008
Hey Nice Site. Anyways just thought ide give a few chess tips. 1. Choose an opening thats solid. One that offers opportunity for you. 2. Aim for a mid game position that is better for you. One where you can exploit the best of your talent. 3. If possible aim for a continuation to your attacks. This keeps the pressure on your opponent. I used this tip successfully my self for year.and still use them.Anonymous
June 09, 2009
PingBack from http://greenteafatburner.info/story.php?id=5557Anonymous
June 17, 2009
PingBack from http://thebasketballhoop.info/story.php?id=3490