Exemplo n.º 1
0
void othello_ai::move(int color, int x, int y){
	o.play(color, x, y);//告诉sdk落子情况,改变局面

}
Exemplo n.º 2
0
int othello_ai::f(othello16 a, int line, int position, int var)
{
	if(line == 4)
	{
		int x;
		x = result(a);
		return x;
	}
	else
	{
		int number = line % 2;
		int color;
		if(number == 1)
			color = 3 - a.mycolor;
		else
			color = a.mycolor;
		vector<pair<int, int> > t = a.allmove(color);
		
		int len = t.size();
		int i = 0;
		int max = var;
		int pos = 0;
		if(position == 1)
			pos = 1;
		if(line == 2)
			pos = 0;
		for( ; i < len ; i ++)
		{
			temp = a;
			temp.play(color,t[i].first,t[i].second);
			int t = f(temp,line + 1, pos ,max);
	//		std::cerr<<t<<" "<<"    var: "<<var<<"   "<<"line: "<<line + 1<<"\n";
			if(i == 0)
			{
				max = t;
			}
			pos = 1;
			if(number == 1)
			{
				if(max > t)
				{
					max = t;
				}
				if(t <= var && position > 0)
				{
	//				std::cerr<<"------"<<"\n";
					return t;
				}
			}
			else
			{
				if(t >= var && position > 0)
				{
	//				std::cerr<<"------"<<"\n";
					return t;
				}
				if(max < t)
				{
					max = t;
				}
			}
		}
	//	std::cerr<<"\n";
		return max;
	}
}
Exemplo n.º 3
0
pair<int, int> othello_ai::get(){
	vector<pair<int, int> > ans = o.allmove(o.mycolor);
	//获得所有可落子的位置,按先行后列的顺序
	if(o.tostring().at(0) == '0' + o.mycolor)
	{
		cost[0][1] = 5;
		cost[1][0] = 5;
	}
	if(o.tostring().at(15) == '0' + o.mycolor)
	{
		cost[0][14] = 5;
		cost[1][15] = 5;
	}
	if(o.tostring().at(16*15) == '0' + o.mycolor)
	{
		cost[14][0] = 5;
		cost[15][1] = 5;
	}
	if(o.tostring().at(16*16 - 1) == '0' + o.mycolor)
	{
		cost[14][15] = 5;
		cost[15][14] = 5;
	}
	int len = ans.size();
	int i;
	int max = 0;
	int pos = 0;
	int position = 0;

	for(i = 0 ; i < len ; i ++)
	{
		int n = cost[ans[i].first][ans[i].second];
		if(max < n)
		{
			max = n;
			pos = i;
		}
	}
	if(max > 0)
	{
		std::cerr<<"----------------------------------------------------"<<"\n";
		std::cerr<<"time : "<<get_time()<<"   choose:"<<pos<<"\n";
		return ans[pos];
	}
	if(len == 1)
	{
		std::cerr<<"====================================================="<<"\n";
		std::cerr<<"time : "<<get_time()<<"   choose: 0"<<"\n";
		return ans[0];
	}
	max = 0;
	pos = 0;
	for(i = 0 ; i < len ; i ++)
	{
		temp = o;
		temp.play(temp.mycolor,ans[i].first,ans[i].second);
		int t = f(temp, 1, position, max);
	//	std::cerr<<t<<"  "<<"line: 1"<<"\n";
		if(i == 0)
			max = t;
		position = 1;
		if(max < t)
		{
			max = t;
			pos = i;
		}
	}
	std::cerr<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<"\n";
	std::cerr<<"time : "<<get_time()<<"   choose:"<<pos<<"\n";
	
	return ans[pos];//返回落子位置为第一个可下的点
}
Exemplo n.º 4
0
//告知所有下子情况(包括你自己的落子情况)
void othello_ai::move(int color, int x, int y){
	o.play(color, x, y);
}