Reply
 
LinkBack Thread Tools Display Modes
  #1   Report Post  
Old April 15th 10, 08:37 PM posted to rec.games.chess.computer
nun nun is offline
external usenet poster
 
First recorded activity by ChessBanter: Jul 2008
Posts: 2
Default Back to computing : how to represent a move by a number ?

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef & hash.
  #2   Report Post  
Old April 15th 10, 09:51 PM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Apr 2005
Posts: 292
Default Back to computing : how to represent a move by a number ?

On 2010-04-15, nun wrote:
For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ?


3446 == b5 x c6
2546 == a4 x c6
etc....

--
Chris F.A. Johnson http://cfajohnson.com
Author: =======================
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
  #3   Report Post  
Old April 15th 10, 09:55 PM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Nov 2007
Posts: 232
Default Back to computing : how to represent a move by a number ?

On 4/15/10 12:37 PM, nun wrote:
For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef& hash.


Um in 1 byte you can represent the source 3 bits for x, 3bits for y....,
destination the same way. so you can do this in 2 bytes, or what most
machines use for 1 integer. There are probably some programming tricks
for move legality, and move generation.

--
If it doesn't fit on a bumper
sticker, Republicans can't un

Clave in RGP
  #4   Report Post  
Old April 16th 10, 02:42 AM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Jul 2006
Posts: 625
Default Back to computing : how to represent a move by a number ?

* nun (21:37) schrieb:

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef & hash.


The easiest way is to have it contain the source square, the target
square, the captured piece and the promotion piece. Piece values are
optimally so, that a zero specifies no piece.

That way you only need three operations for specifying a normal move.

6 source square
+ 6 target square
+ 3 captured piece
+ 3 promotion piece
= 18 bits

fits well into a 32 bit integer.

IIRC that's the way crafty does it.

mfg, simon .... l
  #5   Report Post  
Old April 16th 10, 02:46 AM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Oct 2009
Posts: 10
Default Back to computing : how to represent a move by a number ?

On 4/15/2010 2:37 PM, nun wrote:
For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef& hash.


There are no standard ways because many programmers change things to fit
their program structure.

It also depends on whether you are using a 8x8, 10x12, 12x16, 16x16 or
some other size board. (And sometimes you may even have more than one
board or representation. Sometimes it's just more convenient that way.)

To represent a move usually involves whatever square numbering system
you pick for your program.

On an 8x8 board (like for bitboards), A1 might be square zero and H8 be
square 63. Or you might have any of the four corners to be square
number zero, with the numbering progressing horizontally or vertically.

Then you would just do something like: From x 64 + To

So A1 to B1 would be 0 * 64 + 1 = 1.


Generally, but not always, a person will choose a square numbering
method where the columns are a power of two (like an 8x8 board, a 12x16
or a full 16x16 board). This makes it easy to get the rank & file from
a square number.


As to "hash a move"... I assume that's just accidental terminology.

You might want to look at the computer chess programming wiki.

http://chessprogramming.wikispaces.com/






  #6   Report Post  
Old April 16th 10, 09:16 AM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Jul 2006
Posts: 1,015
Default Back to computing : how to represent a move by a number ?

Simon Krahnke wrote:
* nun (21:37) schrieb:

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef & hash.


The easiest way is to have it contain the source square, the target
square, the captured piece and the promotion piece. Piece values are
optimally so, that a zero specifies no piece.

That way you only need three operations for specifying a normal move.

6 source square
+ 6 target square
+ 3 captured piece
+ 3 promotion piece
= 18 bits


You only need 2 bits for the promotion piece P - Q, R, B, N
And only 6 states of captured piece are used " ", P, N, B, R, Q
It may be advantageous to have a code here to signal an EP capture.

There is obviously something wrong if you find QxK is possible.

I actually use a padded board use the direct index into that rather than
the 0-63 style index. It is nice to fit it all into 32 bits.

En passant rules cause a lot of grief in move generators.

Regards,
Martin Brown
  #7   Report Post  
Old April 16th 10, 11:40 AM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Nov 2007
Posts: 232
Default Back to computing : how to represent a move by a number ?

On 4/16/10 1:16 AM, Martin Brown wrote:
Simon Krahnke wrote:
* nun (21:37) schrieb:

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef & hash.


The easiest way is to have it contain the source square, the target
square, the captured piece and the promotion piece. Piece values are
optimally so, that a zero specifies no piece.

That way you only need three operations for specifying a normal move.

6 source square
+ 6 target square
+ 3 captured piece
+ 3 promotion piece
= 18 bits


You only need 2 bits for the promotion piece P - Q, R, B, N
And only 6 states of captured piece are used " ", P, N, B, R, Q
It may be advantageous to have a code here to signal an EP capture.

There is obviously something wrong if you find QxK is possible.

I actually use a padded board use the direct index into that rather than
the 0-63 style index. It is nice to fit it all into 32 bits.

En passant rules cause a lot of grief in move generators.

Regards,
Martin Brown


There are certain move generators, that do not consider check until the
move generator actually captures the king, so the x K state needs to be
kept. Fortunately, you have one bit still in the captured state for the
King.

Also since en passant is not physically possible, way more often than it
is not logically possible, there are certain move generators, that do
not check which moves are game logical, until after all the possible
moves, such as en passant are generated. Often times, it is not until
the move is moved or about to be moved into the tree as a possible, that
the rule is checked.

Neither of these are requirements, but sometimes you do things for speed
that otherwise seem "backwards".

--
If it doesn't fit on a bumper
sticker, Republicans can't un

Clave in RGP
  #8   Report Post  
Old April 16th 10, 02:40 PM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Jul 2006
Posts: 625
Default Back to computing : how to represent a move by a number ?

* Martin Brown (10:16) schrieb:

Simon Krahnke wrote:
* nun (21:37) schrieb:

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ? Please no puns about beef & hash.


The easiest way is to have it contain the source square, the target
square, the captured piece and the promotion piece. Piece values are
optimally so, that a zero specifies no piece.

That way you only need three operations for specifying a normal move.

6 source square
+ 6 target square
+ 3 captured piece
+ 3 promotion piece
= 18 bits


You only need 2 bits for the promotion piece P - Q, R, B, N


But if that's another piece representation than the already used one,
you only get one bit for the need of a mapping.

And only 6 states of captured piece are used " ", P, N, B, R, Q


In binary there is no difference between 6 states and 8 states.

It may be advantageous to have a code here to signal an EP capture.


If captured_piece == PAWN and target == ep_square

There is obviously something wrong if you find QxK is possible.


Yeah, that means the board is illegal. I actually used this as way of
finding out about illegal boards, immediately exiting the move generator
with a special return code.

I actually use a padded board use the direct index into that rather than
the 0-63 style index. It is nice to fit it all into 32 bits.


For bitboards 6 bits is enough, for 0x88 you need 7 bits.

En passant rules cause a lot of grief in move generators.


Why? Just generate a pawn capture on the ep square.

These special cases of chess cause more trouble to the move doer and
undoer.

I just did a quick one:

,----
| def do move
| r = [ @flags, @ep ]
| @ep = -1
* other = (@to_move^-1) + 2
* set_piece move.from, Piece::NONE, 0
* set_piece move.to, move.to_piece, @to_move
| if move.piece == Piece::P[@to_move] and ? move.from and move.to == move.from + 2*PAWN[@to_move]
| @ep = move.from + PAWN[@to_move]
| elsif move.piece == Piece::P[@to_move] and move.captued_piece == Piece::P[other] and move.to == r[1]
| to = move.to - PAWN[@to_move]
| set_piece to, Piece::NONE, 0
| elsif move.from == E1
| @flags &= (WHITE_KINGSIDE | WHITE_QUEENSIDE)^-1
| if move.piece == Piece::K
| if move.to == G1
| set_piece H1, Piece::NONE, 0
| set_piece G1-1, Piece::R, WHITE
| elsif move.to == C1
| set_piece A1, Piece::NONE, 0
| set_piece C1+1, Piece::R, WHITE
| end
| end
| elsif move.from == E8
| @flags &= (BLACK_KINGSIDE | BLACK_QUEENSIDE)^-1
| if move.piece == Piece::K
| if move.to == G8
| set_piece H8, Piece::NONE, 0
| set_piece G8-1, Piece::R, BLACK
| elsif move.to == C8
| set_piece A8, Piece::NONE, 0
| set_piece C8+1, Piece::R, BLACK
| end
| end
| elsif move.from == A1
| @flags &= WHITE_QUEENSIDE^-1
| elsif move.from == A8
| @flags &= BLACK_QUEENSIDE^-1
| elsif move.from == H1
| @flags &= WHITE_KINGSIDE^-1
| elsif move.from == H8
| @flags &= BLACK_KINGSIDE^-1
| end
* @to_move = other
| return r
| end
`----

I put a * in front of the four lines that don't treat special cases.
Most of these special cases deal with castling: flags maintenance and
rook movement. The code doesn't even address the question of legality.

Only 5 lines deal with en passant.

Looking at this i found two unnecessary tests and I could replace all
these elsif move_from == witch a case statement. Any input is welcome.
:-)

mfg, simon .... l
  #9   Report Post  
Old April 17th 10, 08:38 PM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Apr 2010
Posts: 1
Default how to represent a move by a number ? Thanks

On Thu, 15 Apr 2010 14:37:02 -0500, nun wrote:

For programming is there a standard way to represent or hash a move,
eg Bxc6, to an integer ?

Thanks to all for helpful suggestions. By "hash" I meant putting the
text move, ie 'Bxc6', through a hash function. Choosing such a function
would be difficult as the moves are so short & similar there would be a
lot of "hash clashes" or collisions.
Years ago I programmed a _simple_ chess engine in Pascal. Now I'm
working in Python. Dave WB3DWE
  #10   Report Post  
Old April 17th 10, 09:51 PM posted to rec.games.chess.computer
external usenet poster
 
First recorded activity by ChessBanter: Jul 2006
Posts: 625
Default how to represent a move by a number ? Thanks

* (21:38) schrieb:

Years ago I programmed a _simple_ chess engine in Pascal. Now I'm
working in Python.


You seem to like programming languages with names starting with P.

mfg, simon .... l
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plz analyze game between ChessChallenger7 & Easy Level Offramp rec.games.chess.computer (Computer Chess) 29 January 17th 10 11:06 AM
Plz analyze game between ChessChallenger7 & Easy Level Offramp rec.games.chess.misc (Chess General) 10 January 11th 10 06:07 AM
rgc Tournament PGN Rob rec.games.chess.misc (Chess General) 81 March 4th 07 06:14 AM
RGC chess tournament Rob rec.games.chess.analysis (Chess Analysis) 19 February 14th 07 10:48 PM
USCF Issues Forum: "February Board Meeting" [email protected] rec.games.chess.politics (Chess Politics) 0 February 10th 07 06:55 PM


All times are GMT +1. The time now is 07:30 PM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 ChessBanter.
The comments are property of their posters.
 

About Us

"It's about Chess"

 

Copyright © 2017