⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movegen.c

📁 牛角棋的源码
💻 C
字号:

//movegen.c

#include <assert.h>
#include "data.h"


/*
************************************************************************
MoveGen procedure
******************************
	着法列表中的move格式如下:

	含义:	   |piece|    to     |
	bit:	     5  4  3  2  1  0
*************************************************************************
功能描述:调用MoveGen()产生一个着法列表。在[addr1,addr2-1]之间的着法,构成当前局
面的着法列表。其中,addr1是第ply层着法列表的首地址;addr2是第ply+1层着法列表的首
地址。
参数:	  color:是红方,还是蓝方;mList:着法列表起始地址addr1。
返回值:  着法列表的结束地址addr2。	
*************************************************************************
*/
int* MoveGen(int color, int *mList)
{
	int i = 0;
	int from;
	int to;
	int count = 0;

#ifdef _DEBUG
	int ok = 1;
	int *p = mList;
#endif

	if (color == RED)			/*red move gen*/
	{
		from = stoneIntersection[REDSTONE];
		to = preTable[color][from][i];
		while (to != INV)
		{
			if((to != stoneIntersection[BLUESTONE1])
				&& (to != stoneIntersection[BLUESTONE2]))
			{
				mList[count++] = to;
			}
			to = preTable[color][from][++i];
		}
	}
	
	else					/*blue move gen*/
	{
		//blue stone1
		from = stoneIntersection[BLUESTONE1];
		to = preTable[color][from][i];
		while (to != INV) 
		{
			if ((to != stoneIntersection[REDSTONE])
				&& (to != stoneIntersection[BLUESTONE2]))
			{
				mList[count++] = to|16;
			}
			to = preTable[color][from][++i];
		}

		//blue stone2
		i = 0;
		from = stoneIntersection[BLUESTONE2];
		to = preTable[color][from][i];
		while (to != INV) 
		{
			if ((to != stoneIntersection[REDSTONE])
				&& (to != stoneIntersection[BLUESTONE1]))
			{
				mList[count++] = to|32;
			}
			to = preTable[color][from][++i];
		}
	}

#ifdef _DEBUG					//检查着法列表是否包含了非法着法
	for(; p < mList[count]; ++p)
	{
		if((0 <= (*p)&15) && (((*p)&15) <= 9))
			ok = 0;
	}
	assert(ok);
#endif

	return &mList[count];
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -