Пример #1
0
 public SelectedEventArgs(int position, Mouse mouse, int count, double x,double y,ChessPiece chess)
 {
     this.Position = position;
     this.Mouse = mouse;
     this.Count = count;
     this.Chess = chess;
     this.X = x;
     this.Y = y;
 }
Пример #2
0
 public ChessPieceView(ChessPiece piece = null)
 {
     if (piece != null)
     {
         vm = new ChessPieceViewModel(piece.Code);
         vm.Chess = piece.Chess;
     }
     else
     {
         vm = new ChessPieceViewModel(-1);
     }
     this.IsMark = false;
     this.Piece = piece;
     //this.IsMark = false;
     //this.DataContext = vm;
     this.SetDateContext((ChessPieceViewModel)vm);
 }
Пример #3
0
 /// <summary>
 /// 走棋
 /// </summary>
 /// <param name="piece"></param>
 /// <param name="dest"></param>
 protected bool Move(ChessPiece piece, int dest)
 {
     if (Situation.Positions[piece] == dest)
     {
         return false;
     }
     if (!this.Chessboard.CanMove(piece, dest))
     {
         return false;
     }
     this.OnPreMove(piece, dest);
     this.Chessboard.Mark(piece, true);
     this.Chessboard.Mark(Situation.Positions[piece], true);
     this.Chessboard.Move(piece, dest);
     if (prePiece != null)
     {
         this.Chessboard.Mark(prePiece, false);
     }
     prePiece = piece;
     currPiece = null;
     this.Situation.SwitchPlayer();
     this.OnMove(piece, dest);
     return true;
 }
Пример #4
0
 /// <summary>
 /// 走棋前
 /// </summary>
 /// <param name="piece"></param>
 /// <param name="dest"></param>
 protected virtual void OnPreMove(ChessPiece piece,int dest)
 {
 }
Пример #5
0
        /// <summary>
        /// 当选中棋子或选中棋盘中某个位置时执行
        /// </summary>
        /// <param name="args"></param>
        protected virtual void OnSelected(SelectedEventArgs args)
        {
            //if (args.Mouse == Mouse.LeftDown || args.Mouse == Mouse.RightDown || args.Mouse == Mouse.RightUp)
            //{
            //    return false;
            //}
            //return true;

            //if (!this.OnSelected(args))
            //{
            //    return;
            //}

            Console.WriteLine("selected pos:" + args.Position);
            if (args.Position == 256)
            {
                return;
            }
            if (currPiece == null && args.Chess == null)
            {
                return;
            }
            if (args.Chess != null && args.Chess.Side == this.Situation.Side)
            {
                //args.Chess.IsMark = true;
                this.Chessboard.Mark(args.Chess, true);
                if (currPiece != null && currPiece != args.Chess)
                {
                    //prePicec.IsMark = false;
                    this.Chessboard.Mark(currPiece, false);
                }
                currPiece = args.Chess;
            }
            else
            {
                //if(args.Chess != null)吃子
                if (currPiece != null)
                {
                    //prePicec.IsMark = false;
                    //currPiece = null;
                    if (this.Move(currPiece, args.Position))
                    {
                        currPiece = null;
                    }
                }
            }
        }
Пример #6
0
 public void Move(ChessPiece piece, int dest)
 {
     if (this.situation.Pieces[dest] != null)
     {
         //this.positions[this.pieces[position].Code] = 256;
         this.evaluate -= cvlPieces[this.situation.Pieces[dest].Code][dest];
     }
     int code = piece.Code;
     this.evaluate -= cvlPieces[code][this.situation.Positions[piece]];
     this.evaluate += cvlPieces[code][dest];
 }
Пример #7
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;
 }
Пример #8
0
 protected override void OnPreMove(ChessPiece piece, int dest)
 {
     //if (this.Situation.Pieces[dest] != null)
     //{
     //    //this.positions[this.pieces[position].Code] = 256;
     //    this.Evaluate -= cvlPieces[this.Situation.Pieces[dest].Code][dest];
     //}
     //int code = piece.Code;
     //this.Evaluate -= cvlPieces[code][this.Situation.Positions[piece]];
     //this.Evaluate += cvlPieces[code][dest];
     battleSituation.Move(piece, dest);
 }
Пример #9
0
 protected override void OnMove(ChessPiece piece, int dest)
 {
     this.piece = piece;
     this.dest = dest;
 }
Пример #10
0
        public void Move(ChessPiece piece, int position)
        {
            if (this.pieces[position] != null)
            {
                //this.positions[this.pieces[position].Code] = 256;
                this.pieces[position] = null;
            }
            int code = piece.Code;

            this.pieces[position] = this.pieces[this.positions[code]];
            //this.removes[code] = this.pieces[this.positions[code]];
            this.pieces[this.positions[code]] = null;
            this.positions[code] = position;
        }
Пример #11
0
 /// <summary>
 /// 表示指定位置相对piece方来说是否已经过河
 /// </summary>
 /// <param name="piece"></param>
 /// <returns>已经过河返回true,未过河返回fase</returns>
 public bool InHomeHalf(ChessPiece piece, int dest)
 {
     return (piece.Code & 16) != ((dest & 128) >> 3);
 }
Пример #12
0
 /// <summary>
 /// 表示当前棋子是否未过河
 /// </summary>
 /// <param name="piece"></param>
 /// <returns>未过河返回true,已经过河返回fase</returns>
 public bool InHomeHalf(ChessPiece piece)
 {
     return (piece.Code & 16) != ((positions[piece.Code] & 128) >> 3);
 }
Пример #13
0
 //AWAY_HALF
 /// <summary>
 /// 判断指定位置是否在九宫格中
 /// </summary>
 /// <param name="piece"></param>
 /// <returns></returns>
 public bool InFort(ChessPiece piece)
 {
     return inFort[positions[piece.Code]];
 }
Пример #14
0
 /// <summary>
 /// 判断棋子是否在棋盘中
 /// </summary>
 /// <param name="piece"></param>
 /// <returns></returns>
 public bool InChessboard(ChessPiece piece)
 {
     return inBoard[positions[piece.Code]];
 }
Пример #15
0
 //还要判断将军和将对面的情况
 public bool CanMove(ChessPiece piece, int position)
 {
     return piece.CanMove(this, position);
 }