Example #1
0
 /// <summary>
 /// 构造初始布局
 /// </summary>
 /// <param name="layoutCode">布局数值</param>
 /// <param name="blankPosition1">空白棋子1位置</param>
 /// <param name="blankPosition2">空白棋子2位置</param>
 public PathFinder(long layoutCode, int blankPosition1, int blankPosition2)
 {
     this.StepCodeDict      = new Dictionary <long, long>(0);
     this.InitLayoutCode    = layoutCode;
     this.InitBlankPosition = new BlankPosition {
         Position1 = blankPosition1, Position2 = blankPosition2
     };
 }
Example #2
0
        /// <summary>
        /// 移动棋子到新的位置
        /// </summary>
        /// <param name="chess">待移动的棋子</param>
        /// <param name="moveDirection">移动方向</param>
        /// <param name="newBlankPosition">新的空白格子</param>
        private void MoveChessToNext(ChessBase chess, Direction moveDirection, BlankPosition newBlankPosition)
        {
            int oldPosition = chess.Position;
            int newPosition = chess.NextPosition;

            this.BlankPosition = chess.ChessMove(newBlankPosition, moveDirection, Common.GridColumns);
            chess.Position     = chess.NextPosition;
            this.MoveAnimation(chess.Element, newPosition, oldPosition, moveDirection);
        }
Example #3
0
 /// <summary>
 /// 释放相关资源
 /// </summary>
 private void Dispose()
 {
     this.StepCodeDict.Clear();
     this.StepCodeDict      = null;
     this.InitLayoutCode    = 0;
     this.InitBlankPosition = new BlankPosition {
         Position1 = -1, Position2 = -1
     };
     this.NextNodeList.Clear();
     this.NextNodeList = null;
     GC.Collect();
 }
Example #4
0
        /// <summary>
        /// 尝试将棋子移动到下一个指定的位置
        /// </summary>
        /// <param name="chess">待移动的棋子</param>
        /// <param name="moveDirection">移动方向</param>
        /// <param name="newBlankPosition">新的空白格子</param>
        private void TryMoveToNext(ChessBase chess, Direction moveDirection, BlankPosition newBlankPosition)
        {
            List <ChessBase> chessList = this.CurrentNode.CurrentCode.GetChessList();

            chessList[this.ChessIndex].Position = chess.NextPosition;
            long nodeCode = chessList.GetLayoutCode();

            if (nodeCode != this.CurrentNode.ParentCode && !this.StepCodeDict.Keys.Contains(nodeCode))
            {
                PathNode node = new PathNode
                {
                    CurrentCode = nodeCode,
                    ParentCode  = this.CurrentNode.CurrentCode,
                    //BlankPosition = chess.ChessMove(this.CurrentNode.BlankPosition, moveDirection, Common.GridColumns),
                    BlankPosition = chess.ChessMove(newBlankPosition, moveDirection, Common.GridColumns),
                    IsLast        = chessList.LayoutFinished()
                };
                this.NextNodeList.Add(node);
            }
        }