角斗士(Blokus)博弈程序

这是一个用C++实现的Blokus博弈程序,由coolypf编写。程序包括游戏初始化、棋盘操作、AI算法等功能,通过读取命令行输入进行游戏流程控制。AI部分采用了基于评估函数的搜索策略,考虑了棋子位置、相邻角度等因素。
摘要由CSDN通过智能技术生成
/********************************
* Blokus Baicai Seeker Release *
*          by coolypf          *
*       2009-05-22 09:24       *
********************************/
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

#define Blank -1
int Me,iStart=19;

const int soBlock=1,
	soBlank=3,
	soFix=30,
	soAngle=75;

const char Piece[21][5][5]=
{
	{
		{1,0,0,0,0},    
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,1,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,1,1,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,1,1,1},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,1,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{0,1,1,0,0},
		{0,0,1,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,0,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,0,0,0,0},
		{1,0,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,0,0,0,0},
		{1,1,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,0,0,0,0},
		{1,1,0,0,0},
		{1,0,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,0,0,0},
		{1,0,0,0,0},
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{0,1,0,0,0},
		{1,1,1,0,0},
		{0,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,0,0,0,0},
		{1,1,1,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{1,1,1,0,0},
		{1,0,0,0,0},
		{1,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{0,1,1,0,0},
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{0,1,1,0,0},
		{1,1,0,0,0},
		{0,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{0,1,1,0,0},
		{0,1,0,0,0},
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	},
	{
		{0,1,1,1,0},
		{1,1,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0},
		{0,0,0,0,0}
	}
};

const char soSingle[21]=
{
	1,3,6,8,9,5,8,
	9,9,7,9,7,9,9,
	9,9,9,7,9,9,9
};

char b[20][20],p[21][8][5][5];
int step=0,startx,starty;
bool unused[4][21];

bool IsAngle(char [][20],int,int,int);
bool CanPut(char [][20],int,int,int,int,int);
bool CanPutStart(int,int,int,int);
void Init();
void Backup(char [][20],const char [][20]);
int SimpleEvaluate(char [][20],int,int,int,int,int);
int MyEvaluate(char [][20]);
void AI();
void turn(char [][5],const char [][5],int);
void PutStart();
void Put(int,char [][20],int,int,int,int);
int cBlanks(char [][20],bool [][20],int,int,int);

int main()
{
	Init();
	int n,x,y,p,i,d;
	string cmd;
	while(1)
	{
		cin>>cmd;
		if(cmd=="[end]") break;
		else if(cmd=="[start]")
		{
			cin>>startx>>starty;
			cin>>cmd;
			cin>>n;
			if(startx&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值