Recently, and friends to play chess, and then think of this years old code (some of these code refer to some of the network posts), once because do not know how to achieve man-machine war and give up to continue research. Now, this friend, gave me back to the interest, so come here please help, how to achieve man-machine war, let the computer automatically?
At present, has completed the black, the red two square chess rules, but has not realized the human-machine to fight, at present only everybody fights, namely a chess game rules board.
In order to facilitate everyone to give me a break, I first said the principle of their own program:
1, 32 pieces are specific classes, and are inherited from the chessworldbase.
Pawn base class
Using System;
Using System.Collections;
Using System.Windows.Forms;
Namespace Zivsoft.Business.Chess
{
<summary>
Pieces
</summary>
Internal abstract class Chesswordbase:ichess
{
public const int xboardlength = 9;
public const int yboardlength = 10;
public static ArrayList all = new ArrayList ();
<summary>
Within the Board range
</summary>
<returns></returns>
Public virtual bool Check ()
{
if (this. X > 9) | | (This. X < 1))
{
return false;
}
if (this. Y > 10) | | (This. Y < 1))
{
return false;
}
return true;
}
<summary>
Be eaten
</summary>
public virtual void Destroy ()
{
This. Isdogfall = false;
This. X = 0;
This. Y = 0;
}
public virtual void Init ()
{
This. Isdogfall = true;
This. X = 0;
This. Y = 0;
}
#region Ichess Members
<summary>
///
</summary>
public bool Isredchess
{
Get
Set
}
<summary>
///
</summary>
public bool Isdogfall
{
Get
Set
}
<summary>
Attack
</summary>
public bool Isattack
{
Get
Set
}
public int NEXTX
{
Get
Set
}
public int Nexty
{
Get
Set
}
public int X
{
Get
Set
}
public int Y
{
Get
Set
}
<summary>
///
</summary>
public string Name
{
Get
Set
}
Public abstract ArrayList getnextlocation ();
public void Move (int ix,int iy)
{
This. MoveNext ();
if (this. Check (ix, IY, Getnextlocation ()))
{
X = IX;
Y = iy;
}
}
private void MoveNext ()
{
This. NEXTX = this. X
This. Nexty = this. Y
}
public abstract bool Check (int x, int y, ArrayList al);
public void Move (int iX, int IY, Object QZ)
{
if (QZ = null)
{
This. Move (IX, IY);
}
Else
{
This. MoveNext ();
if (this. Check (IX, IY, Getnextlocation ()))
{
X = IX;
Y = IY;
((chesswordbase) QZ). Destroy ();
}
}
}
#endregion
}
}