## move structure

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, Dann Corbit, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
smatovic
Posts: 1612
Joined: Wed Mar 10, 2010 9:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic
Contact:

### Re: move structure

would be a reasonably efficient way to generate moves.
I dont get it. What is the content of nextMoveTable ?

Edmund
Posts: 668
Joined: Mon Dec 03, 2007 2:01 pm
Location: Barcelona, Spain
Contact:

### Re: move structure

smatovic wrote:
would be a reasonably efficient way to generate moves.
I dont get it. What is the content of nextMoveTable ?
I once wrote a similar move-generator .. maybe it is of any help to you. It is a retro-move generator but in principle you should get the idea.

Code: Select all

``````int mgen_backward&#40;int color, int * curpc, int * curdir, int * curshift&#41; &#123;

for (;*curpc < pccnt&#91;color&#93;; (*curpc&#41;++) &#123;
U8 curpcflag = pcflag&#91;*curpc&#93;;
int curpos = pcsq&#91;color&#93;&#91;*curpc&#93;;
int curpct = pct&#91;color&#93;&#91;*curpc&#93;;

for (;offset&#91;curpct&#93;&#91;*curdir&#93;; (*curdir&#41;++) &#123;

(*curshift&#41;++;
int newpos = curpos + offset&#91;curpct&#93;&#91;*curdir&#93; * (*curshift&#41;;

if (&#40;newpos & ~63&#41; ||															// newpos on the board
(!&#40;table_move&#91;curpos&#93;&#91;newpos&#93; & curpcflag&#41;) ||								// newpos reachable for current piece
(&#40;curpct == KING&#41; && &#40;table_move&#91;newpos&#93;&#91;pcsq&#91;!color&#93;&#91;0&#93;&#93;&pcflag&#91;KING&#93;)) ||	// kings may not stand next to each other
(&#40;occ&#91;0&#93;|occ&#91;1&#93;|bbSQ&#91;pcsq&#91;0&#93;&#91;dynid&#93;&#93;) & bbSQ&#91;newpos&#93;) ) &#123;					// occupied newpos square
*curshift = 0;
continue;
&#125;

pcsq&#91;color&#93;&#91;*curpc&#93; = newpos;
return curpos;

&#125;

*curdir = 0;
&#125;

return -1;
&#125;
``````

hgm
Posts: 25448
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

### Re: move structure

smatovic wrote:I dont get it. What is the content of nextMoveTable ?
nextMoveTable[0][currentMove] would contain the (encoded) move to try after currentMove in case the toSquare of currentMove was occupied, nextMoveTable[1][currentMove] the one to try if it was empty. For leapers that would be the same, but for sliders the first would be the first step of a new ray, and the second the next step along the same ray.

There should be an encoding for 'invalid', to indicate that you are done with the current piece, and can start with the next. I forgot to include the test for that in the code I gave.

smatovic
Posts: 1612
Joined: Wed Mar 10, 2010 9:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic
Contact:

### Re: move structure

Ok, i got a clue how this works....will think about that.

smatovic
Posts: 1612
Joined: Wed Mar 10, 2010 9:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic
Contact:

### Re: move structure

...ran some tests...packing and unpacking lowers performance significantly.