Thursday, December 23, 2004

The Lord giveth, and the Lord taketh away

So I got semi excited that my chess was actually playing semi fast (relative to the suckiness of Flash). That was before I added in the castling, enpassant and check rules, which should be no big deal right?

Castling, piece of cake. No performance hit
enPassant? No biggie either
check rules? Oh I'm sorry, Flash sucks remember?

Lets back up a bit, I got semi around the bitboard problem by creating the standard 8x8 array to represent my board, and while that was indeed time consuming, I also implemented a little bit of code that would move and then unmove pieces while the computer thought about what to do. This worked immensely faster than array copying, because array copying in flash is horridly slow. Not too mention it means I'm not storing each board position, and hence, use less memory (and Flash really blows at managing memory). If I had say, 900 boards of 64bits for a bit board, thats not exactly a whole lot of ram to worry about when you are using Gigs. Turn that into 900 8x8 arrays for flash, even with a miniscule amount of info stored in each array position, and its gonna get hurt, badly. It completely drove my system into the ground trying to manage it all. If I had my way, I think I would have used bitboards for the computations and still used a move/unmove system, with maybe 1 "backup" board in the memory per leaf node (which would then be erased upon leaving the leaf completley).

So, back to topic. No bit boards means no fast computations, and of course in chess, you need to make sure your king isn't in check (or mated). I originally started looking at every opponent piece for side X, to see if they could attack row A col B (where the king is) but that was not an acceptable solution as it took too long. So I worked the problem backwards, for some good gains. At row A col B, where could I move to if I was a rook,queen,bishop. If I could move and the square was occupied, was it an enemy piece? And if so, was that piece the corrosponding one to get back to the king location? This works quite well (of course, you slightly alter this for pawns) as a king "sealed" off by its own pieces yields very little check work. If we look at the standard set up (turn 1, white to move):

rnbqkbnr
pppppppp
--------
--------
--------
--------
pppppppp
rnbqkbnr

The "old" way (my first attempt) had me looking at 16 pieces, many of which would have a ton of moves (IIRC the average is 30 something total possible moves, I want to say upper 30s, but don't quote me).

The new way, in this case, has me looking at 5 squares. Much, much better no? Worst case is 27 squares to look at with the king isolate and can be attacked along an entire rank / file / diagonals. An unlikely setup, but better than 30 some odd combinations. And if the game has progressed to the end, there aren't very many pieces left anyway, which means a small (hopefully) first tier leaf.

Ok, so, even tho I made these gains, they still aren't quite enough. 2 moves ahead its taking nearly 2 minutes to complete. Why? Because the extra time spent on making sure the king is or isnot checked for 900 boards (or so) really adds up :(

Santa needs to deliver a better Flash (with binaries as big as I'd like)

0 Comments:

Post a Comment

<< Home