Exemple #1
0
    public SimpleRoute(SimpleRoute route1, SimpleRoute route2)
    {
        _patrolRouteGen = new List <SimpleAction>();

        for (int i = 0; i < route1.PatrolRouteGen.Count; i++)
        {
            _patrolRouteGen.Add(route1.PatrolRouteGen[i].Copy());
        }

        for (int i = 0; i < route2.PatrolRouteGen.Count; i++)
        {
            _patrolRouteGen.Add(route2.PatrolRouteGen[i].Copy());
        }

        _startNode = new Vector2();
        if (Random.value <= 0.5)
        {
            _startNode.x = route1.StartNode.x;
        }
        else
        {
            _startNode.x = route2.StartNode.x;
        }

        if (Random.value <= 0.5)
        {
            _startNode.y = route1.StartNode.y;
        }
        else
        {
            _startNode.y = route2.StartNode.y;
        }
    }
Exemple #2
0
    public SimpleRoute(SimpleRoute route, Vector2 startNode, int start = 0, int end = -1)
    {
        _patrolRouteGen = new List <SimpleAction>();

        if (end == -1)
        {
            end = route.PatrolRouteGen.Count;
        }

        if (start <= end)
        {
            for (int i = start; i < end; i++)
            {
                _patrolRouteGen.Add(route.PatrolRouteGen[i].Copy());
            }
        }
        else
        {
            for (int i = start; i < route.PatrolRouteGen.Count; i++)
            {
                _patrolRouteGen.Add(route.PatrolRouteGen[i].Copy());
            }

            for (int i = 0; i < end; i++)
            {
                _patrolRouteGen.Add(route.PatrolRouteGen[i].Copy());
            }
        }

        _startNode = startNode;
    }
Exemple #3
0
    public Guard(SimpleRoute route)
    {
        _lastId++;
        _id = _lastId;

        _patrol      = route;
        _routeLength = route.PatrolRoutePhen.Count;
        _guardState  = GuardStates.Patrol;
    }
Exemple #4
0
        public void PostResolveRequestCache(object sender, EventArgs e)
        {
            //得到http上下文
            HttpContext context = (sender as HttpApplication).Context;
            //当前url
            string    currentUrl = context.Request.RawUrl;
            IWebRoute route      = new SimpleRoute();

            //url过路由
            route.distributionHttpHandler(currentUrl, context);
        }
Exemple #5
0
    public SimpleRoute(SimpleRoute route)
    {
        _patrolRouteGen = new List <SimpleAction>();

        for (int i = 0; i < route.PatrolRouteGen.Count; i++)
        {
            _patrolRouteGen.Add(route.PatrolRouteGen[i].Copy());
        }

        _startNode = route.StartNode;
    }
Exemple #6
0
    // crossover
    private static List <SimpleRoute> Crossover(SimpleRoute p1, SimpleRoute p2, int routeLength)
    {
        int index = Random.Range(1, routeLength - 1);

        List <SimpleRoute> subroutes1 = p1.Divide(index);
        List <SimpleRoute> subroutes2 = p2.Divide(index);

        List <SimpleRoute> children = new List <SimpleRoute>()
        {
            new SimpleRoute(subroutes1[0], subroutes2[1]),
            new SimpleRoute(subroutes2[0], subroutes1[1])
        };

        return(children);
    }
    // generates a random route
    public static SimpleRoute RandomRoute(int routeLength, Map map)
    {
        int width  = map.Width;
        int height = map.Height;
        int N      = routeLength;

        SimpleRoute route = new SimpleRoute(new Vector2((float)(Random.Range(0, width)), (float)(Random.Range(0, height))));

        for (int j = 0; j < N; j++)
        {
            route.Add(new SimpleAction((Node.Dir)(Random.Range(0, 4))));
        }

        return(route);
    }
Exemple #8
0
    // bins matrices difference calculator
    private static float DifferenceMeasure(SimpleRoute r1, SimpleRoute r2)
    {
        float measure = 0f;

        for (int x = 0; x < r1.Distribution.Length; x++)
        {
            for (int y = 0; y < r1.Distribution[0].Length; y++)
            {
                measure += Mathf.Abs(r1.Distribution[x][y] - r2.Distribution[x][y]);
            }
        }

        measure /= 2;

        return(measure);
    }