观棋不语真君子落子无悔大丈夫这是小时候就知道的一句话但是进入象棋世界不久的我还没有形成自己独有的下棋风格也没有刻意步步为营落一步子就考虑好以后很多步应该怎么走因此在做几乎所有单机象棋版本都会有的功能——悔棋算法的时候对人生也进行了一些思考
人生的每一步棋我们不可能都是走对的但是我们没有悔棋功能为了以后少走烂着少牺牲一些本来就不多的棋子还是要每走一步停下来思考一下
悔棋算法
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()
{
thisInitialize();
}
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++)
{
thisChess_Text[i]=;
thissignRight[i]=;
thisstart[i]=false;
thiswrongString[i]=right;
thiswhichFangQianZou[i]=false;
thisb[i] = new RegretBack();
thisb[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]=;
thisChess_Text[i]=;
thissignRight[i]=;
thisstart[i]=false;
thiswrongString[i]=right;
thiswhichFangQianZou[i]=false;
thisb[i]Initialize();
}
public void SubLastItem()
{
if(thisactiveIndex
{
for(int i=thisactiveIndex+;i<=thistailIndex;i++) thisInitialize(i);
return;
}
thisInitialize(thistailIndex);
thistailIndex;
thisactiveIndex=thistailIndex;
}
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(thisactiveIndex>thistailIndex)
{
thisactiveIndex=thistailIndex;
}
thisactiveIndex++;
if(thisactiveIndex==)
{
MessageBoxShow(悔棋超出边界范围!);
return;
}
thisfromIndex[thisactiveIndex]=fromIndex;
thistoIndex[thisactiveIndex]=toIndex;
thisfromPoint[thisactiveIndex]=fromPoint;
thistoPoint[thisactiveIndex]=toPoint;
thisChess_Text[thisactiveIndex]=Chess_Text;
thissignRight[thisactiveIndex]=signRight;
thisstart[thisactiveIndex]=start;
thiswrongString[thisactiveIndex]=wrongString;
thiswhichFangQianZou[thisactiveIndex]=whichFangQianZou;
RegretBack tempRegretBack = new RegretBack();
tempRegretBackInitialize();
for(int i=;i<;i++)
{
tempRegretBackhave[i] = bhave[i];
tempRegretBackwho[i] = bwho[i];
tempRegretBackstr[i] = bstr[i];
tempRegretBackallPoint[i] = ballPoint[i];
if(i<)
tempRegretBackpartPoint[i] = bpartPoint[i];
tempRegretBackwhichPicture[i] = bwhichPicture[i];
}
tempRegretBackrednum = brednum;
tempRegretBackblacknum = bblacknum;
tempRegretBackindex = bindex;
tempRegretBackfirst_X = bfirst_X;
tempRegretBackfirst_Y = bfirst_Y;
tempRegretBackheight = bheight;
tempRegretBackwidth = bwidth;
thisb[thisactiveIndex] = tempRegretBack;
thistailIndex=thisactiveIndex;
}
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(thisactiveIndex<)
return ;
if(thisactiveIndex>=thistailIndex) thisactiveIndex=thistailIndex;
if(thisactiveIndex<=) //防止一开始就点后退
return ;
fromIndex=thisfromIndex[thisactiveIndex];
toIndex=thistoIndex[thisactiveIndex];
fromPoint=thisfromPoint[thisactiveIndex];
toPoint=thistoPoint[thisactiveIndex];
Chess_Text=thisChess_Text[thisactiveIndex];
signRight=thissignRight[thisactiveIndex];
start=thisstart[thisactiveIndex];
wrongString=thiswrongString[thisactiveIndex];
whichFangQianZou=thiswhichFangQianZou[thisactiveIndex];
bInitialize();
bInitialize(thisb[thisactiveIndex]);
thisactiveIndex;
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(thisactiveIndex>=thistailIndex)
return ; //只能前进到最后一步旗
thisactiveIndex++;
if(thisactiveIndex<) thisactiveIndex=;
fromIndex=thisfromIndex[thisactiveIndex];
toIndex=thistoIndex[thisactiveIndex];
fromPoint=thisfromPoint[thisactiveIndex];
toPoint=thistoPoint[thisactiveIndex];
Chess_Text=thisChess_Text[thisactiveIndex+];
signRight=thissignRight[thisactiveIndex+];
start=thisstart[thisactiveIndex+];
wrongString=thiswrongString[thisactiveIndex+];
whichFangQianZou=thiswhichFangQianZou[thisactiveIndex+];
bInitialize();
bInitialize(thisb[thisactiveIndex+]);
return ;
}
}
很感激我在博客园里的好朋友特别要谢谢你们给我的鼓励和建议这段时间比较忙很少写技术文章但是每次来这里在这块技术的净土都能感受到大家对技术的执着追求和分享技术的无私