예제 #1
0
        private Path recursiveTraceBack(RectangleNode goalNode, Path l)
        {
            if (goalNode.getParent() == null)
            {
                l.AddNewPoint(goalNode.getState().point);
                return(l);
            }
            else
            {
                this.recursiveTraceBack(goalNode.getParent(), l);
                l.AddNewPoint(goalNode.getState().point);
                if (goalNode.getParent().getParent() != null)
                {
                    if (goalNode.getParent().getState().getVelocityX() != goalNode.getState().getVelocityX() && goalNode.getParent().getState().getPosY() >= goalNode.getState().getPosY())
                    {
                        goalNode.getParent().getState().point.TurningPoint = true;
                    }
                }

                return(l);
            }
        }
예제 #2
0
        public override Boolean validate(RectangleNode newnode, RectangleNode oldnode, InfoDomain domain, Graph graph)
        {
            State newstate = newnode.getState();
            State oldstate = oldnode.getState();

            // The 3rd and 4th action were already verified
            if (newnode.getState().getAction() == 3 || newnode.getState().getAction() == 4)
            {
                return(true);
            }

            if (outsideOfMap(newstate))
            {
                return(false);
            }
            else
            {
                if (isVerticalMovement(oldstate, newstate) || newstate.getAction() == 2)               //se foi gap nao fazer isto
                {
                    if (thereIsWallBetweenV(newstate, oldstate, domain))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    if (thereIsWallBetweenH(newstate, oldstate, domain))
                    {
                        if (emptyBottom)
                        {
                            oldnode._busyActions[3] = false;
                            emptyBottom             = false;
                            if (newstate.getVelocityX() == 0)
                            {
                                oldnode._busyMorphLeft = false;
                            }
                            else
                            {
                                oldnode._busyMorphRight = false;
                            }
                            //may need to put a turning point.
                        }
                        if (canPassOver(newstate, oldstate, domain))
                        {
                            oldnode._busyActions[4] = false;
                            if (newstate.getVelocityX() == 0)
                            {
                                oldnode._busyTiltLeft = false;
                            }
                            else
                            {
                                oldnode._busyTiltRight = false;
                            }
                            //may need to put a turning point.
                        }

                        if ((!oldnode._busyActions[3] || !oldnode._busyActions[4]))
                        {
                            if (!graph.NonBusyNodes.Contains(oldnode))
                            {
                                graph.NonBusyNodes.Add(oldnode);
                            }
                        }

                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
예제 #3
0
        public override RectangleNode apply(RectangleNode Xinit, InfoDomain _domain, Graph graph)
        {
            bool             newState = false;
            RectangleActions rAction  = new RectangleActions();
            int   action = 0;
            State s      = null;


            while (!newState)
            {
                if (Xinit.allActionsBusy())
                {
                    graph.NonBusyNodes.Remove(Xinit);
                    return(null);
                }

                action = rAction.getRandomAction();
                switch (action)
                {
                case 0:     //MOVE_LEFT
                    if (!Xinit._busyActions[0])
                    {
                        float[] newcoordinates = new float[4];
                        newcoordinates[0] = Xinit.getState().getPosX() - 32;
                        newcoordinates[1] = Xinit.getState().getPosY();
                        newcoordinates[2] = 0;      // 0 means going left
                        newcoordinates[3] = Xinit.getState().getVelocityY();
                        float[] gapInfo;

                        s = new State(newcoordinates[2], newcoordinates[3], newcoordinates[0], newcoordinates[1], 0, null, Xinit.getState().getAllCaughtCollectibles());
                        s.setSizeOfAgent(Xinit.getState().getSizeOfAgent());
                        s.point.Size = s.getSizeOfAgent();

                        int halfwidth  = getWidth(s.getSizeOfAgent()) / 2;
                        int halfheight = s.getSizeOfAgent() / 2;

                        if (s.getPosX() + MINSIZE / 2 <= Xinit.getState().CurrentPlatform.minWidth())
                        {
                            if ((!Xinit.getState().SpecialMoveL) && ((gapInfo = _domain.AllObstacles.isThereAGap(s, Xinit.getState().CurrentPlatform, min, max)) != null))
                            {
                                //when it's gap it just needs to keep on going, but for the planning sake
                                //we moved it's position to next platform's begining
                                s.setPosX(s.getPosX() - gapInfo[0] - halfwidth);
                                s.point.x         = s.getPosX();
                                s.CurrentPlatform = _domain.AllObstacles.getNextPlatform(s);
                                Xinit.getState().SpecialMoveL = true;
                                s.setPosX(s.CurrentPlatform.maxWidth() - halfwidth);
                                s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                s.point.Size = s.getSizeOfAgent();
                                s.point.x    = s.getPosX();
                            }
                            else
                            {
                                if (Xinit.getState().SpecialMoveL)
                                {
                                    gapInfo = gapInfo = _domain.AllObstacles.isThereAGap(s, Xinit.getState().CurrentPlatform, min, max);
                                    int gapsize = (int)gapInfo[3];
                                    if (gapsize <= NORMALSIZE)
                                    {
                                        s.setSizeOfAgent(getHeight(gapsize - 16));
                                        if (gapsize < MINSIZE)
                                        {
                                            s.setSizeOfAgent(MAXSIZE);
                                        }
                                    }
                                    else
                                    {
                                        s.setSizeOfAgent(NORMALSIZE);
                                    }

                                    s.CurrentPlatform = _domain.AllObstacles.getNextPlatformRange(s, NORMALSIZE);
                                    halfwidth         = getWidth(s.getSizeOfAgent()) / 2;
                                    halfheight        = s.getSizeOfAgent() / 2;
                                    s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                    s.point.y = Math.Min((Xinit.getState().CurrentPlatform.maxHeight() + NORMALSIZE), s.getPosY());
                                    s.point.x = Xinit.getState().CurrentPlatform.minWidth() - gapsize / 2;
                                    s.setPosX(s.point.x);
                                    s.point.Size    = s.getSizeOfAgent();
                                    s.point.FallGap = true;
                                }
                                else
                                {
                                    s.point.x = Xinit.getState().CurrentPlatform.minWidth() - halfwidth;
                                    s.setPosX(s.point.x);
                                    s.setSizeOfAgent(possibleHeight(s, _domain));
                                    halfwidth  = getWidth(s.getSizeOfAgent()) / 2;
                                    halfheight = s.getSizeOfAgent() / 2;
                                    s.setPosY(Xinit.getState().CurrentPlatform.maxHeight() - halfheight);     //so distanceForMomentum is correct
                                    s.CurrentPlatform = Xinit.getState().CurrentPlatform;
                                    int distance = distanceForMomentum(s, _domain);
                                    s.point.DistanceMomentum = distance;
                                    s.CurrentPlatform        = _domain.AllObstacles.getNextPlatformRange(s, distance);
                                    s.point.DistancePlatform = (int)Math.Max(0, Xinit.getState().CurrentPlatform.minWidth() - s.CurrentPlatform.maxWidth());
                                    s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                    s.point.y = Math.Min((Xinit.getState().CurrentPlatform.maxHeight() + NORMALSIZE), s.getPosY());
                                    s.point.x = Math.Min((Xinit.getState().CurrentPlatform.minWidth() - halfwidth), (s.CurrentPlatform.maxWidth() - halfwidth));
                                    s.setPosX(s.point.x);
                                    s.point.Size = s.getSizeOfAgent();
                                    s.point.Fall = true;
                                }


                                if (s.getSizeOfAgent() != Xinit.getState().getSizeOfAgent())
                                {
                                    s.point.Morph = true;
                                }
                                Xinit.setActionBusy(0);
                            }
                        }
                        else
                        {
                            Xinit.setActionBusy(0);
                            s.CurrentPlatform = Xinit.getState().CurrentPlatform;
                        }

                        this.caughtCollectible(Xinit.getState(), s);
                        s.point.numberOfCollectibles = s.numberOfCollectibles();
                        if (!this.contains(s, graph))
                        {
                            newState = true;
                        }
                    }
                    break;

                case 1:     //MOVE_RIGHT
                    if (!Xinit._busyActions[1])
                    {
                        float[] newcoordinates = new float[4];
                        newcoordinates[0] = Xinit.getState().getPosX() + 32;
                        newcoordinates[1] = Xinit.getState().getPosY();
                        newcoordinates[2] = 1;      // 1 means going right
                        newcoordinates[3] = Xinit.getState().getVelocityY();
                        float[] gapInfo;

                        s = new State(newcoordinates[2], newcoordinates[3], newcoordinates[0], newcoordinates[1], 1, null, Xinit.getState().getAllCaughtCollectibles());
                        s.setSizeOfAgent(Xinit.getState().getSizeOfAgent());
                        s.point.Size = s.getSizeOfAgent();

                        int halfwidth  = getWidth(s.getSizeOfAgent()) / 2;
                        int halfheight = s.getSizeOfAgent() / 2;

                        if (s.getPosX() - MINSIZE / 2 >= Xinit.getState().CurrentPlatform.maxWidth())
                        {
                            if ((!Xinit.getState().SpecialMoveR) && ((gapInfo = _domain.AllObstacles.isThereAGap(s, Xinit.getState().CurrentPlatform, min, max)) != null))
                            {
                                //when it's gap it just needs to keep on going, but for the planning sake
                                //we moved it's position to next platform's begining
                                s.setPosX(s.getPosX() + gapInfo[0] + halfwidth);
                                s.point.x         = s.getPosX();
                                s.CurrentPlatform = _domain.AllObstacles.getNextPlatform(s);
                                Xinit.getState().SpecialMoveR = true;
                                s.setPosX(s.CurrentPlatform.minWidth() + halfwidth);
                                s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                s.point.y = s.getPosY();
                                s.point.x = s.getPosX();
                            }
                            else
                            {
                                if (Xinit.getState().SpecialMoveR)
                                {
                                    gapInfo = _domain.AllObstacles.isThereAGap(s, Xinit.getState().CurrentPlatform, min, max);
                                    int gapsize = (int)gapInfo[3];
                                    if (gapsize <= NORMALSIZE)
                                    {
                                        s.setSizeOfAgent(getHeight(gapsize - 16));
                                        if (gapsize < MINSIZE)
                                        {
                                            s.setSizeOfAgent(MAXSIZE);
                                        }
                                    }
                                    else
                                    {
                                        s.setSizeOfAgent(NORMALSIZE);
                                    }
                                    s.CurrentPlatform = _domain.AllObstacles.getNextPlatformRange(s, NORMALSIZE);
                                    halfwidth         = getWidth(s.getSizeOfAgent()) / 2;
                                    halfheight        = s.getSizeOfAgent() / 2;
                                    s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                    s.point.y = Math.Min((Xinit.getState().CurrentPlatform.maxHeight() + NORMALSIZE), s.getPosY());
                                    s.point.x = Xinit.getState().CurrentPlatform.maxWidth() + gapsize / 2;
                                    s.setPosX(s.point.x);
                                    s.point.Size    = s.getSizeOfAgent();
                                    s.point.FallGap = true;
                                }
                                else
                                {
                                    s.point.x = Xinit.getState().CurrentPlatform.maxWidth() + halfwidth;
                                    s.setPosX(s.point.x);
                                    s.setSizeOfAgent(possibleHeight(s, _domain));
                                    halfwidth  = getWidth(s.getSizeOfAgent()) / 2;
                                    halfheight = s.getSizeOfAgent() / 2;
                                    s.point.x  = Xinit.getState().CurrentPlatform.maxWidth() + halfwidth;
                                    s.setPosX(s.point.x);
                                    s.setPosY(Xinit.getState().CurrentPlatform.maxHeight() - halfheight);
                                    s.CurrentPlatform = Xinit.getState().CurrentPlatform;
                                    int distance = distanceForMomentum(s, _domain);
                                    s.point.DistanceMomentum = distance;
                                    s.CurrentPlatform        = _domain.AllObstacles.getNextPlatformRange(s, distance);
                                    s.point.DistancePlatform = (int)Math.Max(0, s.CurrentPlatform.minWidth() - Xinit.getState().CurrentPlatform.maxWidth());
                                    s.setPosY(s.CurrentPlatform.maxHeight() - halfheight);
                                    s.point.y = Math.Min((Xinit.getState().CurrentPlatform.maxHeight() + NORMALSIZE), s.getPosY());
                                    s.point.x = Math.Max((Xinit.getState().CurrentPlatform.maxWidth() + halfwidth), (s.CurrentPlatform.minWidth() + halfwidth));
                                    s.setPosX(s.point.x);
                                    s.point.Size = s.getSizeOfAgent();
                                    s.point.Fall = true;
                                }

                                if (s.getSizeOfAgent() != Xinit.getState().getSizeOfAgent())
                                {
                                    s.point.Morph = true;
                                }
                                Xinit.setActionBusy(1);
                            }
                        }
                        else
                        {
                            Xinit.setActionBusy(1);
                            s.CurrentPlatform = Xinit.getState().CurrentPlatform;
                        }


                        this.caughtCollectible(Xinit.getState(), s);
                        s.point.numberOfCollectibles = s.numberOfCollectibles();
                        if (!this.contains(s, graph))
                        {
                            newState = true;
                        }
                    }
                    break;

                case 2:     //MORPH_UP
                    if (!Xinit._busyActions[2])
                    {
                        float[] newcoordinates = new float[4];
                        newcoordinates[0] = Xinit.getState().getPosX();
                        newcoordinates[1] = Xinit.getState().getPosY() + Xinit.getState().getSizeOfAgent() / 2 - MAXSIZE;
                        newcoordinates[2] = Xinit.getState().getVelocityX();
                        newcoordinates[3] = Xinit.getState().getVelocityY();

                        s = new State(newcoordinates[2], newcoordinates[3], newcoordinates[0], newcoordinates[1], 2, null, Xinit.getState().getAllCaughtCollectibles());
                        s.setSizeOfAgent(Xinit.getState().getSizeOfAgent());

                        Xinit.setActionBusy(2);
                        s.CurrentPlatform = Xinit.getState().CurrentPlatform;

                        this.caughtCollectible(Xinit.getState(), s);
                        s.setPosY(Xinit.getState().getPosY());
                        s.point.y = s.getPosY();     //ok?
                        if (Xinit.getState().sizeOfCaughtCollectible() < s.sizeOfCaughtCollectible())
                        {
                            s.point.DiamondAbove = true;
                            if (Xinit.getState().getAction() == 0)
                            {
                                s.point.x -= 32;
                                s.point.x -= radius;
                            }
                            else if (Xinit.getState().getAction() == 1)
                            {
                                s.point.x += 32;
                                s.point.x += radius;
                            }
                        }
                        else
                        {
                            continue;
                        }

                        s.point.numberOfCollectibles = s.numberOfCollectibles();
                        if (!this.contains(s, graph))
                        {
                            newState = true;
                        }
                    }
                    break;

                case 3:     //MORPH_DOWN
                    if (!Xinit._busyActions[3])
                    {
                        float[] newcoordinates = new float[4];
                        if (!Xinit._busyMorphLeft)
                        {
                            newcoordinates[2]    = 0;
                            Xinit._busyMorphLeft = true;
                        }
                        else if (!Xinit._busyMorphRight)
                        {
                            newcoordinates[2]     = 1;
                            Xinit._busyMorphRight = true;
                        }

                        newcoordinates[3] = Xinit.getState().getVelocityY();
                        if (newcoordinates[2] == 0)
                        {
                            newcoordinates[0] = Xinit.getState().getPosX() - 32;
                        }
                        else if (newcoordinates[2] == 1)
                        {
                            newcoordinates[0] = Xinit.getState().getPosX() + 32;
                        }
                        newcoordinates[1] = Xinit.getState().getPosY() + Xinit.getState().getSizeOfAgent() / 2 - MINSIZE / 2;
                        //float[] gapInfo;

                        s = new State(newcoordinates[2], newcoordinates[3], newcoordinates[0], newcoordinates[1], 3, null, Xinit.getState().getAllCaughtCollectibles());
                        s.setSizeOfAgent(MINSIZE);
                        s.point.Size = s.getSizeOfAgent();

                        s.CurrentPlatform = Xinit.getState().CurrentPlatform;

                        s.point.Morph = true;
                        this.caughtCollectible(Xinit.getState(), s);

                        s.point.numberOfCollectibles = s.numberOfCollectibles();
                        if (Xinit._busyMorphLeft && Xinit._busyMorphRight)
                        {
                            Xinit.setActionBusy(3);
                        }
                        if (!this.contains(s, graph))     //TODO equals ter em conta o size
                        {
                            newState = true;
                        }
                    }
                    break;

                case 4:     //TILT
                    if (!Xinit._busyActions[4])
                    {
                        int     halfwidth      = getWidth(Xinit.getState().getSizeOfAgent()) / 2;
                        float[] newcoordinates = new float[4];
                        if (!Xinit._busyTiltLeft)
                        {
                            Xinit._busyTiltLeft = true;
                            newcoordinates[2]   = 0;
                            newcoordinates[0]   = Xinit.getState().getPosX() - 32 - halfwidth;
                        }
                        else if (!Xinit._busyTiltRight)
                        {
                            Xinit._busyTiltRight = true;
                            newcoordinates[2]    = 1;
                            newcoordinates[0]    = Xinit.getState().getPosX() + 32 + halfwidth;
                        }
                        newcoordinates[3] = Xinit.getState().getVelocityY();
                        newcoordinates[1] = Xinit.getState().getPosY() - 96;

                        s = new State(newcoordinates[2], newcoordinates[3], newcoordinates[0], newcoordinates[1], 4, null, Xinit.getState().getAllCaughtCollectibles());
                        s.setSizeOfAgent(96);
                        s.point.Size      = s.getSizeOfAgent();
                        s.CurrentPlatform = _domain.AllObstacles.getNextPlatform(s);
                        s.point.Size      = getMaxHeight(s, Xinit.getState(), _domain) - 10;
                        //Can be wrong if platform is smaller than 96
                        if (newcoordinates[2] == 0)
                        {
                            s.setPosX(s.CurrentPlatform.maxWidth() - s.getSizeOfAgent() / 2);   //change if you change the size from 96
                        }
                        else
                        {
                            s.setPosX(s.CurrentPlatform.minWidth() + s.getSizeOfAgent() / 2);   //change if you change the size from 96
                        }
                        s.setPosY(s.CurrentPlatform.maxHeight() - s.getSizeOfAgent() / 2);
                        s.point.Tilt = true;

                        this.caughtCollectible(Xinit.getState(), s);     //TODO ter em conta o start diferente
                        if (Xinit._busyTiltLeft && Xinit._busyTiltRight)
                        {
                            Xinit.setActionBusy(4);
                        }
                        s.point.numberOfCollectibles = s.numberOfCollectibles();
                        if (!this.contains(s, graph))     //TODO equals ter em conta o size
                        {
                            newState = true;
                        }
                    }
                    break;
                }
            }
            RectangleNode n = new RectangleNode(s);

            return(n);
        }