コード例 #1
0
        //implements abstract rectangle interface: updates the agent state logic and predictions
        public override void Update(TimeSpan elapsedGameTime)
        {
            if (this.collectiblesInfo.Length > 0)
            {
                this.agentStatus.Update(this.circleInfo, this.rectangleInfo, this.collectiblesInfo[0], AgentType.Rectangle, currentAction);
            }

            //prepare all the debug information to be passed to the agents manager
            List <DebugInformation> newDebugInfo = new List <DebugInformation>();

            // see nodes considered by A*
            // No need to show duplicated nodes
            // Graph.ShowNodes(newDebugInfo, this.graph);
            // see path created by A*
            if (Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS)
            {
                this.graph.showAllKnownPaths(newDebugInfo, this.type);
            }
            else
            {
                // see current path
                if (this.nextDiamondPath != null)
                {
                    Graph.showPath(newDebugInfo, this.nextDiamondPath.path, this.type);
                }
            }

            //List<DebugInformation> debug = new List<DebugInformation>();
            //debug.AddRange(this.debugInfo);
            //debug.AddRange(newDebugInfo.ToArray());

            //PARA TESTAR
            if (this.diamondsToCatch.Count > this.nCollectiblesLeft)
            {
                Node node = this.graph.diamondNodes[nextDiamondIndex];
                catchNextDiamond(node);
            }

            if (this.diamondsToCatch.Count > 0)
            {
                this.currentAction = this.decideActionFromCurrentPath();
            }


            this.debugInfo = newDebugInfo.ToArray();
        }
コード例 #2
0
        //implements abstract circle interface: updates the agent state logic and predictions
        public override void Update(TimeSpan elapsedGameTime)
        {
            // Execute an action every 'moveStep' cycles
            if (iterationCount == moveStep)
            {
                DecideAction();
                iterationCount = 0;
            }

            iterationCount++;

            //check if any collectible was caught
            lock (remaining)
            {
                if (remaining.Count > 0)
                {
                    List <CollectibleRepresentation> toRemove = new List <CollectibleRepresentation>();
                    foreach (CollectibleRepresentation item in uncaughtCollectibles)
                    {
                        if (!remaining.Contains(item))
                        {
                            caughtCollectibles.Add(item);
                            toRemove.Add(item);
                        }
                    }
                    foreach (CollectibleRepresentation item in toRemove)
                    {
                        uncaughtCollectibles.Remove(item);

                        //PARA TESTAR
                        Node  circleNextNode = this.graph.diamondNodes[nextDiamondIndex];
                        Point point          = new Point((int)item.X, (int)item.Y);
                        Node  caughtNode     = new Node(point.X, point.Y, Node.Type.Diamond);



                        if (point == circleNextNode.location)
                        {
                            updateNextDiamond(caughtNode);
                            SendRequest(new Request(new Command.DeleteDiamond(caughtNode)));
                        }
                        else
                        {
                            SendRequest(new Request(new Command.CatchNextDiamond(caughtNode)));
                            deleteDiamond(caughtNode);
                        }
                    }
                }
            }

            //predict what will happen to the agent given the current state and current action
            if (predictor != null) //predictions are only possible where the agents manager provided
            {
                /*
                 * 1) simulator can only be properly used when the Circle and Rectangle characters are ready, this must be ensured for smooth simulation
                 * 2) in this implementation we only wish to simulate a future state when whe have a fresh simulator instance, i.e. the generated debug information is empty
                 */
                if (predictor.CharactersReady() && predictor.SimulationHistoryDebugInformation.Count == 0)
                {
                    List <CollectibleRepresentation> simCaughtCollectibles = new List <CollectibleRepresentation>();
                    //keep a local reference to the simulator so that it can be updated even whilst we are performing simulations
                    ActionSimulator toSim = predictor;

                    //prepare the desired debug information (to observe this information during the game press F1)
                    toSim.DebugInfo = true;
                    //you can also select the type of debug information generated by the simulator to circle only, rectangle only or both as it is set by default
                    //toSim.DebugInfoSelected = ActionSimulator.DebugInfoMode.Circle;

                    //setup the current circle action in the simulator
                    toSim.AddInstruction(currentAction);

                    //register collectibles that are caught during simulation
                    toSim.SimulatorCollectedEvent += delegate(Object o, CollectibleRepresentation col) { simCaughtCollectibles.Add(col); };

                    //simulate 2 seconds (predict what will happen 2 seconds ahead)
                    toSim.Update(2);

                    //prepare all the debug information to be passed to the agents manager
                    List <DebugInformation> newDebugInfo = new List <DebugInformation>();
                    //clear any previously passed debug information (information passed to the manager is cumulative unless cleared in this way)
                    newDebugInfo.Add(DebugInformationFactory.CreateClearDebugInfo());
                    //add all the simulator generated debug information about circle/rectangle predicted paths
                    newDebugInfo.AddRange(toSim.SimulationHistoryDebugInformation);

                    // see nodes considered by A*
                    Graph.ShowNodes(newDebugInfo, this.graph);

                    // see initial paths created by A*
                    if (Utils.AIAD_DEMO_A_STAR_INITIAL_PATHS)
                    {
                        this.graph.showAllKnownPaths(newDebugInfo, this.type);
                    }

                    //see current path
                    else
                    {
                        Graph.showPath(newDebugInfo, this.nextDiamondPath.path, this.type);
                    }


                    //create additional debug information to visualize collectibles that have been predicted to be caught by the simulator
                    foreach (CollectibleRepresentation item in simCaughtCollectibles)
                    {
                        newDebugInfo.Add(DebugInformationFactory.CreateCircleDebugInfo(new PointF(item.X - debugCircleSize / 2, item.Y - debugCircleSize / 2), debugCircleSize, GeometryFriends.XNAStub.Color.Red));
                        newDebugInfo.Add(DebugInformationFactory.CreateTextDebugInfo(new PointF(item.X, item.Y), "Predicted catch!", GeometryFriends.XNAStub.Color.White));
                    }
                    //create additional debug information to visualize collectibles that have already been caught by the agent
                    foreach (CollectibleRepresentation item in caughtCollectibles)
                    {
                        newDebugInfo.Add(DebugInformationFactory.CreateCircleDebugInfo(new PointF(item.X - debugCircleSize / 2, item.Y - debugCircleSize / 2), debugCircleSize, GeometryFriends.XNAStub.Color.GreenYellow));
                    }
                    //set all the debug information to be read by the agents manager
                    debugInfo = newDebugInfo.ToArray();
                }
            }
        }