Compact Computer Format for Storing Shogi Boards

These are the notes on the very compact format I came up with for storing shogi boards when writing computer programs dealing with shogi. I wrote this format around 2003. Feel free to reuse as permitted by the license below.


Board representation:


*** bits needed=480 (or 60 bytes)
*** 12 bits per token


attribute: krbgslnp color promotion board_or_reserve_location
bit count: 3        1     1         7


----------------------



bits reference:

2 4 8 16 32 64 128 256


----------------------

type of token: krbgslnp in 3 bits

king  : 0
rook  : 1
bishop: 2
gold  : 3
silver: 4
lance : 5
knight: 6
pawn  : 7



----------------------

color: in 1 bit

black token: 0
white token: 1


----------------------

promotion: in 1 bit

unpromoted token: 0
promoted token  : 1


----------------------

board_or_reserve_location: numbering in 7 bits

 9  8  7  6  5  4  3  2  1
+---------------------------+
|8  7  6  5  4  3  2  1  0  |a
|                           |
|17 16 15 14 13 12 11 10 9  |b
|                           |
|   You get the idea ... 18 |c
|                           |
|                           |d
|                           |
|                           |e
|                           |
|                           |f
|                           |
|                           |g
|                           |
|                           |h
|                           |
|                           |i
+---------------------------+
White reserve: 81
black reserve: 82





Copyright (c) 2014, Terrance Gene Davis All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. Redistributions in binary
form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials
provided with the distribution. Neither the name of japanesechess.net,
Samurai Chess, Gene Davis Software nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.