move structure

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: move structure

Post by smatovic »

would be a reasonably efficient way to generate moves.
I dont get it. What is the content of nextMoveTable ?
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: move structure

Post by Edmund »

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(int color, int * curpc, int * curdir, int * curshift) {

	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;
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: move structure

Post by hgm »

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: 2658
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: move structure

Post by smatovic »

Ok, i got a clue how this works....will think about that.
smatovic
Posts: 2658
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: move structure

Post by smatovic »

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