知识大全 象棋编程游戏——悔棋算法

Posted 象棋

篇首语:不知道自己无知,乃是双倍的无知。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 象棋编程游戏——悔棋算法相关的知识,希望对你有一定的参考价值。

  

   观棋不语真君子 落子无悔大丈夫 这是小时候就知道的一句话 但是进入象棋世界不久的我 还没有形成自己独有的下棋风格 也没有刻意步步为营 落一步子 就考虑好以后很多步应该怎么走 因此 在做几乎所有单机象棋版本都会有的功能——悔棋算法的时候 对人生也进行了一些思考

  人生的每一步棋 我们不可能都是走对的 但是我们没有悔棋功能 为了以后少走烂著 少牺牲一些本来就不多的棋子 还是要每走一步 停下来思考一下

  悔棋算法

  public class RegretBack

  

  public int[] fromIndex=new int[ ]; //记录每走一步棋 所动的棋子public int[] toIndex = new int[ ]; //记录每走一步棋 所动的棋子

  public Point[] fromPoint=new Point[ ];

  public Point[] toPoint=new Point[ ];

  public int[] fromPointIndex=new int[ ]; //记录当前棋子位置

  public int[] toPointIndex=new int[ ];

  public string[] Chess_Text=new string[ ]; //存放每一步棋的说明文字

  public int[] signRight=new int[ ]; //保存哪方走棋标志

  public bool[] start=new bool[ ]; //悔棋操作 要恢复的标志位

  public string[] wrongString=new string[ ]; //记录排斥事件的标志

  public bool[] whichFangQianZou = new bool[ ];//悔棋操作 要恢复的标志位

  public RegretBack[] b = new RegretBack[ ];

  public int activeIndex; //起流动指针作用

  public int tailIndex; //始终指向尾部(刚走完的最后一步)的索引

  public RegretBack()

  

  this Initialize();

  

  public void Initialize()

  

  //初始化各数组

  for(int i= ;i< ;i++)

  

  fromIndex[i]= ; toIndex[i]= ;

  fromPoint[i] X= ; fromPoint[i] Y= ;

  toPoint[i] X= ; toPoint[i] Y= ;

  fromPointIndex[i]= ; toPointIndex[i]= ;

  

  for(int i= ;i< ;i++)

  

  this Chess_Text[i]= ;

  this signRight[i]= ;

  this start[i]=false;

  this wrongString[i]= right ;

  this whichFangQianZou[i]=false;

  this b[i] = new RegretBack();

  this b[i] Initialize();

  

  //初始化索引activeIndex= ;

  tailIndex= ;

  

  public void Initialize(int i)

  

  //初始化一个数组

  fromIndex[i]= ; toIndex[i]= ;

  fromPoint[i] X= ; fromPoint[i] Y= ;

  toPoint[i] X= ; toPoint[i] Y= ;

  fromPointIndex[i]= ; toPointIndex[i]= ;

  this Chess_Text[i]= ;

  this signRight[i]= ;

  this start[i]=false;

  this wrongString[i]= right ;

  this whichFangQianZou[i]=false;

  this b[i] Initialize();

  

  public void SubLastItem()

  

  if(this activeIndex

  

  for(int i=this activeIndex+ ;i<=this tailIndex;i++) this Initialize(i);

  return;

  

  this Initialize(this tailIndex);

  this tailIndex ;

  this activeIndex=this tailIndex;

  

  public void SaveNewItem(int fromIndex int toIndex Point fromPoint Point toPoint string Chess_Text int signRight bool start string wrongString bool whichFangQianZou RegretBack b)

  

  if(this activeIndex>this tailIndex)

  

  this activeIndex=this tailIndex;

  

  this activeIndex++;

  if(this activeIndex== )

  

  MessageBox Show( 悔棋超出边界范围! );

  return;

  

  this fromIndex[this activeIndex]=fromIndex;

  this toIndex[this activeIndex]=toIndex;

  this fromPoint[this activeIndex]=fromPoint;

  this toPoint[this activeIndex]=toPoint;

  this Chess_Text[this activeIndex]=Chess_Text;

  this signRight[this activeIndex]=signRight;

  this start[this activeIndex]=start;

  this wrongString[this activeIndex]=wrongString;

  this whichFangQianZou[this activeIndex]=whichFangQianZou;

  RegretBack tempRegretBack = new RegretBack();

  tempRegretBack Initialize();

  for(int i= ;i< ;i++)

  

  tempRegretBack have[i] = b have[i];

  tempRegretBack who[i] = b who[i];

  tempRegretBack str[i] = b str[i];

  tempRegretBack allPoint[i] = b allPoint[i];

  if(i< )

  tempRegretBack partPoint[i] = b partPoint[i];

  tempRegretBack whichPicture[i] = b whichPicture[i];

  

  tempRegretBack rednum = b rednum;

  tempRegretBack blacknum = b blacknum;

  tempRegretBack index = b index;

  tempRegretBack first_X = b first_X;

  tempRegretBack first_Y = b first_Y;

  tempRegretBack height = b height;

  tempRegretBack width = b width;

  this b[this activeIndex] = tempRegretBack;

  this tailIndex=this activeIndex;

  

  public int FallBack(ref int fromIndex ref int toIndex ref Point fromPoint ref Point toPoint ref string Chess_Text ref int signRight ref bool start ref string wrongString ref bool whichFangQianZou ref RegretBack b)

  

  if(this activeIndex< )

  return ;

  if(this activeIndex>=this tailIndex) this activeIndex=this tailIndex ;

  if(this activeIndex<= ) //防止一开始就点后退

  return ;

  fromIndex=this fromIndex[this activeIndex];

  toIndex=this toIndex[this activeIndex];

  fromPoint=this fromPoint[this activeIndex];

  toPoint=this toPoint[this activeIndex];

  Chess_Text=this Chess_Text[this activeIndex];

  signRight=this signRight[this activeIndex];

  start=this start[this activeIndex];

  wrongString=this wrongString[this activeIndex];

  whichFangQianZou=this whichFangQianZou[this activeIndex];

  b Initialize();

  b Initialize(this b[this activeIndex]);

  this activeIndex ;

  return ;

  

  public int GoAhead(ref int fromIndex ref int toIndex ref Point fromPoint ref Point toPoint ref string Chess_Text ref int signRight ref bool start ref string wrongString ref bool whichFangQianZou ref RegretBack b)

  

  if(this activeIndex>=this tailIndex )

  return ; //只能前进到最后一步旗

  this activeIndex++;

  if(this activeIndex< ) this activeIndex= ;

  fromIndex=this fromIndex[this activeIndex];

  toIndex=this toIndex[this activeIndex];

  fromPoint=this fromPoint[this activeIndex];

  toPoint=this toPoint[this activeIndex];

  Chess_Text=this Chess_Text[this activeIndex+ ];

  signRight=this signRight[this activeIndex+ ];

  start=this start[this activeIndex+ ];

  wrongString=this wrongString[this activeIndex+ ];

  whichFangQianZou=this whichFangQianZou[this activeIndex+ ];

  b Initialize();

  b Initialize(this b[this activeIndex+ ]);

  return ;

  

  

cha138/Article/program/net/201311/12475

相关参考