Пример #1
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();
                }
            }
        }
Пример #2
0
        private Moves Launch()
        {
            Moves move = Moves.NO_ACTION;

            if (this.predictor != null)
            {
                if (predictor.CharactersReady() && predictor.SimulationHistoryDebugInformation.Count == 0)
                {
                    ActionSimulator sim = predictor;
                    sim.Update(1);

                    //TODO NAO e preciso esta treta toda dos status
                    CircleRepresentation circle = new CircleRepresentation(sim.CirclePositionX, sim.CirclePositionY,
                                                                           sim.CircleVelocityX, sim.CircleVelocityY, sim.CircleVelocityRadius);
                    RectangleRepresentation rectangle = new RectangleRepresentation(sim.RectanglePositionX, sim.RectanglePositionY,
                                                                                    sim.RectangleVelocityX, sim.RectangleVelocityY, sim.RectangleHeight);
                    ObstacleRepresentation dummy = new ObstacleRepresentation(sim.RectanglePositionX, sim.RectanglePositionY,
                                                                              Utils.getRectangleWidth(sim.RectangleHeight), sim.RectangleHeight);

                    Status futureCircle = new Status();
                    futureCircle.Update(circle, rectangle, dummy, AgentType.Circle);


                    if (this.Jumping)
                    {
                        if (this.rectangleInfo.Height > 160) //When almost fully morphed up, circle jumps
                        {
                            Log.LogInformation("REHEARSAL: Jumping!");
                            move = Moves.JUMP;
                            SendRequest(new Request(new Command.MorphUp()));
                            this.Jumping = false; //Already ended the jump
                        }
                        else //while rectangle not yet all morphed up
                        {
                            Log.LogInformation("REHEARSAL: Beginning the launch!");
                            move = Moves.NO_ACTION;
                            SendRequest(new Request(new Command.MorphUp()));
                        }
                    }
                    else
                    {
                        if (this.agentStatus.ABOVE_OTHER_AGENT == Utils.Quantifier.SLIGHTLY &&
                            this.agentStatus.LEFT_FROM_OTHER_AGENT == Utils.Quantifier.NONE &&
                            this.agentStatus.RIGHT_FROM_OTHER_AGENT == Utils.Quantifier.NONE &&
                            this.agentStatus.NEAR_OTHER_AGENT) //Ready to jump
                        {
                            if (this.agentStatus.MOVING)
                            {
                                Log.LogInformation("REHEARSAL: Still moving on top of rectangle");
                                move = HoldGround();
                                SendRequest(new Request(new Command.MorphDown()));
                            }
                            else //Prepare to jump
                            {
                                Log.LogInformation("REHEARSAL: Stopped, and activating launch sequence");
                                this.Jumping = true;
                                move         = Moves.NO_ACTION;
                                SendRequest(new Request(new Command.MorphUp()));
                            }
                        }
                        else //Position himself on top of the rectangle
                        {
                            Log.LogInformation("REHEARSAL: Jumping onto Rectangle");
                            move = JumpOntoRectangle();
                            SendRequest(new Request(new Command.MorphDown()));
                        }
                    }
                }
            }

            return(move);
        }
Пример #3
0
        //implements abstract circle interface: updates the agent state logic and predictions
        public override void Update(TimeSpan elapsedGameTime)
        {
            //Every second one new action is choosen
            if (lastMoveTime == 60)
            {
                lastMoveTime = 0;
            }

            if ((lastMoveTime) <= (DateTime.Now.Second) && (lastMoveTime < 60))
            {
                if (!(DateTime.Now.Second == 59))
                {
                    RandomAction();
                    lastMoveTime = lastMoveTime + 1;
                    //DebugSensorsInfo();
                }
                else
                {
                    lastMoveTime = 60;
                }
            }

            //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);
                    }
                }
            }

            //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);
                    //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();
                }
            }
        }