Example #1
0
        private void AddCellToCanJumpList(List <Cell> jumpCells, JumpRoute route, Cell startCell, int movementX, int movementY)
        {
            var cellToMove = GetMoveToCell(startCell, movementX, movementY);

            if (CanJump(route, cellToMove)
                )
            {
                jumpCells.Add(cellToMove);
            }
        }
 /// <summary>
 /// 最短距離のrouteになる可能性あるかどうかを判定
 /// </summary>
 /// <param name="route"></param>
 /// <returns></returns>
 private bool IsPossibleShortestRoute(JumpRoute route)
 {
     if (MinSteps > 0)
     {
         if (route.Steps > MinSteps)
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 /// 最短Step数を更新
 /// </summary>
 /// <param name="route"></param>
 private void RefreshMinRouteStep(JumpRoute route)
 {
     if (route.IsEatAllCheese)
     {
         if (MinSteps == 0)
         {
             MinSteps = route.Steps;
         }
         else if (MinSteps > 0)
         {
             if (route.Steps < MinSteps)
             {
                 MinSteps = route.Steps;
             }
         }
     }
 }
        /// <summary>
        /// スタート場所から最短距離のrouteを探す
        /// </summary>
        public IEnumerable <JumpRoute> FindShortestJumpRoute(Cell startCell)
        {
            ValidateCell(startCell);

            JumpRoute route = new JumpRoute(this.Table, startCell);

            routes.Add(route);
            while (true)
            {
                GenerateJumpRouteByCurrentRoutes();
                // すべてのルートが探し完了
                if (FindComplted)
                {
                    break;
                }
            }
            return(routes.Where(a => a.IsEatAllCheese && a.Steps == MinSteps));
        }
Example #5
0
        /// <summary>
        /// 八方桂馬飛びで可能な場所(cell)一覧を取得
        /// </summary>
        /// <param name="startCell"></param>
        /// <param name="route"></param>
        /// <returns></returns>
        public List <Cell> GetCanJumpCells(Cell startCell, JumpRoute route)
        {
            List <Cell> jumpCells = new List <Cell>();

            // TopLeft
            AddCellToCanJumpList(jumpCells, route, startCell, -1, -2);
            AddCellToCanJumpList(jumpCells, route, startCell, -2, -1);
            // TopRight
            AddCellToCanJumpList(jumpCells, route, startCell, 1, -2);
            AddCellToCanJumpList(jumpCells, route, startCell, 2, -1);
            // BottomLeft
            AddCellToCanJumpList(jumpCells, route, startCell, -1, 2);
            AddCellToCanJumpList(jumpCells, route, startCell, -2, 1);
            // BottomRight
            AddCellToCanJumpList(jumpCells, route, startCell, 1, 2);
            AddCellToCanJumpList(jumpCells, route, startCell, 2, 1);
            return(jumpCells);
        }
Example #6
0
        public bool CanEatAllCheese(JumpRoute jump)
        {
            if (cheeseCells.Count == 0)
            {
                return(false);
            }
            bool all = true;

            foreach (Cell cell in cheeseCells)
            {
                if (!jump.GetCellsEnumerator.Any(a => a.Compare(cell)))
                {
                    all = false;
                    break;
                }
            }

            return(all);
        }
Example #7
0
        public bool CanJumpeToNext(JumpRoute jump, Cell nextCell)
        {
            if (jump.Complete)
            {
                return(false);
            }
            // チーズ食べ済みか
            bool eatAllCheese = CanEatAllCheese(jump);

            if (eatAllCheese)
            {
                return(false);
            }
            // 既に飛んだ場所
            if (jump.ContainCell(nextCell))
            {
                return(false);
            }
            return(true);
        }
        private IEnumerable <JumpRoute> GenerateNewRoutes(JumpRoute route, List <Cell> canJumps)
        {
            List <JumpRoute> newRoutes = new List <JumpRoute>();

            for (int i = canJumps.Count - 1; i >= 0; i--)
            {
                JumpRoute routeNew = null;
                // 既にrouteListにあるroute
                if (i == 0)
                {
                    routeNew = route;
                }
                else
                {
                    routeNew = new JumpRoute(this.Table);
                    routeNew.AddCellList(route.GetCellsEnumerator);
                    newRoutes.Add(routeNew);
                }
                routeNew.AddCell(canJumps[i]);
            }
            return(newRoutes);
        }
        private IEnumerable <JumpRoute> GenerateByOneJumpRoute(JumpRoute route)
        {
            if (!IsPossibleShortestRoute(route))
            {
                route.Complete = true;
                return(Enumerable.Empty <JumpRoute>());
            }
            Cell startCell = route.LastCell;
            // 飛べる場所を計算
            Jumper      jump     = new Jumper(Table);
            List <Cell> canJumps = jump.GetCanJumpCells(startCell, route);

            // 新しい組み合わせ作成必要がない場合
            if (!IsNeedToGenerate(canJumps))
            {
                route.Complete = true;
                RefreshMinRouteStep(route);
                return(Enumerable.Empty <JumpRoute>());
            }
            // routeのlastCellから飛べる場所の組み合わせRouteリストを作成
            return(GenerateNewRoutes(route, canJumps));
        }
Example #10
0
 private bool CanJump(JumpRoute route, Cell cellToMove)
 {
     return(JumpTable.Exists(cellToMove) &&
            JumpTable.CanJumpeToNext(route, cellToMove));
 }