一个象棋程序,大佬帮忙看看什么地方可以改进!谢谢大佬
  • 板块灌水区
  • 楼主_Arbiter_
  • 当前回复15
  • 已保存回复15
  • 发布时间2020/5/18 19:32
  • 上次更新2023/11/7 02:12:32
查看原帖
一个象棋程序,大佬帮忙看看什么地方可以改进!谢谢大佬
127950
_Arbiter_楼主2020/5/18 19:32
#include<iostream>
using namespace std;
int starta,starty,endx,endy,jx,jy,paojx,paojy;
void move()
{
	cin>>startx>>starty>>endx>>endy;
	if(row==true)
	{
		qipan[endx][endy]=qipan[startx][starty];
		qipan[startx][starty]="  ";
	}
	else
	{
		cout<<"WRONG\n";
	}
}
bool panduan()
{
	int gx=endx-startx,gy=endy-starty;
	if(gx<0) gx=-gx;
	if(gy<0) gy=-gy;
	bool row=true;
	if(qipan[startx][starty]=="马"&&gx>gy&&qipan[startx+1][starty]=="  ")
		row=true;
	if(qipan[startx][starty]=="马"&&gx<gy&&qipan[startx][starty+1]=="  ")
		row=true;
	if(qipan[startx][starty]=="馬"&&gx>gy&&qipan[startx+1][starty]=="  ")
		row=true;
	if(qipan[startx][starty]=="馬"&&gx<gy&&qipan[startx][starty+1]=="  ")
		row=true;
	if(qipan[startx][starty]=="车"||qipan[startx][starty]=="車")
		for(int i=startx;i<=endx;i++)
			for(int j=startx;j<=endx;j++)
				if(qipan[i][j]!="  ")
					row=false;
	if(qipan[startx][starty]=="相"&&qipan[startx-(startx-endx)/2][starty-(starty-endy)/2]=="  ")
		row=true;
	if(qipan[startx][starty]=="象"&&qipan[startx-(startx-endx)/2][starty-(starty-endy)/2]=="  ")
		row=true;
	if(qipan[startx][starty]=="炮"&&qipan[endx][endy]!="  ")
	{
		row=false;
		for(int i=0;i<9;i++)
			for(int j=0;j<9;j++)
			{
				if(qipan[i][j]!="  ")
				{
					row=true;
				}
			}
	}
	if(qipan[startx][starty]=="炮"&&qipan[endx][endy]=="  ")
	{
		for(int i=0;i<9;i++)
			for(int j=0;j<9;j++)
			{
				if(qipan[i][j]!="  ")
				{
					row=false;
				}
			}
	}
	row=true;
}
int main()
{
	string qipan[9][9]={
					 "车","马","相","士","帅","士","相","马","车\n",
	                 "  ","  ","  ","  ","  ","  ","  ","  ","  \n", 
					 "  ","炮","  ","  ","  ","  ","  ","炮","  \n", 
					 "兵","  ","兵","  ","兵","  ","兵","  ","兵\n", 
					 "  ","  ","  ","  ","  ","  ","  ","  ","  \n",
					 "卒","  ","卒","  ","卒","  ","卒","  ","卒\n",
					 "  ","炮","  ","  ","  ","  ","  ","炮","  \n", 
					 "  ","  ","  ","  ","  ","  ","  ","  ","  \n", 
					 "車","馬","象","仕","将","仕","象","馬","車"};
	move();
	return 0;
}
2020/5/18 19:32
加载中...