best board representation for variants (javascript) ?

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, bob, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
Posts: 234
Joined: Sat Jan 17, 2015 10:54 pm

best board representation for variants (javascript) ?

Post by MahmoudUthman » Sun Dec 10, 2017 1:54 pm

In your opinion what is the best (most convenient) board representation for move generation only , that can be easily made to support arbitrary variants with the least amount of coding effort (javascript) ?

User avatar
Posts: 25025
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller

Re: best board representation for variants (javascript) ?

Post by hgm » Sun Dec 10, 2017 8:53 pm

Least coding would be a 1-dimensional array containing the piece types, with a 0x88-type square layout (i.e. gaps between the ranks), and a band of boundary guards around it to prevent pieces could jump off board. You can generate moves from that with a triply mested loop, over the board to find pieces, then over directions the piece moves in, and then (if it is a sliding move) over the number of steps taken in that direction.

This is not very efficient, though, as you spend a lot of time locating your own pieces on the board. And captures are only generated as the last move of a slide, meaning that you basically always generate all the moves, even if you only want captures. There are ways to enormously speed up the move generation, but they all add code complexity.

User avatar
Posts: 2929
Joined: Fri Jan 21, 2011 11:42 pm
Location: NL

Re: best board representation for variants (javascript) ?

Post by Evert » Mon Dec 11, 2017 8:22 pm

Mailbox with piecelists. You can do generalised 0x88 for alignment tests by making the in-memory board twice as wide as the actual board.

That's what I'd do anyway.

Post Reply