protected abstract void updateVelocity(Moves action);
 public void removeMove(Moves move)
 {
     remainingMoves.Remove(move);
 }
Exemple #3
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);
        }
 public abstract List <DebugInformation> simulate(Moves action, float time);
Exemple #5
0
 internal void MorphUp()
 {
     this.currentAction = Moves.MORPH_UP;
 }
Exemple #6
0
        //TODO If near Obstacle, but still below, doesnt jump
        private Moves JumpOnto(ObstacleRepresentation obstacle)
        {
            Moves move = Moves.NO_ACTION;

            Status statusCircle = new Status();

            statusCircle.Update(this.circleInfo, this.rectangleInfo, obstacle, AgentType.Circle);

            Utils.Quantifier Distance_From_Obstacle;
            Moves            Roll_To_Obstacle;
            Moves            Roll_Away_From_Obstacle;

            Utils.Direction Direction_To_Get_To_Obstacle;

            if (statusCircle.LEFT_FROM_TARGET == Utils.Quantifier.NONE) //Circle is on the obstacle's right side
            {
                Distance_From_Obstacle       = statusCircle.RIGHT_FROM_TARGET;
                Roll_To_Obstacle             = Moves.ROLL_LEFT;
                Roll_Away_From_Obstacle      = Moves.ROLL_RIGHT;
                Direction_To_Get_To_Obstacle = Utils.Direction.LEFT;
            }
            else if (statusCircle.RIGHT_FROM_TARGET == Utils.Quantifier.NONE)//Circle is on the obstacle's left side
            {
                Distance_From_Obstacle       = statusCircle.LEFT_FROM_TARGET;
                Roll_To_Obstacle             = Moves.ROLL_RIGHT;
                Roll_Away_From_Obstacle      = Moves.ROLL_LEFT;
                Direction_To_Get_To_Obstacle = Utils.Direction.RIGHT;
            }
            else //Circle is vertically aligned with obstacle
            {
                Distance_From_Obstacle       = Utils.Quantifier.NONE;
                Roll_To_Obstacle             = Moves.NO_ACTION;
                Roll_Away_From_Obstacle      = Moves.NO_ACTION;
                Direction_To_Get_To_Obstacle = Utils.Direction.RIGHT; //Default, not gonna be used
            }

            if (statusCircle.MOVING_TOWARDS_TARGET == Utils.Quantifier.NONE) //When circle is not moving towards the target
            {
                if (statusCircle.NEAR_TARGET)
                {
                    if (statusCircle.ABOVE_TARGET == Utils.Quantifier.SLIGHTLY) //Already Above target
                    {
                        move = Moves.NO_ACTION;
                    }
                    else //Has to roll away from target to gain speed to jump
                    {
                        if (Distance_From_Obstacle == Utils.Quantifier.NONE) //Is directly below target
                        {
                            //TODO CIRCLE MUST FIND A WAY TO TRY TO POSITION HIMSELF TO JUMP
                            move = Moves.NO_ACTION; //TODO PROVISIONAL
                        }
                        else
                        {
                            move = Roll_Away_From_Obstacle;
                        }
                    }
                }
                else //Circle has to start moving in the obstacle's direction, because is far away
                {
                    move = Roll_To_Obstacle;
                }
            }
            else //When the circle is moving towards the target
            {
                if (Distance_From_Obstacle == Utils.Quantifier.SLIGHTLY) //when the circle has to jump now
                {
                    move = Moves.JUMP;
                }
                else if (Distance_From_Obstacle > Utils.Quantifier.A_BIT) //When the circle is very far away, and has to go fast
                {
                    move = Roll(Direction_To_Get_To_Obstacle, Utils.Quantifier.A_BIT);
                }
                else if (Distance_From_Obstacle > Utils.Quantifier.SLIGHTLY) //When the circle is almost in the jumping spot
                {
                    move = Roll(Direction_To_Get_To_Obstacle, Utils.Quantifier.SLIGHTLY);
                }
                else //When an error occurs
                {
                    move = Moves.NO_ACTION;
                }
            }

            Log.LogInformation("JUMP_ONTO");
            Log.LogInformation(statusCircle.ToString());
            Log.LogInformation(move.ToString());
            return(move);
        }
Exemple #7
0
 internal void NoAction()
 {
     this.currentAction = Moves.NO_ACTION;
 }
        /********************************************************************************************/
        /********************************************************************************************/
        /***                                                                                      ***/
        /***                                     PLANNING                                         ***/
        /***                                                                                      ***/
        /********************************************************************************************/
        /********************************************************************************************/

        private void planSolution()
        {
            //The agent must be still so it starts at the same position as the one in the first point of the plan
            //This is to guarantee that the agent stops before start planning, and keeps still
            if (circleInfo.VelocityY < correctVelYMargin && circleInfo.VelocityY > -correctVelYMargin &&
                circleInfo.VelocityX < correctVelXMargin && circleInfo.VelocityX > -correctVelXMargin &&
                utils.onPlatform(circleInfo.X, circleInfo.Y + circleInfo.Radius, 25, 10) != null)
            {
                //make sure there is nothing moving the agent when planning
                currentAction = Moves.NO_ACTION;

                //if the plan is new build a new tree
                if (newPlan)
                {
                    List <DiamondInfo> remainingDiamonds = new List <DiamondInfo>();
                    List <DiamondInfo> caughtDiamonds    = new List <DiamondInfo>();
                    foreach (DiamondInfo diamond in Diamonds)
                    {
                        if (!diamond.wasCaught())
                        {
                            remainingDiamonds.Add(diamond);
                        }
                        else
                        {
                            caughtDiamonds.Add(diamond);
                        }
                    }

                    //Simulator
                    Simulator sim = new CircleSimulator(Platforms);
                    sim.setSimulator(circleInfo.X, circleInfo.Y, circleInfo.VelocityX, circleInfo.VelocityY, remainingDiamonds);

                    //update the diamond list
                    RRT.setDiamonds(Diamonds);
                    //create initial state
                    State initialState = new State(circleInfo.X, circleInfo.Y, circleInfo.VelocityX, circleInfo.VelocityY, circleInfo.Radius, circleInfo.Radius, caughtDiamonds, remainingDiamonds);
                    //run algorithm
                    T = RRT.buildNewRRT(initialState, sim, iterationsS);
                }
                else //continue the previous tree
                {
                    T = RRT.RRT(T);
                }
                //draw the nodes of the tree
                if (debugTree)
                {
                    debugInfo = RRT.getDebugTreeInfo(T).ToArray();
                }

                newPlan = false;

                //if the argorithm reached a goal state or a semi plan then get the plan
                if (T.getGoal() != null)
                {
                    if (!written)
                    {
                        int exploredNodesOnce  = RRT.getExploredNodesOnce();
                        int exploredNodesTotal = RRT.getExploredNodesTotal();
                        int totalNodes         = T.getNodes().Count;
                        utils.writeTimeToFile(1, 0, searchTime, exploredNodesOnce, exploredNodesTotal, totalNodes, gSpeed);
                        written = true;
                    }

                    pathPlan = RRT.getPlan(T);

                    firstAction = true;
                    lastMove    = Moves.NO_ACTION;


                    //do not plan on the next iteration
                    planRRT      = false;
                    getDebugInfo = true;

                    //save a copy of the original plan
                    if (cutplan)
                    {
                        pathPlan.cleanPlan(obstaclesInfo, Diamonds, area, circleInfo.Radius, true, true);
                    }
                    originalPlan = pathPlan.clone();
                    pathPlan.saveOriginal();
                }
            }
            else
            {
                keepStill();
            }
        }
Exemple #9
0
 /**
  * Functions below describe what effects a command has.
  */
 public void MoveLeft()
 {
     this.currentAction = Moves.MOVE_LEFT;
 }
Exemple #10
0
 public void MoveRight()
 {
     this.currentAction = Moves.MOVE_RIGHT;
 }
Exemple #11
0
        private void DiscoverAction()
        {
            model.VerifyPlatform();
            if (model.AgentPlatform != null)
            {
                GameState state = model.GetGameState();
                if (model.WillHaveMoves() && learningCenter.ContainsState(state.GetStateId()))
                {
                    if (!gameStateId.Equals(state.GetStateId()))
                    {
                        gameStateId = state.GetStateId();
                        numberOfMovements++;
                        knownStatesNumber++;
                        if (rnd.NextDouble() < 0.2)
                        {
                            bool hasNewAction = false;
                            //currentAction = -1;
                            double maxValue = 0;
                            foreach (Moves move in learningCenter.GetMovesForState(state.GetStateId()))
                            {
                                if (learningCenter.GetMoveValueInState(move, state.GetStateId()) > maxValue)
                                {
                                    maxValue      = learningCenter.GetMoveValueInState(move, state.GetStateId());
                                    currentAction = move;
                                    hasNewAction  = true;
                                }
                            }
                            if (hasNewAction)
                            {
                                selectAction();
                                return;
                            }
                        }
                    }
                    if (rnd.Next(1, 3) > 1 && model.WillHaveMoves())
                    {
                        currentAction = model.FindMoveTowardsClosestCollectible();
                    }
                    else
                    {
                        RandomAction();
                    }

                    selectAction();
                    return;
                }

                numberOfMovements++;
                if (rnd.Next(1, 3) > 1 && model.WillHaveMoves())
                {
                    currentAction = model.FindMoveTowardsClosestCollectible();
                }
                else
                {
                    RandomAction();
                }



                selectAction();
            }
            else
            {
                currentAction = Moves.NO_ACTION;
            }
        }
Exemple #12
0
 public NodeSimulator(Node p, State s, Moves action, Simulator sim, List <Moves> moves) : base(p, s, action, moves)
 {
     simulator = sim;
 }
        /*******************************************************/
        /*                  Planning - aux                     */
        /*******************************************************/

        //used when trying to recover a plan where the agent is not on a platform and state of the plan
        //join plans on utils

        //simple plan recovery - check if agent is on a platform that belongs to the plan and with the same state
        private void recoverPlan()
        {
            //TODO - update debug drawing
            currentAction          = Moves.NO_ACTION;
            lastMove               = Moves.NO_ACTION;
            controller.jumpReached = false;
            controller.rollReached = false;

            //see if there is a point in the original plan that is the same as the one the agent is on and that has the same number or less of diamonds caught
            bool pointFound = false;

            Platform     currentPlatform = utils.onPlatform(circleInfo.X, circleInfo.Y + circleInfo.Radius, 25, 10);
            List <Point> pathPoints      = pathPlan.getOriginalPoints();

            int i;

            //start from the end
            for (i = pathPoints.Count - 1; i >= 0; i--)
            {
                if (pathPoints[i].getUncaughtDiamonds().Count >= uncaughtCollectibles.Count)
                {
                    Platform pointPlatform = utils.onPlatform(pathPoints[i].getPosX(), pathPoints[i].getPosY() + circleInfo.Radius, 25, 10);

                    if (utils.samePlatform(currentPlatform, pointPlatform) && !utils.obstacleBetween(circleInfo.X, pathPoints[i].getPosX(), currentPlatform))
                    {
                        pointFound = true;
                        break;
                    }
                }
            }
            if (pointFound)
            {
                //create a new plan from the point we got previously
                pathPlan = new PathPlan(cutplan, remaining.Count, utils);
                pathPlan.setTotalCollectibles(originalPlan.getTotalCollectibles());
                pathPlan.setCurrentPoint(i);

                for (int j = i; j < pathPoints.Count; j++)
                {
                    pathPlan.addPointEnd(pathPoints[j]);
                }
                pathPlan.setOriginalPoints(pathPoints);
                firstAction = true;
                return;
            }
            //if no platform in common was found, then try to find a way to a platform in the plan and replan if this fails
            else if (pathPlan.getPathPoints().Count != 0)
            {
                List <DiamondInfo> remainingDiamonds = new List <DiamondInfo>();
                List <DiamondInfo> caughtDiamonds    = new List <DiamondInfo>();
                foreach (DiamondInfo diamond in Diamonds)
                {
                    if (!diamond.wasCaught())
                    {
                        remainingDiamonds.Add(diamond);
                    }
                    else
                    {
                        caughtDiamonds.Add(diamond);
                    }
                }

                //Simulator
                Simulator sim = new CircleSimulator(Platforms);
                sim.setSimulator(circleInfo.X, circleInfo.Y, circleInfo.VelocityX, circleInfo.VelocityY, remainingDiamonds);

                //TEST
                RRT.setDiamonds(Diamonds);

                State   initialState = new State(circleInfo.X, circleInfo.Y, circleInfo.VelocityX, circleInfo.VelocityY, circleInfo.Radius, circleInfo.Radius, caughtDiamonds, remainingDiamonds);
                float[] returnPos    = new float[2];
                returnPos[0] = pathPlan.getPathPoints()[0].getPosX();
                returnPos[1] = pathPlan.getPathPoints()[0].getPosY();
                RRT.setReturnPos(returnPos);
                Tree t = RRT.buildNewMPRRT(initialState, sim, GoalType.Return, iterationsS);

                if (t.getGoal() != null)
                {
                    PathPlan shortPlan = RRT.getPlan(t);
                    pathPlan = pathPlan.joinPlans(shortPlan, pathPlan);
                    pathPlan.cleanPlan(obstaclesInfo, remainingDiamonds, area, circleInfo.Radius, true, true);
                    getDebugInfo = true;
                    return;
                }
                else
                {
                    replan(false);
                }
            }
            replan(false);
        }
 private void SetAction(Moves a)
 {
     currentAction = a;
 }
Exemple #15
0
 internal void MorphDown()
 {
     this.currentAction = Moves.MORPH_DOWN;
 }
 public NodeGS(Node p, State s, Moves action, ActionSimulator predictor, List <Moves> moves) : base(p, s, action, moves)
 {
     simulator = predictor;
 }
        public override Moves getActionRectangle()
        {
            Moves action = rectangleSingleplayer.GetAction();

            return(action);
        }