Exemplo n.º 1
0
        public void OnStandOut()
        {
            var  player   = PlayerEngine.Instance.GetCurrent();
            bool hasRoute = false;

            _candidateRoutes = BoardEngine.Instance.FindRoutes(player, 1, player.currentTurn.standMovement);
            if (_candidateRoutes.routes.Count > 0)
            {
                var maxCount = _candidateRoutes.routes.Max(cr => cr.Value.Max(r => r.route.Count));
                if (maxCount > 1)
                {
                    foreach (var routes in _candidateRoutes.routes)
                    {
                        var route = routes.Value.Where(r => r.route.Count == maxCount)
                                    .OrderBy(r => r.nbLineMove)
                                    .ThenBy(r => r.route.Count(c => c.isDangerous)).FirstOrDefault();

                        if (route != null && !route.isBadWay)
                        {
                            hasRoute = true;
                            var caseCandidate = route.route.Last();
                            caseCandidate.UpdateContent(player.currentTurn.gear, route.route.Count - 1, route.route.Count - 1, false, false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                }
            }

            if (!hasRoute)
            {
                PlayerEngine.Instance.EndTurn(null);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void OnAspiration(bool enable)
        {
            if (enable)
            {
                PlayerEngine.Instance.LoadAspirationView();
                var player = PlayerEngine.Instance.GetCurrent();
                int min;
                int max;
                FeatureEngine.Instance.ComputeMinMaxUseBrake(player, 3, out min, out max);
                _candidateRoutes = BoardEngine.Instance.FindRoutes(player, min, max);
                if (_candidateRoutes.routes.Count > 0)
                {
                    var gear = player.currentTurn.gear;
                    foreach (var routes in _candidateRoutes.routes)
                    {
                        var route = routes.Value
                                    .OrderBy(r => r.nbLineMove)
                                    .ThenByDescending(r => r.route.Count - max)
                                    .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                        var hasWarning = route.nbOutOfBend > 0;
                        if (!hasWarning && 3 - (route.route.Count - 1) >= 1)
                        {
                            hasWarning = true;
                        }
                        if (!hasWarning && route.route.Skip(1).Any(c => c.isDangerous))
                        {
                            hasWarning = true;
                        }

                        var caseCandidate = route.route.Last();
                        caseCandidate.UpdateContent(gear, route.route.Count - 1, route.route.Count - 1, hasWarning, route.isBadWay);
                        caseCandidate.isCandidate = true;
                    }
                }
                else
                {
                    PlayerEngine.Instance.EndTurn(null);
                }
            }
            else
            {
                PlayerEngine.Instance.EndTurn(null);
            }
        }
Exemplo n.º 5
0
        public void OnAspiration(bool enable)
        {
            if (enable)
            {
                PlayerEngine.Instance.LoadAspirationView();
                var player = PlayerEngine.Instance.GetCurrent();
                int min;
                int max;
                FeatureEngine.Instance.ComputeMinMaxUseBrake(player, 3, out min, out max);
                _candidateRoutes = BoardEngine.Instance.FindRoutes(player, min, max);
                if (_candidateRoutes.routes.Count > 0)
                {
                    var gear = player.currentTurn.gear;
                    foreach (var routes in _candidateRoutes.routes)
                    {
                        var route = routes.Value
                            .OrderBy(r => r.nbLineMove)
                            .ThenByDescending(r => r.route.Count - max)
                            .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                        var hasWarning = route.nbOutOfBend > 0;
                        if (!hasWarning && 3 - (route.route.Count - 1) >= 1)
                        {
                            hasWarning = true;
                        }
                        if (!hasWarning && route.route.Skip(1).Any(c => c.isDangerous))
                        {
                            hasWarning = true;
                        }

                        var caseCandidate = route.route.Last();
                        caseCandidate.UpdateContent(gear, route.route.Count - 1, route.route.Count - 1, hasWarning, route.isBadWay);
                        caseCandidate.isCandidate = true;
                    }
                }
                else
                {
                    PlayerEngine.Instance.EndTurn(null);
                }
            }
            else
            {
                PlayerEngine.Instance.EndTurn(null);
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
0
 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);
     }
 }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        public void OnViewRollDice(int gear, int deValue)
        {
            var player = PlayerEngine.Instance.GetCurrent();
            if (deValue == 0)
            {
                var current = BoardEngine.Instance.GetCase(PlayerEngine.Instance.GetCurrentIndex(player));
                player.state = PlayerStateType.ChoseRoute;
                PlayerEngine.Instance.SelectedRoute(new RouteResult()
                {
                    route = new List<CaseManager>() { current },
                    nbOutOfBend = 0,
                    isStandWay = false,
                    isBadWay = false,
                    nbLineMove = 0
                });
                this.OnFinishMouvement();
            }
            else
            {
                PlayerEngine.Instance.UpdateGear(gear, deValue);

                int minValue;
                int maxValue;
                FeatureEngine.Instance.ComputeMinMaxUseBrake(player, deValue, out minValue, out maxValue);
                _candidateRoutes = BoardEngine.Instance.FindRoutes(player, minValue - 1, maxValue);

                if (ContextEngine.Instance.gameContext.state == GameStateType.Race)
                {
                    var playerStandCase = _candidateRoutes.routes.Select(r => r.Value.First().route.Last()).Where(r => r.standDataSource != null && r.standDataSource.playerIndex.HasValue).FirstOrDefault();
                    if (playerStandCase != null)
                    {
                        var standWay = _candidateRoutes.routes[playerStandCase.itemDataSource.index]
                            .OrderBy(r => r.nbLineMove)
                            .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous))
                            .FirstOrDefault();
                        if (standWay != null && standWay.route.Count > 1)
                        {
                            var caseCandidate = standWay.route.Last();
                            caseCandidate.UpdateContent(gear, standWay.route.Count - 1, standWay.route.Count - 1, standWay.route.Any(r => r.isDangerous), false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                    else
                    {
                        var standWay = _candidateRoutes.routes.SelectMany(r => r.Value.Where(c => c.isStandWay).Select(c => c.route))
                            .OrderByDescending(r => r.Last().itemDataSource.order)
                            .ThenBy(r => r.Skip(1).Count(c => c.isDangerous))
                            .FirstOrDefault();
                        if (standWay != null && standWay.Count > 1)
                        {
                            var caseCandidate = standWay.Last();
                            caseCandidate.UpdateContent(gear, standWay.Count - 1, standWay.Count - 1, standWay.Any(r => r.isDangerous), false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                }

                foreach (var routes in _candidateRoutes.routes.Where(r => !r.Value.Any(rv => rv.isStandWay)))
                {
                    var route = routes.Value
                        .OrderBy(r => r.nbLineMove)
                        .ThenByDescending(r => r.route.Count - deValue)
                        .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                    if (route.isBadWay || route.route.Count - 1 >= minValue)
                    {
                        var caseCandidate = route.route.Last();
                        var hasWarning = route.nbOutOfBend > 0;
                        if (!hasWarning && deValue - (route.route.Count - 1) >= 1)
                        {
                            hasWarning = true;
                        }
                        if (!hasWarning && route.route.Skip(1).Any(c => c.isDangerous))
                        {
                            hasWarning = true;
                        }
                        caseCandidate.UpdateContent(gear, route.route.Count - 1, route.route.Count - 1, hasWarning, route.isBadWay);
                        caseCandidate.isCandidate = true;
                    }
                }
            }
        }
Exemplo n.º 16
0
        public void OnViewGear(int gear, int min, int max)
        {
            if (_candidateRoutes != null)
            {
                this.CleanCurrent();
            }

            PlayerEngine.Instance.SelectedDe(gear);
            var player = PlayerEngine.Instance.GetCurrent();
            _candidateRoutes = BoardEngine.Instance.FindRoutes(player, min, max);

            foreach (var routes in _candidateRoutes.routes)
            {
                var caseCandidate = routes.Value.First().route.Last();
                if (ContextEngine.Instance.gameContext.state != GameStateType.Qualification || caseCandidate.standDataSource == null)
                {
                    if (routes.Value.Any(r => !r.isBadWay))
                    {
                        var minCandidate = routes.Value.Where(r => !r.isBadWay).Min(r => r.route.Count) - 1;
                        var maxCandidate = routes.Value.Where(r => !r.isBadWay).Max(r => r.route.Count) - 1;
                        if (minCandidate < min)
                        {
                            minCandidate = min;
                        }
                        if (maxCandidate > max)
                        {
                            maxCandidate = max;
                        }
                        caseCandidate.UpdateContent(gear, minCandidate, maxCandidate, routes.Value.Any(r => r.nbOutOfBend > 0), false);
                    }
                    else
                    {
                        var minCandidate = max;
                        var maxCandidate = min;
                        var hasRouteCandidate = false;
                        foreach (var route in routes.Value)
                        {
                            if (!_candidateRoutes.routes.Any(cr => cr.Value.Any(r => !r.isBadWay && r.route.Count == route.route.Count)))
                            {
                                if (route.route.Count < minCandidate)
                                {
                                    minCandidate = route.route.Count;
                                }
                                if (route.route.Count > maxCandidate)
                                {
                                    maxCandidate = route.route.Count;
                                }
                                hasRouteCandidate = true;
                            }
                        }
                        if (hasRouteCandidate)
                        {
                            if (minCandidate < min)
                            {
                                minCandidate = min;
                            }
                            if (maxCandidate > max)
                            {
                                maxCandidate = max;
                            }
                            caseCandidate.UpdateContent(gear, minCandidate, maxCandidate, routes.Value.Any(r => r.nbOutOfBend > 0), true);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void OnStandOut()
        {
            var player = PlayerEngine.Instance.GetCurrent();
            bool hasRoute = false;
            _candidateRoutes = BoardEngine.Instance.FindRoutes(player, 1, player.currentTurn.standMovement);
            if (_candidateRoutes.routes.Count > 0)
            {
                var maxCount = _candidateRoutes.routes.Max(cr => cr.Value.Max(r => r.route.Count));
                if (maxCount > 1)
                {
                    foreach (var routes in _candidateRoutes.routes)
                    {
                        var route = routes.Value.Where(r => r.route.Count == maxCount)
                            .OrderBy(r => r.nbLineMove)
                            .ThenBy(r => r.route.Count(c => c.isDangerous)).FirstOrDefault();

                        if (route != null && !route.isBadWay)
                        {
                            hasRoute = true;
                            var caseCandidate = route.route.Last();
                            caseCandidate.UpdateContent(player.currentTurn.gear, route.route.Count - 1, route.route.Count - 1, false, false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                }
            }

            if (!hasRoute)
            {
                PlayerEngine.Instance.EndTurn(null);
            }
        }
Exemplo n.º 18
0
        public void OnViewGear(int gear, int min, int max)
        {
            if (_candidateRoutes != null)
            {
                this.CleanCurrent();
            }

            PlayerEngine.Instance.SelectedDe(gear);
            var player = PlayerEngine.Instance.GetCurrent();

            _candidateRoutes = BoardEngine.Instance.FindRoutes(player, min, max);

            foreach (var routes in _candidateRoutes.routes)
            {
                var caseCandidate = routes.Value.First().route.Last();
                if (ContextEngine.Instance.gameContext.state != GameStateType.Qualification || caseCandidate.standDataSource == null)
                {
                    if (routes.Value.Any(r => !r.isBadWay))
                    {
                        var minCandidate = routes.Value.Where(r => !r.isBadWay).Min(r => r.route.Count) - 1;
                        var maxCandidate = routes.Value.Where(r => !r.isBadWay).Max(r => r.route.Count) - 1;
                        if (minCandidate < min)
                        {
                            minCandidate = min;
                        }
                        if (maxCandidate > max)
                        {
                            maxCandidate = max;
                        }
                        caseCandidate.UpdateContent(gear, minCandidate, maxCandidate, routes.Value.Any(r => r.nbOutOfBend > 0), false);
                    }
                    else
                    {
                        var minCandidate      = max;
                        var maxCandidate      = min;
                        var hasRouteCandidate = false;
                        foreach (var route in routes.Value)
                        {
                            if (!_candidateRoutes.routes.Any(cr => cr.Value.Any(r => !r.isBadWay && r.route.Count == route.route.Count)))
                            {
                                if (route.route.Count < minCandidate)
                                {
                                    minCandidate = route.route.Count;
                                }
                                if (route.route.Count > maxCandidate)
                                {
                                    maxCandidate = route.route.Count;
                                }
                                hasRouteCandidate = true;
                            }
                        }
                        if (hasRouteCandidate)
                        {
                            if (minCandidate < min)
                            {
                                minCandidate = min;
                            }
                            if (maxCandidate > max)
                            {
                                maxCandidate = max;
                            }
                            caseCandidate.UpdateContent(gear, minCandidate, maxCandidate, routes.Value.Any(r => r.nbOutOfBend > 0), true);
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        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);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void OnViewRollDice(int gear, int deValue)
        {
            var player = PlayerEngine.Instance.GetCurrent();

            if (deValue == 0)
            {
                var current = BoardEngine.Instance.GetCase(PlayerEngine.Instance.GetCurrentIndex(player));
                player.state = PlayerStateType.ChoseRoute;
                PlayerEngine.Instance.SelectedRoute(new RouteResult()
                {
                    route = new List <CaseManager>()
                    {
                        current
                    },
                    nbOutOfBend = 0,
                    isStandWay  = false,
                    isBadWay    = false,
                    nbLineMove  = 0
                });
                this.OnFinishMouvement();
            }
            else
            {
                PlayerEngine.Instance.UpdateGear(gear, deValue);

                int minValue;
                int maxValue;
                FeatureEngine.Instance.ComputeMinMaxUseBrake(player, deValue, out minValue, out maxValue);
                _candidateRoutes = BoardEngine.Instance.FindRoutes(player, minValue - 1, maxValue);

                if (ContextEngine.Instance.gameContext.state == GameStateType.Race)
                {
                    var playerStandCase = _candidateRoutes.routes.Select(r => r.Value.First().route.Last()).Where(r => r.standDataSource != null && r.standDataSource.playerIndex.HasValue).FirstOrDefault();
                    if (playerStandCase != null)
                    {
                        var standWay = _candidateRoutes.routes[playerStandCase.itemDataSource.index]
                                       .OrderBy(r => r.nbLineMove)
                                       .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous))
                                       .FirstOrDefault();
                        if (standWay != null && standWay.route.Count > 1)
                        {
                            var caseCandidate = standWay.route.Last();
                            caseCandidate.UpdateContent(gear, standWay.route.Count - 1, standWay.route.Count - 1, standWay.route.Any(r => r.isDangerous), false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                    else
                    {
                        var standWay = _candidateRoutes.routes.SelectMany(r => r.Value.Where(c => c.isStandWay).Select(c => c.route))
                                       .OrderByDescending(r => r.Last().itemDataSource.order)
                                       .ThenBy(r => r.Skip(1).Count(c => c.isDangerous))
                                       .FirstOrDefault();
                        if (standWay != null && standWay.Count > 1)
                        {
                            var caseCandidate = standWay.Last();
                            caseCandidate.UpdateContent(gear, standWay.Count - 1, standWay.Count - 1, standWay.Any(r => r.isDangerous), false);
                            caseCandidate.isCandidate = true;
                        }
                    }
                }

                foreach (var routes in _candidateRoutes.routes.Where(r => !r.Value.Any(rv => rv.isStandWay)))
                {
                    var route = routes.Value
                                .OrderBy(r => r.nbLineMove)
                                .ThenByDescending(r => r.route.Count - deValue)
                                .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                    if (route.isBadWay || route.route.Count - 1 >= minValue)
                    {
                        var caseCandidate = route.route.Last();
                        var hasWarning    = route.nbOutOfBend > 0;
                        if (!hasWarning && deValue - (route.route.Count - 1) >= 1)
                        {
                            hasWarning = true;
                        }
                        if (!hasWarning && route.route.Skip(1).Any(c => c.isDangerous))
                        {
                            hasWarning = true;
                        }
                        caseCandidate.UpdateContent(gear, route.route.Count - 1, route.route.Count - 1, hasWarning, route.isBadWay);
                        caseCandidate.isCandidate = true;
                    }
                }
            }
        }