Пример #1
0
        public override bool CanMove(Situation situation, int dest)
        {
            if (!situation.InChessboard(dest))//如果如果目标位置不在棋盘中
            {
                return false;
            }
            if (!situation.InFort(dest))//如果如果目标位置不在九宫格中
            {
                return false;
            }
            if (situation.Pieces[dest] != null && situation.Pieces[dest].Side == this.Side)
            {
                return false;
            }

            int setp = situation.Positions[this] - dest;
            for (int n = 0; n < setps.Length; n++)
            {
                if (setp == setps[n])
                {
                    return true;
                }
            }
            return false;
        }
Пример #2
0
 public override int[] Moves(Situation situation, bool capture = false)
 {
     int pos = situation.Positions[this];
     int dest = 0;
     ChessPiece destPiece = null;
     List<int> moves = new List<int>();
     if (situation.InHomeHalf(this))//如果未过河
     {
         dest = pos + (this.Code & 16) == 0 ? -16 : 16;
         destPiece = situation.Pieces[dest];
         if (destPiece == null || destPiece.Side != Side)
         {
             moves.Add(pos | (dest << 8));
         }
     }
     for (int n = 0 + ((this.Code & 16) >> 4); n < 3 + ((this.Code & 16) >> 4); n++)
     {
         dest = pos + setps[n];
         destPiece = situation.Pieces[dest];
         if (!situation.InFort(dest) ||
             (destPiece != null && destPiece.Side == this.Side))
         {
             continue;
         }
         //pcDst = ucpcSquares[sqDst];
         if (capture && destPiece == null)
         {
             continue;
         }
         moves.Add(pos | (dest << 8) | (this.Code << 16));
     }
     return moves.ToArray();
 }
Пример #3
0
 public override int[] Moves(Situation situation, bool capture = false)
 {
     int pos = situation.Positions[this];
     int dest = 0;
     ChessPiece destPiece = null;
     List<int> moves = new List<int>();
     for (int i = 0; i < 8; i++)
     {
         dest = pos + setps[i, 0];
         destPiece = situation.Pieces[dest];
         if (!situation.InChessboard(dest) ||
             situation.Pieces[pos + setps[i, 1]] != null ||
             (destPiece != null && destPiece.Side == this.Side))
         {
             continue;
         }
         //pcDst = ucpcSquares[sqDst];
         if (capture && destPiece == null)
         {
             continue;
         }
         moves.Add(pos | (dest << 8) | (this.Code << 16));
     }
     return moves.ToArray();
 }
Пример #4
0
 public override int[] Moves(Situation situation, bool capture = false)
 {
     int pos = situation.Positions[this];
     int dest = 0;
     List<int> moves = new List<int>();
     for (int k = 0; k < 4; k++)
     {
         dest = pos + setps[k];
         for (; situation.Pieces[dest] == null && situation.InChessboard(dest); dest += setps[k])
         {
             if (!capture)
             {
                 moves.Add(pos | (dest << 8) | (this.Code << 16));
             }
         }
         if (situation.InChessboard(dest))
         {
             dest += setps[k];
             while (situation.Pieces[dest] == null && situation.InChessboard(dest)) { dest += setps[k]; }
             if (situation.InChessboard(dest) && situation.Pieces[dest].Side != Side)
             {
                 moves.Add(pos | (dest << 8) | (this.Code << 16));
             }
         }
     }
     return moves.ToArray();
 }
Пример #5
0
        public override bool CanMove(Situation situation, int dest)
        {
            if (!situation.InChessboard(dest))//如果如果目标位置不在棋盘中
            {
                return false;
            }
            if (situation.Pieces[dest] != null && situation.Pieces[dest].Side == this.Side)
            {
                return false;
            }

            int setp = dest - situation.Positions[this];
            if (situation.InHomeHalf(this, dest))//未过河
            {
                return (this.Code & 16) == 0 ? setp == -16 : setp == 16;
            }
            for (int n = 0 + ((this.Code & 16) >> 4); n < 3 + ((this.Code & 16) >> 4); n++)
            {
                if (setp == setps[n])
                {
                    return true;
                }
            }
            return false;
        }
Пример #6
0
 public override bool CanMove(Situation situation, int dest)
 {
     if (!situation.InChessboard(dest))//如果如果目标位置不在棋盘中
     {
         return false;
     }
     if (!situation.InHomeHalf(this,dest))
     {
         return false;
     }
     if (situation.Pieces[dest] != null && situation.Pieces[dest].Side == this.Side)
     {
         return false;
     }
     int pos = situation.Positions[this];
     int setp = dest - pos;
     for (int n = 0; n < setps.GetLength(0); n++)
     {
         if (setps[n, 0] == setp && situation.Pieces[pos + setps[n, 1]] == null)
         {
             return true;
         }
     }
     return false;
 }
Пример #7
0
        public override bool CanMove(Situation situation, int dest)
        {
            int pos = situation.Positions[this];
            if (pos == dest)
            {
                return false;
            }
            int delta = 0;
            if (situation.IsSameRank(pos, dest))
            {
                delta = pos < dest ? 1 : -1;
            }
            else if (situation.IsSameFile(pos, dest))
            {
                delta = pos < dest ? 16 : -16;
            }
            else
            {
                return false;
            }

            pos += delta;
            while (pos != dest && situation.Pieces[pos] == null) { pos += delta; }
            if (situation.Pieces[pos] == null)
            {
                return true;
            }
            if (situation.Pieces[dest] == null || situation.Pieces[dest].Side == this.Side)
            {
                return false;
            }
            pos += delta;
            while (pos != dest && situation.Pieces[pos] == null) { pos += delta; }
            return pos == dest;
        }
Пример #8
0
 public BattleSituation(Situation situation, ChessSide side = ChessSide.Red)
 {
     this.situation = situation;
     InitEvaluate();
 }
Пример #9
0
 /// <summary>
 /// 如果"capture"为"true"则只生成吃子走法
 /// </summary>
 /// <param name="situation"></param>
 /// <param name="capture"></param>
 /// <returns></returns>
 private List<int> GenerateMoves(Situation situation, bool capture = false)
 {
     ChessPiece piece = null;
     //int[] moves = null;
     List<int> moves = new List<int>();
     for (int n = 0; n < 256; n++)
     {
         piece = situation.Pieces[n];
         if (piece == null || piece.Side != Situation.Side)
         {
             continue;
         }
         moves.AddRange(piece.Moves(situation, capture));
     }
     return moves;
 }
Пример #10
0
 //public byte Position
 //{
 //    get { return _pos; }
 //    internal set { _pos = value; }
 //}
 /// <summary>
 /// n*2的数组,数据的第一列表示可以表的偏移量,第二列表示指定位置有棋子时,则此种走法不行的
 /// </summary>
 //public abstract int[,] Setps { get; }
 /// <summary>
 /// 生成所有走法,如果"capture"为"true"则只生成吃子走法
 /// 0-7 原来位置
 /// 8-15 目标位置
 /// 16-32 棋子
 /// </summary>
 /// <param name="situation"></param>
 /// <param name="capture"></param>
 /// <returns></returns>
 public abstract int[] Moves(Situation situation,bool capture = false);
Пример #11
0
 public abstract bool CanMove(Situation situation, int dest);
Пример #12
0
 private Situation(Situation situation)
 {
     //for (int n = 0; n < 32; n++)
     //{
     //    this.positions[n] = situation.positions[n];
     //    this.codes[n] = situation.codes[n];
     //    //this.removes[n] = situation.removes[n];
     //}
     //for (int n = 0; n < 256; n++)
     //{
     //    this.pieces[n] = situation.pieces[n];
     //}
     CopyProperty(situation, this);
     init();
 }
Пример #13
0
 private static void CopyProperty(Situation source, Situation dest)
 {
     for (int n = 0; n < 32; n++)
     {
         dest.positions[n] = source.positions[n];
         dest.codes[n] = source.codes[n];
         //this.removes[n] = situation.removes[n];
     }
     for (int n = 0; n < 256; n++)
     {
         dest.pieces[n] = source.pieces[n];
     }
 }
Пример #14
0
 public Situation Clone(Situation other = null)
 {
     if (other == null)
     {
         return new Situation(this);
     }
     else
     {
         CopyProperty(this, other);
         return other;
     }
 }