move structure

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

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

Re: move structure

Post by smatovic » Sat Jun 19, 2010 4:08 pm

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

Post by Edmund » Sat Jun 19, 2010 4:26 pm

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: 23790
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: move structure

Post by hgm » Sat Jun 19, 2010 5:06 pm

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

Re: move structure

Post by smatovic » Sat Jun 19, 2010 5:37 pm

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

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

Re: move structure

Post by smatovic » Mon Jun 21, 2010 6:13 pm

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

Post Reply