예제 #1
0
        private int getMaxHeight(State state, State previousState, InfoDomain domain)
        {
            int centerx;

            if (state.getVelocityX() == 0)
            {
                centerx = (int)(state.CurrentPlatform.maxWidth() - 40 + MINSIZE / 2) / 8;
            }
            else
            {
                centerx = (int)(state.CurrentPlatform.minWidth() - 40 - MINSIZE / 2) / 8;
            }
            int y      = (int)(previousState.CurrentPlatform.maxHeight() - 40 - MAXSIZE) / 8;
            int limit  = y + 12;
            int startx = centerx - MINSIZE / 8 / 2;
            int endx   = centerx + MINSIZE / 8 / 2 - 1;

            int[,] table = domain.Table;

            for (; y < limit; y--)
            {
                for (int x = startx; x < endx; x++)
                {
                    if (!(table[y, x] == 1 || table[y, x] == 2))
                    {
                        return((int)(previousState.CurrentPlatform.maxHeight() - (y * 8 + 40)));
                    }
                }
            }
            return(96);
        }
예제 #2
0
        public override Boolean validate(CircleNode newnode, CircleNode oldnode, InfoDomain domain, Graph graph)
        {
            State newstate = newnode.getState();
            State oldstate = oldnode.getState();

            if (outsideOfMap(newstate))
            {
                return(false);
            }
            else
            {
                if (isVerticalMovement(oldstate, newstate) || newstate.getAction() == 2)
                {
                    if (thereIsWallBetweenV(newstate, oldstate, domain))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    if (thereIsWallBetweenH(newstate, oldstate, domain))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
예제 #3
0
        private int distanceForMomentum(State state, InfoDomain domain)
        {
            int centerx = (int)(state.getPosX() - 40) / 8;
            int centery = (int)(state.getPosY() - 40) / 8;

            int height = state.getSizeOfAgent();
            int width  = getWidth(height);

            int direction = (int)state.getVelocityX();

            int startx;
            int endx;

            int starty = centery - height / 8 / 2;
            int endy   = centery + height / 8 / 2;

            int[,] table = domain.Table;

            int endOfPlatform;

            if (direction == 1)
            {
                startx        = centerx - width / 8 / 2;
                endOfPlatform = (int)(state.CurrentPlatform.minWidth() - 40) / 8;
                endx          = Math.Max(0, endOfPlatform);

                for (int x = startx; x >= endx; x--)
                {
                    for (int y = starty; y < endy; y++)
                    {
                        if (table[y, x] == 1 || table[y, x] == 2)
                        {
                            return((centerx - x) * 8);
                        }
                    }
                }

                return(centerx * 8 - width / 2);
            }
            else
            {
                startx        = centerx + width / 8 / 2 - 1;
                endOfPlatform = (int)(state.CurrentPlatform.minWidth() - 40) / 8;
                endx          = Math.Min(149, endOfPlatform);

                for (int x = startx; x <= endx; x++)
                {
                    for (int y = starty; y < endy; y++)
                    {
                        if (table[y, x] == 1 || table[y, x] == 2)
                        {
                            return((x - centerx) * 8);
                        }
                    }
                }

                return((149 - centerx) * 8 - width / 2);
            }
        }
예제 #4
0
        protected Boolean canPassOver(State newstate, State oldstate, InfoDomain domain)
        {
            float oldpx = (oldstate.getPosX() - 40) / 8;
            float oldpy = (oldstate.getPosY() - 40) / 8;
            float newpx = (newstate.getPosX() - 40) / 8;
            float newpy = (newstate.getPosY() - 40) / 8;

            int ioldpx = (int)oldpx;
            int inewpx = (int)newpx;
            int ioldpy = (int)oldpy;
            int inewpy = (int)newpy;

            int startx;
            int endx;
            int starty;
            int endy;
            int iterx;

            if (topy <= ((newstate.CurrentPlatform.maxHeight() - 40) / 8) - 12)
            {
                return(false);
            }

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

            int[,] table = domain.Table;

            startx = topx - 12;             // 12 = NORMALSIZE / 8
            endx   = topx + 12;


            starty = topy - 13;
            endy   = topy;

            if (starty < 0 || endy >= 90 || startx < 0 || endx >= 150)
            {
                return(false);
            }

            for (; starty < /*<=?*/ endy; starty++)
            {
                iterx = startx;
                for (; iterx < /*<=?*/ endx; iterx++)
                {
                    if (table[starty, iterx] == 1 || table[starty, iterx] == 2)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #5
0
        protected override Boolean thereIsWallBetweenV(State newstate, State oldstate, InfoDomain domain)
        {
            float oldpx = (oldstate.getPosX() - 40) / 8;
            float oldpy = (oldstate.getPosY() - 40) / 8;
            float newpx = (newstate.getPosX() - 40) / 8;
            float newpy = (newstate.getPosY() - 40) / 8;

            int ioldpx = (int)oldpx;
            int inewpx = (int)newpx;
            int ioldpy = (int)oldpy;
            int inewpy = (int)newpy;

            int startx;
            int endx;
            int starty;
            int endy;
            int iterx;

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

            if (newstate.getAction() == 2)
            {
                float newx         = newstate.getPosX();
                float collectibley = 720;
                for (int i = oldstate.sizeOfCaughtCollectible() * 2; i < newstate.sizeOfCaughtCollectible() * 2; i += 2)
                {
                    if (newstate.getCaughtCollectible(i + 1) < collectibley)
                    {
                        collectibley = newstate.getCaughtCollectible(i + 1);
                        newx         = newstate.getCaughtCollectible(i);
                    }
                }

                starty = (int)(collectibley + 32 - 40) / 8;
                if (starty < 0)
                {
                    starty = 0;
                }
                int height = (int)(newstate.CurrentPlatform.maxHeight() - collectibley - 32);
                halfwidth = getWidth(height) / 2;
                endy      = (int)(newstate.getPosY() - 40 + oldstate.getSizeOfAgent() / 2) / 8;
                startx    = (int)(newstate.getPosX() - 40 - halfwidth) / 8;
                endx      = (int)(newstate.getPosX() - 40 + halfwidth) / 8;
                //
                newstate.point.Size = (int)(newstate.CurrentPlatform.maxHeight() - collectibley - 32);
                newstate.setSizeOfAgent(newstate.point.Size);
                newstate.setPosY(newstate.CurrentPlatform.maxHeight() - newstate.getSizeOfAgent() / 2);
                //
                newstate.point.x = newx;
            }
            else
            {
                if (inewpy > ioldpy)
                {
                    starty = (int)(oldstate.getPosY() - 40 - halfheight) / 8;
                    endy   = (int)(newstate.getPosY() - 40 + halfheight) / 8;
                }
                else
                {
                    starty = (int)(newstate.getPosY() - 40 - halfheight) / 8;
                    endy   = (int)(oldstate.getPosY() - 40 + halfheight) / 8;
                }
                startx = (int)(newstate.getPosX() - 40 - halfwidth) / 8;
                endx   = (int)(newstate.getPosX() - 40 + halfwidth) / 8;
            }

            int[,] table = domain.Table;

            for (; starty < /*<=?*/ endy; starty++)
            {
                iterx = startx;
                for (; iterx < /*<=?*/ endx; iterx++)
                {
                    if (table[starty, iterx] == 1 || table[starty, iterx] == 2)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #6
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);
                    }
                }
            }
        }
예제 #7
0
        protected override Boolean thereIsWallBetweenH(State newstate, State oldstate, InfoDomain domain)
        {
            float oldpx = (oldstate.getPosX() - 40) / 8;
            float oldpy = (oldstate.getPosY() - 40) / 8;
            float newpx = (newstate.getPosX() - 40) / 8;
            float newpy = (newstate.getPosY() - 40) / 8;

            int ioldpx = (int)oldpx;
            int inewpx = (int)newpx;
            int ioldpy = (int)oldpy;
            int inewpy = (int)newpy;

            int startx;
            int endx;
            int starty;
            int endy;
            int midy;
            int iterx;

            bool walltop    = false;
            bool wallbottom = false;

            int halfheight   = newstate.getSizeOfAgent() / 2;
            int oldhalfwidth = getWidth(oldstate.getSizeOfAgent()) / 2;
            int halfwidth    = getWidth(newstate.getSizeOfAgent()) / 2;

            int[,] table = domain.Table;

            if (inewpx > ioldpx)
            {
                startx = (int)(oldstate.getPosX() - 40 + oldhalfwidth) / 8;
                endx   = (int)(newstate.getPosX() - 40 + halfwidth) / 8;;
            }
            else
            {
                startx = (int)(newstate.getPosX() - 40 - halfwidth) / 8;
                endx   = (int)(oldstate.getPosX() - 40 - oldhalfwidth) / 8;
            }

            starty = (int)(oldstate.getPosY() - 40 - halfheight) / 8;
            endy   = (int)(oldstate.getPosY() - 40 + halfheight) / 8;

            midy = endy - 6;

            for (; starty < /*<=?*/ midy; starty++)
            {
                iterx = startx;
                for (; iterx < /*<=?*/ endx; iterx++)
                {
                    if (table[starty, iterx] == 1 || table[starty, iterx] == 2)
                    {
                        topy    = starty;
                        topx    = iterx;
                        walltop = true;
                        break;
                    }
                }
                if (walltop)
                {
                    break;
                }
            }

            starty = midy;

            for (; starty < /*<=?*/ endy; starty++)
            {
                iterx = startx;
                for (; iterx < /*<=?*/ endx; iterx++)
                {
                    if (table[starty, iterx] == 1 || table[starty, iterx] == 2)
                    {
                        if (!walltop)
                        {
                            topy = starty;
                            topx = iterx;
                        }
                        wallbottom = true;
                        break;
                    }
                }
                if (wallbottom)
                {
                    break;
                }
            }

            if (!walltop && !wallbottom)
            {
                return(false);
            }
            else
            {
                if (walltop && !wallbottom)
                {
                    emptyBottom = true;
                }
                return(true);
            }
        }
예제 #8
0
 public override Boolean validate(CircleNode newnode, CircleNode oldnode, InfoDomain domain, Graph graph)
 {
     return(false);
 }
예제 #9
0
        protected override Boolean thereIsWallBetweenV(State newstate, State oldstate, InfoDomain domain)
        {
            float oldpx = (oldstate.getPosX() - 40) / 8;
            float oldpy = (oldstate.getPosY() - 40) / 8;
            float newpx = (newstate.getPosX() - 40) / 8;
            float newpy = (newstate.getPosY() - 40) / 8;

            int ioldpx = (int)oldpx;
            int inewpx = (int)newpx;
            int ioldpy = (int)oldpy;
            int inewpy = (int)newpy;

            int startx;
            int endx;
            int starty;
            int endy;

            int[,] table = domain.Table;

            //int maxHeight = 300;

            if (newstate.getAction() == 3)
            {
                starty = (int)(newstate.getPosY() - 40 - radiusOfCircle) / 8;
                endy   = (int)(oldstate.getPosY() - 40 + radiusOfCircle) / 8;
                startx = (int)(oldstate.getPosX() - 40 - radiusOfCircle) / 8;
                endx   = (int)(oldstate.getPosX() - 40 + radiusOfCircle) / 8;
            }
            else
            if (newstate.getAction() == 2)
            {
                float collectibley = 720;
                for (int i = oldstate.sizeOfCaughtCollectible() * 2; i < newstate.sizeOfCaughtCollectible() * 2; i += 2)
                {
                    if (newstate.getCaughtCollectible(i + 1) < collectibley)
                    {
                        collectibley = newstate.getCaughtCollectible(i + 1);
                    }
                }

                starty = (int)(collectibley + 32 - 40) / 8;
                if (starty < 0)
                {
                    starty = 0;
                }
                endy   = (int)(newstate.getPosY() - 40 + radiusOfCircle) / 8;
                startx = (int)(newstate.getPosX() - 40 - radiusOfCircle) / 8;
                endx   = (int)(newstate.getPosX() - 40 + radiusOfCircle) / 8;
            }
            else
            {
                if (inewpy > ioldpy)
                {
                    starty = (int)(oldstate.getPosY() - 40 - radiusOfCircle) / 8;
                    endy   = (int)(newstate.getPosY() - 40 + radiusOfCircle) / 8;
                }
                else
                {
                    starty = (int)(newstate.getPosY() - 40 - radiusOfCircle) / 8;
                    endy   = (int)(oldstate.getPosY() - 40 + radiusOfCircle) / 8;
                }
                startx = (int)(newstate.getPosX() - 40 - radiusOfCircle) / 8;
                endx   = (int)(newstate.getPosX() - 40 + radiusOfCircle) / 8;
            }

            for (; starty < /*<=?*/ endy; starty++)
            {
                for (int iterx = startx; iterx < /*<=?*/ endx; iterx++)
                {
                    if (table[starty, iterx] == 1 || table[starty, iterx] == 3)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #10
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);
        }
예제 #11
0
 abstract public Boolean validate(CircleNode newnode, CircleNode oldnode, InfoDomain domain, Graph graph);
예제 #12
0
 abstract public RectangleNode apply(RectangleNode Xinit, InfoDomain _domain, Graph graph);
예제 #13
0
 abstract public CircleNode apply(CircleNode Xinit, InfoDomain _domain, Graph graph);
예제 #14
0
        public void DeprecatedSetup(int[] nI, float[] sI, float[] cI, float[] oI, float[] sPI, float[] cPI, float[] colI, Rectangle area, double timeLimit)
        {
            // Time limit is the time limit of the level - if negative then there is no time constrains
            this.area = area;
            int temp;



            // numbersInfo[] Description
            //
            // Index - Information
            //
            //   0   - Number of Obstacles
            //   1   - Number of Rectangle Platforms
            //   2   - Number of Circle Platforms
            //   3   - Number of Collectibles

            numbersInfo = new int[4];
            int i;

            for (i = 0; i < nI.Length; i++)
            {
                numbersInfo[i] = nI[i];
            }

            nCollectiblesLeft = nI[3];

            // rectangleInfo[] Description
            //
            // Index - Information
            //
            //   0   - Rectangle X Position
            //   1   - Rectangle Y Position
            //   2   - Rectangle X Velocity
            //   3   - Rectangle Y Velocity
            //   4   - Rectangle Height

            rectangleInfo = new float[5];

            rectangleInfo[0] = sI[0];
            rectangleInfo[1] = sI[1];
            rectangleInfo[2] = sI[2];
            rectangleInfo[3] = sI[3];
            rectangleInfo[4] = sI[4];

            // circleInfo[] Description
            //
            // Index - Information
            //
            //   0  - Circle X Position
            //   1  - Circle Y Position
            //   2  - Circle X Velocity
            //   3  - Circle Y Velocity
            //   4  - Circle Radius

            circleInfo = new float[5];

            circleInfo[0] = cI[0];
            circleInfo[1] = cI[1];
            circleInfo[2] = cI[2];
            circleInfo[3] = cI[3];
            circleInfo[4] = cI[4];


            // Obstacles and Platforms Info Description
            //
            //  X = Center X Coordinate
            //  Y = Center Y Coordinate
            //
            //  H = Platform Height
            //  W = Platform Width
            //
            //  Position (X=0,Y=0) = Left Superior Corner

            // obstaclesInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Obstacles > 0)
            //  [0 ; (NumObstacles * 4) - 1]      - Obstacles' info [X,Y,H,W]
            // Else
            //   0                                - 0
            //   1                                - 0
            //   2                                - 0
            //   3                                - 0

            if (numbersInfo[0] > 0)
            {
                obstaclesInfo = new float[numbersInfo[0] * 4];
            }
            else
            {
                obstaclesInfo = new float[4];
            }

            temp = 1;
            if (nI[0] > 0)
            {
                while (temp <= nI[0])
                {
                    obstaclesInfo[(temp * 4) - 4] = oI[(temp * 4) - 4];
                    obstaclesInfo[(temp * 4) - 3] = oI[(temp * 4) - 3];
                    obstaclesInfo[(temp * 4) - 2] = oI[(temp * 4) - 2];
                    obstaclesInfo[(temp * 4) - 1] = oI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                obstaclesInfo[0] = oI[0];
                obstaclesInfo[1] = oI[1];
                obstaclesInfo[2] = oI[2];
                obstaclesInfo[3] = oI[3];
            }

            // rectanglePlatformsInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Rectangle Platforms > 0)
            //  [0; (numRectanglePlatforms * 4) - 1]   - Rectangle Platforms' info [X,Y,H,W]
            // Else
            //   0                                  - 0
            //   1                                  - 0
            //   2                                  - 0
            //   3                                  - 0


            if (numbersInfo[1] > 0)
            {
                rectanglePlatformsInfo = new float[numbersInfo[1] * 4];
            }
            else
            {
                rectanglePlatformsInfo = new float[4];
            }

            temp = 1;
            if (nI[1] > 0)
            {
                while (temp <= nI[1])
                {
                    rectanglePlatformsInfo[(temp * 4) - 4] = sPI[(temp * 4) - 4];
                    rectanglePlatformsInfo[(temp * 4) - 3] = sPI[(temp * 4) - 3];
                    rectanglePlatformsInfo[(temp * 4) - 2] = sPI[(temp * 4) - 2];
                    rectanglePlatformsInfo[(temp * 4) - 1] = sPI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                rectanglePlatformsInfo[0] = sPI[0];
                rectanglePlatformsInfo[1] = sPI[1];
                rectanglePlatformsInfo[2] = sPI[2];
                rectanglePlatformsInfo[3] = sPI[3];
            }

            // circlePlatformsInfo[] Description
            //
            // Index - Information
            //
            // If (Number of Circle Platforms > 0)
            //  [0; (numCirclePlatforms * 4) - 1]   - Circle Platforms' info [X,Y,H,W]
            // Else
            //   0                                  - 0
            //   1                                  - 0
            //   2                                  - 0
            //   3                                  - 0

            if (numbersInfo[2] > 0)
            {
                circlePlatformsInfo = new float[numbersInfo[2] * 4];
            }
            else
            {
                circlePlatformsInfo = new float[4];
            }

            temp = 1;
            if (nI[2] > 0)
            {
                while (temp <= nI[2])
                {
                    circlePlatformsInfo[(temp * 4) - 4] = cPI[(temp * 4) - 4];
                    circlePlatformsInfo[(temp * 4) - 3] = cPI[(temp * 4) - 3];
                    circlePlatformsInfo[(temp * 4) - 2] = cPI[(temp * 4) - 2];
                    circlePlatformsInfo[(temp * 4) - 1] = cPI[(temp * 4) - 1];
                    temp++;
                }
            }
            else
            {
                circlePlatformsInfo[0] = cPI[0];
                circlePlatformsInfo[1] = cPI[1];
                circlePlatformsInfo[2] = cPI[2];
                circlePlatformsInfo[3] = cPI[3];
            }

            //Collectibles' To Catch Coordinates (X,Y)
            //
            //  [0; (numCollectibles * 2) - 1]   - Collectibles' Coordinates (X,Y)

            collectiblesInfo = new float[numbersInfo[3] * 2];

            temp = 1;
            while (temp <= nI[3])
            {
                collectiblesInfo[(temp * 2) - 2] = colI[(temp * 2) - 2];
                collectiblesInfo[(temp * 2) - 1] = colI[(temp * 2) - 1];

                temp++;
            }

            InfoDomain domain = new InfoDomain(nI, sI, cI, oI, sPI, cPI, colI, timeLimit, 0);
            TableMaker table  = new TableMaker(nI, oI, sPI, cPI, colI);

            table.makeTable();
            domain.Table = table.Table;
            ArrayList collectibles = new ArrayList();

            temp = 1;
            while (temp <= nI[3])
            {
                collectibles.Add(colI[(temp * 2) - 2]);
                collectibles.Add(colI[(temp * 2) - 1]);

                temp++;
            }


            if (cI[0] > 0 && cI[1] > 0)
            {
                State root = new State(cI[2], cI[3], cI[0], cI[1], -1, collectibles, new ArrayList());

                root.setSizeOfAgent(80);

                CircleValidator validator = new CircleValidator();
                CircleTactics   tactics   = new CircleTactics();

                Obstacles.Obstacle o = domain.AllObstacles.getNextPlatform(root);
                root.CurrentPlatform = o;

                root.setPosY(root.CurrentPlatform.maxHeight() - root.getSizeOfAgent() / 2);

                CircleGFRRT gfrrt = new CircleGFRRT(root, domain, 10000000, validator, tactics);

                plays = gfrrt.run();

                walker        = new CircleWalker(plays);
                pointToTarget = walker.getFirstPoint();

                DebugSensorsInfo();

                //p.Print();
            }
        }
예제 #15
0
        private int possibleHeight(State state, InfoDomain domain)
        {
            int  height      = state.getSizeOfAgent();
            int  width       = getWidth(height);
            int  centerx     = (int)(state.getPosX() - 40) / 8;
            int  centery     = (int)(state.getPosY() - 40) / 8;
            bool thereiswall = true;

            int[,] table = domain.Table;
            float v = state.getVelocityX();
            int   x;

            if (v == 0)
            {
                x = centerx - (width / 8) / 2;
                if (x < 0)
                {
                    width -= (0 - x) * 8;
                    if (width < 48)
                    {
                        return(96);
                    }
                    centerx += ((0 - x) / 2);
                    x        = 0;
                }
            }
            else
            {
                x = centerx + (width / 8) / 2 - 1;
                if (x > 149)
                {
                    width -= ((x - 149) * 8);
                    if (width < 48)
                    {
                        return(96);
                    }
                    centerx -= ((x - 149) / 2);
                    x        = 149;
                }
            }

            height = getHeight(width);

            int starty = centery - (height / 8) / 2;
            int endy   = centery + (height / 8) / 2;

            if (endy > 89)
            {
                endy = 89;
            }

            int iter = 1;

            while (thereiswall)
            {
                thereiswall = false;
                for (int y = starty; y < endy; y++)
                {
                    if (table[y, x] == 1 || table[y, x] == 2)
                    {
                        thereiswall = true;
                        break;
                    }
                }

                if (thereiswall)
                {
                    width -= 8;
                    if (width < 48)
                    {
                        return(96); //it wont pass the validator either way
                    }
                    height = getHeight(width);
                    // Y will be checked by the validator
                    if (v == 0)
                    {
                        if (iter % 2 == 0)
                        {
                            centerx += 1; //half what we took from the width
                        }
                        x = centerx - (width / 8) / 2;
                    }
                    else
                    {
                        if (iter % 2 == 0)
                        {
                            centerx -= 1; //half what we took from the width
                        }
                        x = centerx + (width / 8) / 2 - 1;
                    }
                    iter++;
                }
            }
            if (height < 192 - 10)
            {
                return(height + 10);
            }
            else
            {
                return(height);
            }
        }
예제 #16
0
 abstract protected Boolean thereIsWallBetweenV(State newstate, State oldstate, InfoDomain domain);
예제 #17
0
        protected override Boolean thereIsWallBetweenH(State newstate, State oldstate, InfoDomain domain)
        {
            float oldpx = (oldstate.getPosX() - 40) / 8;
            float oldpy = (oldstate.getPosY() - 40) / 8;
            float newpx = (newstate.getPosX() - 40) / 8;
            float newpy = (newstate.getPosY() - 40) / 8;

            int ioldpx = (int)oldpx;
            int inewpx = (int)newpx;
            int ioldpy = (int)oldpy;
            int inewpy = (int)newpy;

            int startx;
            int endx;
            int starty;
            int endy;

            int[,] table = domain.Table;

            // If horizontal movement
            if (inewpy == ioldpy)
            {
                if (inewpx > ioldpx)
                {
                    startx = (int)(oldstate.getPosX() - 40 + 40) / 8;
                    endx   = (int)(newstate.getPosX() - 40 + 40) / 8;;
                }
                else
                {
                    startx = (int)(newstate.getPosX() - 40 - 40) / 8;
                    endx   = (int)(oldstate.getPosX() - 40 - 40) / 8;
                }

                starty = (int)(oldstate.getPosY() - 40 - 40) / 8;
                endy   = (int)(oldstate.getPosY() - 40 + 40) / 8;

                for (; starty < /*<=?*/ endy; starty++)
                {
                    for (; startx < /*<=?*/ endx; startx++)
                    {
                        if (table[starty, startx] == 1 || table[starty, startx] == 3)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            return(false);
        }
예제 #18
0
 abstract public Boolean validate(RectangleNode newnode, RectangleNode oldnode, InfoDomain domain, Graph graph);
예제 #19
0
 public override CircleNode apply(CircleNode Xinit, InfoDomain _domain, Graph graph)
 {
     return(null);
 }