Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Minimum Number of Bytes - encode castling within kings coordinates

Author: KarinsDad

Date: 20:33:39 12/23/03

Go up one level in this thread


On December 23, 2003 at 22:22:25, Reinhard Scharnagl wrote:

>Hi KarinsDad,
>
>a comprehensive solution always would be a better solution.
>
>There is a solution (complex translation table), which I would like to be
>substituted by a more intuitive, before I would fix that idea then.
>
>Your solution (in my opinion) is no solution. Because if one king is able
>to castle, the other is not and HAS BEEN PLACED SOMEWHERE on the board, his
>coordinate (different from original position) vanishes by your encoding.
>
>Reinhard.

Yes of course. I was only listing some of the cases.

However, it does not change the number of bits needed.

In 12 bits (4096 possibilities), there are 484 illegal positions (i.e.
wka1/bka1/bka2/bkb1/bkb2 as 4 examples). To calculate this, it is white king in
4 corners * 4 black illegal king squares. Plus, white king on 24 edge squares *
6 black illegal king squares. Plus, white king on 36 inner squares * 9 black
illegal king squares. 4*4 + 24*6 + 36*9 = 484.

Each of the 3612 legal positions (4096-484) all represent themselves where
neither king can castle.

The remaining cases are:

1) white king on e1, black king not on d1/d2/e1/e2/f1/f2/e8 = 57 * 3 possible
white castling possibilities (the white cannot castle possibility for all legal
black squares has already been taken care of) for a total of 171 cases.

2) black king on e8, white king not on d8/d7/e8/e7/f8/f7/e1 = 57 * 3 possible
black castling possibilities (the black cannot castle possibility for all legal
white squares has already been taken care of) for a total of 171 cases.

3) white king on e1, black king on e8, 15 possible castling cases (the cannot
castle for both kings on e1/e8 respectively case has already been handled).

For a total of 3612 + 171 + 171 + 15 = 3969 cases which can be stored in 12 bits
(3969 out of 4096).

When doing position compression though, the idea is to basically ignore how
difficult it is to get the data into or out of the bits (that can be solved once
the compression encoding schema is determined), but merely to figure out which
compression does it to the smallest number of bits.


Granted, the encoding/decoding algorithms are not as simple I stated earlier,
but you can actually do them in code without too much difficulty (and without a
bunch of if/else or switch statements). For example, one way is to create a 2
dimensional 64x64 array of booleans (i.e. transposition table) for all
white/black pairs and set the booleans to true if legal and false if not legal,
then iterate through the illegal boolean array pairs in some set order of legal
castling positions to assign the rest. When you get to your current "at least
one king can castle position" (regardless of which case it is) in the list
(based on the iteration order you picked), you have your encoded number. Do the
exact same calculation for decoding (when the number matches the 12 bits, you
know which case it is ...).



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.