コード例 #1
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void ComputeStandWay(SearchRouteResult result, SearchRouteContext context, List <CaseManager> route, CaseManager currentCase, int currentMove, int outOfBend, int nbLineMove, int rowMove, int exceeding)
        {
            var         targets      = currentCase.itemDataSource.targets.Select(t => boardManager.FindCaseManager(t)).ToList();
            var         playerTarget = targets.FirstOrDefault(t => t.standDataSource != null && t.standDataSource.playerIndex.HasValue && t.standDataSource.playerIndex.Value == context.playerIndex);
            CaseManager targetCase;

            if (playerTarget != null)
            {
                targetCase = playerTarget;
            }
            else
            {
                targetCase = targets.FirstOrDefault();
            }

            if (targetCase.hasPlayer && currentMove < context.min)
            {
                result.AddRoute(route.ToList(), outOfBend, true, false, nbLineMove);
            }
            else if (!targetCase.hasPlayer && targetCase == playerTarget)
            {
                var newRoute = route.ToList();
                newRoute.Add(targetCase);
                result.AddRoute(newRoute, outOfBend, true, false, nbLineMove);
            }
            else if (!targetCase.hasPlayer)
            {
                var newRoute = route.ToList();
                newRoute.Add(targetCase);
                this.SearchRoutes(result, context, newRoute, rowMove, exceeding, outOfBend, nbLineMove);
            }
        }
コード例 #2
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void SearchRoutes(SearchRouteResult result, SearchRouteContext context, List <CaseManager> route, int rowMove, int exceeding, int outOfBend, int nbLineMove)
        {
            var currentMove = route.Count - 1;
            var currentCase = route.Last();

            if (context.min <= currentMove && currentMove <= context.max)
            {
                result.AddRoute(route.ToList(), outOfBend, currentCase.standDataSource != null, false, nbLineMove);
            }

            if (currentMove < context.max)
            {
                if (currentCase.standDataSource != null)
                {
                    this.ComputeStandWay(result, context, route, currentCase, currentMove, outOfBend, nbLineMove, rowMove, exceeding);
                }
                else
                {
                    var isNewOutOfBend = false;
                    var nextTarget     = currentCase.itemDataSource.targets.FirstOrDefault(t => t.enable && t.column == currentCase.itemDataSource.index.column);
                    var nextcase       = boardManager.FindCaseManager(nextTarget);
                    if (currentCase.bendDataSource != null && nextcase.bendDataSource == null)
                    {
                        var stop = 0;
                        if (currentCase.bendDataSource.name == context.bendName)
                        {
                            stop = context.bendStop;
                        }
                        if (currentCase.bendDataSource.stop > stop)
                        {
                            isNewOutOfBend = true;
                        }
                    }
                    if (outOfBend > 0 || isNewOutOfBend)
                    {
                        this.ComputeOutOfBendWay(result, context, route, currentCase, nextcase, currentMove, outOfBend, nbLineMove);
                    }
                    else if (currentCase.bendDataSource != null)
                    {
                        this.ComputeBendWay(result, context, route, currentCase, nbLineMove, currentMove);
                    }
                    else
                    {
                        this.ComputeLineWay(result, context, route, currentCase, rowMove, exceeding, nbLineMove, currentMove);
                    }
                }
            }
        }
コード例 #3
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void ComputeBendWay(SearchRouteResult result, SearchRouteContext context, List <CaseManager> route, CaseManager currentCase, int nbLineMove, int currentMove)
        {
            bool findWay = false;

            foreach (var target in currentCase.itemDataSource.targets.Where(t => t.enable))
            {
                var targetCase = boardManager.FindCaseManager(target);
                if (!targetCase.hasPlayer)
                {
                    var newRoute = route.ToList();
                    newRoute.Add(targetCase);
                    this.SearchRoutes(result, context, newRoute, 0, 0, 0, nbLineMove);
                    findWay = true;
                }
            }
            if (!findWay && currentMove < context.min)
            {
                result.AddRoute(route.ToList(), 0, false, true, nbLineMove);
            }
        }
コード例 #4
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        public SearchRouteResult FindRoutes(PlayerContext player, int min, int max)
        {
            SearchRouteResult result = new SearchRouteResult();
            var context = new SearchRouteContext();

            context.bendName    = player.lastBend;
            context.bendStop    = player.stopBend;
            context.min         = min;
            context.max         = max;
            context.tire        = player.features.tire;
            context.playerIndex = player.index;
            context.isLastLap   = ContextEngine.Instance.gameContext.totalLap - player.lap <= 1;
            List <CaseManager> baseRoute = new List <CaseManager>();
            var currentIndex             = PlayerEngine.Instance.GetCurrentIndex(player);

            baseRoute.Add(boardManager.FindCaseManager(currentIndex));
            this.SearchRoutes(result, context, baseRoute, 0, 0, 0, 0);

            return(result);
        }
コード例 #5
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
 private void ComputeOutOfBendWay(SearchRouteResult result, SearchRouteContext context, List <CaseManager> route, CaseManager currentCase, CaseManager nextCase, int currentMove, int outOfBend, int nbLineMove)
 {
     if (!nextCase.hasPlayer)
     {
         if (outOfBend == 0)
         {
             var stop = 0;
             if (currentCase.bendDataSource.name == context.bendName)
             {
                 stop = context.bendStop;
             }
             var stopDif = currentCase.bendDataSource.stop - stop;
             if (stopDif > 1)
             {
                 var newRoute = route.ToList();
                 newRoute.Add(nextCase);
                 result.AddRoute(newRoute, 1, false, true, nbLineMove);
                 return;
             }
         }
         var newOutOfBend = outOfBend + 1;
         if (newOutOfBend <= context.tire)
         {
             var newRoute = route.ToList();
             newRoute.Add(nextCase);
             this.SearchRoutes(result, context, newRoute, 0, 0, newOutOfBend, nbLineMove);
         }
         else
         {
             var newRoute = route.ToList();
             newRoute.Add(nextCase);
             result.AddRoute(newRoute, 1, false, true, nbLineMove);
         }
     }
     else if (currentMove < context.min)
     {
         result.AddRoute(route.ToList(), outOfBend, false, true, nbLineMove);
     }
 }
コード例 #6
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void SearchRoutes(SearchRouteResult result, SearchRouteContext context, List<CaseManager> route, int rowMove, int exceeding, int outOfBend, int nbLineMove)
        {
            var currentMove = route.Count - 1;
            var currentCase = route.Last();
            if (context.min <= currentMove && currentMove <= context.max)
            {
                result.AddRoute(route.ToList(), outOfBend, currentCase.standDataSource != null, false, nbLineMove);
            }

            if (currentMove < context.max)
            {
                if (currentCase.standDataSource != null)
                {
                    this.ComputeStandWay(result, context, route, currentCase, currentMove, outOfBend, nbLineMove, rowMove, exceeding);
                }
                else
                {
                    var isNewOutOfBend = false;
                    var nextTarget = currentCase.itemDataSource.targets.FirstOrDefault(t => t.enable && t.column == currentCase.itemDataSource.index.column);
                    var nextcase = boardManager.FindCaseManager(nextTarget);
                    if (currentCase.bendDataSource != null && nextcase.bendDataSource == null)
                    {
                        var stop = 0;
                        if (currentCase.bendDataSource.name == context.bendName)
                        {
                            stop = context.bendStop;
                        }
                        if (currentCase.bendDataSource.stop > stop)
                        {
                            isNewOutOfBend = true;
                        }
                    }
                    if (outOfBend > 0 || isNewOutOfBend)
                    {
                        this.ComputeOutOfBendWay(result, context, route, currentCase, nextcase, currentMove, outOfBend, nbLineMove);
                    }
                    else if (currentCase.bendDataSource != null)
                    {
                        this.ComputeBendWay(result, context, route, currentCase, nbLineMove, currentMove);
                    }
                    else
                    {
                        this.ComputeLineWay(result, context, route, currentCase, rowMove, exceeding, nbLineMove, currentMove);
                    }
                }
            }
        }
コード例 #7
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void ComputeStandWay(SearchRouteResult result, SearchRouteContext context, List<CaseManager> route, CaseManager currentCase, int currentMove, int outOfBend, int nbLineMove, int rowMove, int exceeding)
        {
            var targets = currentCase.itemDataSource.targets.Select(t => boardManager.FindCaseManager(t)).ToList();
            var playerTarget = targets.FirstOrDefault(t => t.standDataSource != null && t.standDataSource.playerIndex.HasValue && t.standDataSource.playerIndex.Value == context.playerIndex);
            CaseManager targetCase;
            if (playerTarget != null)
            {
                targetCase = playerTarget;
            }
            else
            {
                targetCase = targets.FirstOrDefault();
            }

            if (targetCase.hasPlayer && currentMove < context.min)
            {
                result.AddRoute(route.ToList(), outOfBend, true, false, nbLineMove);
            }
            else if (!targetCase.hasPlayer && targetCase == playerTarget)
            {
                var newRoute = route.ToList();
                newRoute.Add(targetCase);
                result.AddRoute(newRoute, outOfBend, true, false, nbLineMove);
            }
            else if (!targetCase.hasPlayer)
            {
                var newRoute = route.ToList();
                newRoute.Add(targetCase);
                this.SearchRoutes(result, context, newRoute, rowMove, exceeding, outOfBend, nbLineMove);
            }
        }
コード例 #8
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
 private void ComputeOutOfBendWay(SearchRouteResult result, SearchRouteContext context, List<CaseManager> route, CaseManager currentCase, CaseManager nextCase, int currentMove, int outOfBend, int nbLineMove)
 {
     if (!nextCase.hasPlayer)
     {
         if (outOfBend == 0)
         {
             var stop = 0;
             if (currentCase.bendDataSource.name == context.bendName)
             {
                 stop = context.bendStop;
             }
             var stopDif = currentCase.bendDataSource.stop - stop;
             if (stopDif > 1)
             {
                 var newRoute = route.ToList();
                 newRoute.Add(nextCase);
                 result.AddRoute(newRoute, 1, false, true, nbLineMove);
                 return;
             }
         }
         var newOutOfBend = outOfBend + 1;
         if (newOutOfBend <= context.tire)
         {
             var newRoute = route.ToList();
             newRoute.Add(nextCase);
             this.SearchRoutes(result, context, newRoute, 0, 0, newOutOfBend, nbLineMove);
         }
         else
         {
             var newRoute = route.ToList();
             newRoute.Add(nextCase);
             result.AddRoute(newRoute, 1, false, true, nbLineMove);
         }
     }
     else if (currentMove < context.min)
     {
         result.AddRoute(route.ToList(), outOfBend, false, true, nbLineMove);
     }
 }
コード例 #9
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void ComputeLineWay(SearchRouteResult result, SearchRouteContext context, List<CaseManager> route, CaseManager currentCase, int rowMove, int exceeding, int nbLineMove, int currentMove)
        {
            var isNewExceeding = false;
            var isEndExceeding = false;
            bool findWay = false;
            foreach (var target in currentCase.itemDataSource.targets.Where(t => t.enable))
            {
                var targetCase = boardManager.FindCaseManager(target);
                if (!targetCase.hasPlayer)
                {
                    var newExceeding = exceeding;
                    var newRowMove = rowMove;
                    if (targetCase.standDataSource != null && context.isLastLap)
                    {
                        continue;
                    }
                    else if (targetCase.standDataSource != null)
                    {
                        var newRoute = route.ToList();
                        newRoute.Add(targetCase);
                        this.SearchRoutes(result, context, newRoute, rowMove, exceeding, 0, nbLineMove);
                    }
                    else
                    {
                        var isValideWay = false;
                        var columnDif = target.column - currentCase.itemDataSource.index.column;
                        if (isNewExceeding)
                        {
                            newExceeding = columnDif * -1;
                            isValideWay = true;
                        }
                        else
                        {
                            if (columnDif == 0)
                            {
                                if (newExceeding != 0 && isEndExceeding)
                                {
                                    newExceeding = 0;
                                }
                                isValideWay = true;
                            }
                            else if (newExceeding != 0 && columnDif == newExceeding)
                            {
                                isValideWay = true;
                                newExceeding = 0;
                            }
                            else if (columnDif > 0 && rowMove >= 0 && rowMove < 2)
                            {
                                newRowMove = newRowMove + 1;
                                isValideWay = true;
                                newExceeding = 0;
                            }
                            else if (columnDif < 0 && rowMove <= 0 && rowMove > -2)
                            {
                                newRowMove = newRowMove - 1;
                                isValideWay = true;
                                newExceeding = 0;
                            }
                        }

                        if (isValideWay)
                        {
                            findWay = true;
                            var newRoute = route.ToList();
                            newRoute.Add(targetCase);
                            this.SearchRoutes(result, context, newRoute, newRowMove, newExceeding, 0, nbLineMove + 1);
                        }
                    }
                }
            }
            if (!findWay && currentMove < context.min)
            {
                result.AddRoute(route.ToList(), 0, false, true, nbLineMove);
            }
        }
コード例 #10
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
 private void ComputeBendWay(SearchRouteResult result, SearchRouteContext context, List<CaseManager> route, CaseManager currentCase, int nbLineMove, int currentMove)
 {
     bool findWay = false;
     foreach (var target in currentCase.itemDataSource.targets.Where(t => t.enable))
     {
         var targetCase = boardManager.FindCaseManager(target);
         if (!targetCase.hasPlayer)
         {
             var newRoute = route.ToList();
             newRoute.Add(targetCase);
             this.SearchRoutes(result, context, newRoute, 0, 0, 0, nbLineMove);
             findWay = true;
         }
     }
     if (!findWay && currentMove < context.min)
     {
         result.AddRoute(route.ToList(), 0, false, true, nbLineMove);
     }
 }
コード例 #11
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        public SearchRouteResult FindRoutes(PlayerContext player, int min, int max)
        {
            SearchRouteResult result = new SearchRouteResult();
            var context = new SearchRouteContext();
            context.bendName = player.lastBend;
            context.bendStop = player.stopBend;
            context.min = min;
            context.max = max;
            context.tire = player.features.tire;
            context.playerIndex = player.index;
            context.isLastLap = ContextEngine.Instance.gameContext.totalLap - player.lap <= 1;
            List<CaseManager> baseRoute = new List<CaseManager>();
            var currentIndex = PlayerEngine.Instance.GetCurrentIndex(player);
            baseRoute.Add(boardManager.FindCaseManager(currentIndex));
            this.SearchRoutes(result, context, baseRoute, 0, 0, 0, 0);

            return result;
        }
コード例 #12
0
ファイル: BoardEngine.cs プロジェクト: PotRemus/FormulaD
        private void ComputeLineWay(SearchRouteResult result, SearchRouteContext context, List <CaseManager> route, CaseManager currentCase, int rowMove, int exceeding, int nbLineMove, int currentMove)
        {
            var  isNewExceeding = false;
            var  isEndExceeding = false;
            bool findWay        = false;

            foreach (var target in currentCase.itemDataSource.targets.Where(t => t.enable))
            {
                var targetCase = boardManager.FindCaseManager(target);
                if (!targetCase.hasPlayer)
                {
                    var newExceeding = exceeding;
                    var newRowMove   = rowMove;
                    if (targetCase.standDataSource != null && context.isLastLap)
                    {
                        continue;
                    }
                    else if (targetCase.standDataSource != null)
                    {
                        var newRoute = route.ToList();
                        newRoute.Add(targetCase);
                        this.SearchRoutes(result, context, newRoute, rowMove, exceeding, 0, nbLineMove);
                    }
                    else
                    {
                        var isValideWay = false;
                        var columnDif   = target.column - currentCase.itemDataSource.index.column;
                        if (isNewExceeding)
                        {
                            newExceeding = columnDif * -1;
                            isValideWay  = true;
                        }
                        else
                        {
                            if (columnDif == 0)
                            {
                                if (newExceeding != 0 && isEndExceeding)
                                {
                                    newExceeding = 0;
                                }
                                isValideWay = true;
                            }
                            else if (newExceeding != 0 && columnDif == newExceeding)
                            {
                                isValideWay  = true;
                                newExceeding = 0;
                            }
                            else if (columnDif > 0 && rowMove >= 0 && rowMove < 2)
                            {
                                newRowMove   = newRowMove + 1;
                                isValideWay  = true;
                                newExceeding = 0;
                            }
                            else if (columnDif < 0 && rowMove <= 0 && rowMove > -2)
                            {
                                newRowMove   = newRowMove - 1;
                                isValideWay  = true;
                                newExceeding = 0;
                            }
                        }

                        if (isValideWay)
                        {
                            findWay = true;
                            var newRoute = route.ToList();
                            newRoute.Add(targetCase);
                            this.SearchRoutes(result, context, newRoute, newRowMove, newExceeding, 0, nbLineMove + 1);
                        }
                    }
                }
            }
            if (!findWay && currentMove < context.min)
            {
                result.AddRoute(route.ToList(), 0, false, true, nbLineMove);
            }
        }