Chess programming game-repentance Algorithm

Source: Internet
Author: User

 Bingway original works. for reprinting, please indicate the author and source.

"Watching chess is really a gentleman, and you have no regrets." This is a word you knew when you were a child. However, soon after I entered the world of chess, I had not yet formed my own unique chess style. I did not deliberately step by step, and I had to consider how many steps should be taken in the future. Therefore, almost all single-host chess versions have functions-regretAlgorithmI also thought about my life.

Every step of our lives can't be right, but we don't have the regret function. if you sacrifice less pawns, you have to take every step and stop and think about them.

Regret Algorithm

Public class regretback
{
Public int [] fromindex = new int [200]; // record the chess moves and moves
Public int [] toindex = new int [200]; // records the moves of each step.
Public point [] frompoint = new point [2, 200];
Public point [] topoint = new point [200];
Public int [] frompointindex = new int [200]; // records the current position of the pawn.
Public int [] topointindex = new int [200];
Public String [] chess_text = new string [200]; // stores the description text of each move
Public int [] signright = new int [200]; // specifies the chess icon to save
Public bool [] Start = new bool [200]; // indicates the flag to be restored for the regret operation.
Public String [] wrongstring = new string [200]; // a flag for recording rejection events
Public bool [] whichfangqianzou = new bool [200]; // indicates the position to be restored for the regret operation.
Public regretback [] B = new regretback [1, 200];
Public int activeindex; // flow pointer
Public int tailindex; // index that always points to the end (the last step after completion)
Public regretback ()
{
This. initialize ();
}
Public void initialize ()
{
// Initialize each array
For (INT I = 0; I <200; I ++)
{
Fromindex [I] =-1; toindex [I] =-1;
Frompoint [I]. x =-1; frompoint [I]. Y =-1;
Topoint [I]. x =-1; topoint [I]. Y =-1;
Frompointindex [I] =-1; topointindex [I] =-1;
}
For (INT I = 0; I <200; I ++)
{
This. chess_text [I] = "";
This. signright [I] = 0;
This. Start [I] = false;
This. wrongstring [I] = "right ";
This. whichfangqianzou [I] = false;
This. B [I] = new regretback ();
This. B [I]. initialize ();
}
// Initialize the index
Activeindex =-1;
Tailindex =-1;
}
Public void initialize (int I)
{
// Initialize an array
Fromindex [I] =-1; toindex [I] =-1;
Frompoint [I]. x =-1; frompoint [I]. Y =-1;
Topoint [I]. x =-1; topoint [I]. Y =-1;
Frompointindex [I] =-1; topointindex [I] =-1;
This. chess_text [I] = "";
This. signright [I] = 0;
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 + 1; 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 = 200)
{
MessageBox. Show ("Repentance beyond the boundary! ");
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 = 0; I <90; 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 <32)
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 <0)
Return 0;
If (this. activeindex> = This. tailindex)
This. activeindex = This. tailIndex-1;
If (this. activeindex <=-1) // prevents point-back at the beginning
Return 0;

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 1;
}
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-1)
Return 0; // only forward to the flag of the last step
This. activeindex ++;
If (this. activeindex <0)
This. activeindex = 0;
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 + 1];
Signright = This. signright [This. activeindex + 1];
Start = This. Start [This. activeindex + 1];
Wrongstring = This. wrongstring [This. activeindex + 1];
Whichfangqianzou = This. whichfangqianzou [This. activeindex + 1];
B. initialize ();
B. initialize (this. B [This. activeindex + 1]);
Return 1;
}
}

I am very grateful to my friends in the blog Park. Thank you for your encouragement and suggestions. Very busy during this time, seldom Writing TechnologyArticleBut every time I come here, the pure land of this technology can feel everyone's persistent pursuit of technology and the selflessness of sharing technology.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.