コード例 #1
0
        /**
         * @param args
         * @return true:   false:終了
         */
        private Boolean searchSurrounding(PointXY temp)
        {
            int startY = temp.pointY;
            int startX = temp.pointX;
            int level  = map[startY, startX].level + 1;

            Boolean endFlg = false;

            // -------------------左上piece
            //Param5  1:右下 2:下 3:左下 4:左 5:左上 6:上 7:右上 8:右
            endFlg = readyToSearchPointInit(startY, startX, startY - 1, startX - 1, 1, map[startY, startX].distance + distanceOnePiecePlus, level, endFlg);
            // -------------------上piece
            endFlg = readyToSearchPointInit(startY, startX, startY - 1, startX, 2, map[startY, startX].distance + distanceOnePiece, level, endFlg);
            // -------------------右上piece
            endFlg = readyToSearchPointInit(startY, startX, startY - 1, startX + 1, 3, map[startY, startX].distance + distanceOnePiecePlus, level, endFlg);
            // -------------------右piece
            endFlg = readyToSearchPointInit(startY, startX, startY, startX + 1, 4, map[startY, startX].distance + distanceOnePiece, level, endFlg);
            // -------------------右下piece
            endFlg = readyToSearchPointInit(startY, startX, startY + 1, startX + 1, 5, map[startY, startX].distance + distanceOnePiecePlus, level, endFlg);
            // -------------------下piece
            endFlg = readyToSearchPointInit(startY, startX, startY + 1, startX, 6, map[startY, startX].distance + distanceOnePiece, level, endFlg);
            // -------------------左下piece
            endFlg = readyToSearchPointInit(startY, startX, startY + 1, startX - 1, 7, map[startY, startX].distance + distanceOnePiecePlus, level, endFlg);
            // -------------------左piece
            endFlg = readyToSearchPointInit(startY, startX, startY, startX - 1, 8, map[startY, startX].distance + distanceOnePiece, level, endFlg);

            return(endFlg);
        }
コード例 #2
0
        /**
         * 完成パスを取得
         * @param args
         */
        private List <PointXY> getPathList()
        {
            List <PointXY> arrayPathList = new List <PointXY>();
            int            pointY        = endPointY;
            int            pointX        = endPointX;

            PointXY temp = new PointXY(pointY, pointX);

            arrayPathList.Add(temp);

            PieceArea piecearea;

            while (true)
            {
                piecearea = map[pointY, pointX];
                if (piecearea.level == 1)
                {
                    break;
                }

                // 1:右下 2:下 3:左下 4:左 5:左上 6:上 7:右上 8:右
                if (piecearea.direction == 1)
                {
                    pointY = pointY + 1;
                    pointX = pointX + 1;
                }
                else if (piecearea.direction == 2)
                {
                    pointY = pointY + 1;
                }
                else if (piecearea.direction == 3)
                {
                    pointY = pointY + 1;
                    pointX = pointX - 1;
                }
                else if (piecearea.direction == 4)
                {
                    pointX = pointX - 1;
                }
                else if (piecearea.direction == 5)
                {
                    pointY = pointY - 1;
                    pointX = pointX - 1;
                }
                else if (piecearea.direction == 6)
                {
                    pointY = pointY - 1;
                }
                else if (piecearea.direction == 7)
                {
                    pointY = pointY - 1;
                    pointX = pointX + 1;
                }
                else if (piecearea.direction == 8)
                {
                    pointX = pointX + 1;
                }
                else
                {
                    return(null);
                }
                temp = new PointXY(pointY, pointX);
                arrayPathList.Insert(0, temp);
            }

            return(arrayPathList);
        }
コード例 #3
0
        /**
         * @param args
         */
        public List <PointXY> searchStart()
        {
            if (startPointY == -1 || startPointX == -1)
            {
                return(null);
            }

            // 検索優先エリアを取得
            areaFrom.pointY = startPointY;
            areaFrom.pointX = startPointX;
            areaTo.pointY   = startPointY;
            areaTo.pointX   = startPointX;

            // 全部EndPointをloop
            for (int y = 0; y < lengthY; y++)
            {
                for (int x = 0; x < lengthX; x++)
                {
                    if (map[y, x].level == 0)
                    {
                        areaFrom.pointY = Math.Min(areaFrom.pointY, y);
                        areaFrom.pointX = Math.Min(areaFrom.pointX, x);
                        areaTo.pointY   = Math.Max(areaTo.pointY, y);
                        areaTo.pointX   = Math.Max(areaTo.pointX, x);
                    }
                }
            }

/*          areaFrom.pointY = Math.Min(startPointY, endPointY);
 *          areaFrom.pointX = Math.Min(startPointX, endPointX);
 *          areaTo.pointY = Math.Max(startPointY, endPointY);
 *          areaTo.pointX = Math.Max(startPointX, endPointX);
 */
            PointXY temp = new PointXY(startPointY, startPointX);

            arrListNow.Clear();
            arrListOut.Clear();
            arrListNow.Add(temp);

            keyIndex = keyIndex + 1;
            map[startPointY, startPointX].keyIndex = keyIndex;

            Boolean endFlg = false;

            while (arrListNow.Count > 0)
            {
                if (searchSurrounding(arrListNow[0]))
                {
                    endFlg = true;
                }

                if (endFlg)
                {
                    // true:EndPoint 見つかれました
                    if (arrListNow.Count() < 2 || map[arrListNow[0].pointY, arrListNow[0].pointX].level != map[arrListNow[1].pointY, arrListNow[1].pointX].level)
                    {
                        // 検索Pointが最終Point || 現在のLevelは全部LOOP完了
                        break;
                    }
                }
                arrListNow.RemoveAt(0);

                if (arrListNow.Count == 0 && arrListOut.Count > 0)
                {
                    arrListNow = arrListOut;
                    arrListOut = new List <PointXY>();

                    int areaFromY = areaFrom.pointY;
                    int areaFromX = areaFrom.pointX;
                    int areaToY   = areaTo.pointY;
                    int areaToX   = areaTo.pointX;
                    foreach (PointXY pTemp in arrListNow)
                    {
                        areaFromY = Math.Min(areaFromY, pTemp.pointY);
                        areaFromX = Math.Min(areaFromX, pTemp.pointX);
                        areaToY   = Math.Max(areaToY, pTemp.pointY);
                        areaToX   = Math.Max(areaToX, pTemp.pointX);
                    }
                    areaFrom.pointY = areaFromY;
                    areaFrom.pointX = areaFromX;
                    areaTo.pointY   = areaToY;
                    areaTo.pointX   = areaToX;
                }
            }
            arrListNow.Clear();

            if (endFlg)
            {
                //			System.out.println("成功");
                return(getPathList());
            }
            else
            {
                //			System.out.println("失敗");
                return(null);
            }
        }