Example #1
0
        public void CoverAllIncline(int lastIncline, BoadState[,] lastBoad, int[] lastPoints, Ball[] lastBalls, List <int> lastRoute)
        {
            //全ての玉が外に出たら最大値を比較して、終了
            if (lastBalls.FirstOrDefault(b => b.IsOut == false) == null)
            {
                var tmpPointSum = lastPoints.Sum();
                if (tmpPointSum > MaxPoint)
                {
                    MaxPoint = tmpPointSum;
                    MaxRoute = lastRoute.ToArray();
                }
                return;
            }

            var currentBoad = new BoadState[Field.Size, Field.Size];

            var currentPoints = new int[3];

            var currentBalls = new Ball[Field.BallNum];

            List <int> currentRoute = null;

            CopyDataToCurrent(lastBoad, lastPoints, lastBalls, lastRoute, currentBoad, currentPoints, currentBalls, ref currentRoute);
            for (int i = 0; i < 4; i++)
            {
                //前回と同じ操作はしない
                if (i == lastIncline)
                {
                    continue;
                }
                //1回傾ける ポイントがある場合
                if (InclineField(i, currentBoad, currentPoints, currentBalls, currentRoute))
                {
                    //次へ
                    CoverAllIncline(i, currentBoad, currentPoints, currentBalls, currentRoute);
                    //終わったら元に戻して別の方向へ
                    CopyDataToCurrent(lastBoad, lastPoints, lastBalls, lastRoute, currentBoad, currentPoints, currentBalls, ref currentRoute);
                }
                //ポイントが無い場合、元に戻して別方向へ
                else
                {
                    //全方向動かした場合は何もせず終了(重複ループ)
                    if (i == 3 || (lastIncline == 3 && i == 2))
                    {
                        return;
                    }
                    //元に戻す
                    CopyDataToCurrent(lastBoad, lastPoints, lastBalls, lastRoute, currentBoad, currentPoints, currentBalls, ref currentRoute);
                    continue;
                }
            }
            //全パターン回ったら終了
            //無限ループ?起きないはず
            return;
        }
Example #2
0
        public void CalculateAllRoute(Coor[] startBallPosition)
        {
            var originalBoad = new Tile[10][];
            var boad         = new BoadState[Field.Size, Field.Size];
            var points       = new int[3];
            var balls        = new Ball[Field.BallNum];
            var Route        = new List <int>();

            //初期位置設定
            for (int i = 0; i < Field.BallNum; i++)
            {
                balls[i] = new Ball()
                {
                    Coor = startBallPosition[i]
                };

                var startTile = Field.OriginalBoad[startBallPosition[i].X, startBallPosition[i].Y];
                balls[i].Points[(int)startTile] = 1;
                boad[startBallPosition[i].X, startBallPosition[i].Y].IsPassed = true;
            }
            CoverAllIncline(-1, boad, points, balls, Route);
        }