예제 #1
0
 public override void SensorsUpdated(int nC, RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation[] colI)
 {
     DeprecatedSensorsUpdated(nC,
                              rI.ToArray(),
                              cI.ToArray(),
                              CollectibleRepresentation.RepresentationArrayToFloatArray(colI));
 }
        private void deleteCollectedDiamonds()
        {
            float[]     colInfo     = CollectibleRepresentation.RepresentationArrayToFloatArray(CircleAgent.colI);
            List <Node> colLeftList = new List <Node>();

            for (int i = 0; i < colInfo.Length; i = i + 2)
            {
                Node node = new Node((int)colInfo[i], (int)colInfo[i + 1], true);
                colLeftList.Add(node);
            }

            for (int index = 0; index < nodes.Count; index++)
            {
                Node nodeOfFullList = nodes[index];
                if (nodeOfFullList.getDiamond())
                {
                    bool isDiamond = false;
                    foreach (Node leftDiamond in colLeftList)
                    {
                        if ((nodeOfFullList.getX() == leftDiamond.getX() && nodeOfFullList.getY() == leftDiamond.getY()) || ((nodeOfFullList.getY() - leftDiamond.getY()) <= 80 && (nodeOfFullList.getY() - leftDiamond.getY()) > 0 && nodeOfFullList.getX() == leftDiamond.getX()))
                        {
                            isDiamond = true;
                        }
                    }
                    if (!isDiamond)
                    {
                        nodeOfFullList.setDiamond(false);
                        nodes[index] = nodeOfFullList;
                    }
                }
            }
        }
        public CircleSingleplayerRule(CollectibleRepresentation objectiveDiamond) : base()
        {
            circleSingleplayer = new CircleSingleplayer(true, true, true);

            this.objectiveDiamond = new CollectibleRepresentation[1];

            this.objectiveDiamond[0] = objectiveDiamond;

            setup = false;
        }
        public CircleGoTo(CollectibleRepresentation objectiveDiamond, bool rectangleAsPlatform) : base()
        {
            this.singleplayer = new CircleSingleplayer(true, true, true);

            this.objectiveDiamond = new CollectibleRepresentation[1];

            this.objectiveDiamond[0] = objectiveDiamond;

            this.rectangleAsPlatform = rectangleAsPlatform;
        }
예제 #5
0
        public void generateNodes(RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, AgentType agentType)
        {
            int rectangleX = (int)rI.X;
            int rectangleY = (int)rI.Y;

            int circleX = (int)cI.X;
            int circleY = (int)cI.Y;

            Node rectangle = new Node(rectangleX, rectangleY, Node.Type.Rectangle);

            this.addNode(rectangle);
            this.rectangleNode = rectangle;

            Node circle = new Node(circleX, circleY, Node.Type.Circle);

            this.addNode(circle);
            this.circleNode = circle;

            // OBSTACLE
            for (int i = 0; i < oI.Length; i++)
            {
                ObstacleRepresentation obstacle = oI[i];

                createNodesForObstacle(obstacle, Node.Type.Obstacle);
            }

            // CIRCLE PLATFORM
            for (int i = 0; i < cPI.Length; i++)
            {
                ObstacleRepresentation circlePlatform = cPI[i];

                createNodesForObstacle(circlePlatform, Node.Type.CirclePlatform);
            }

            // RECTANGLE PLATFORM
            for (int i = 0; i < rPI.Length; i++)
            {
                ObstacleRepresentation rectanglePlatform = rPI[i];

                createNodesForObstacle(rectanglePlatform, Node.Type.RectanglePlatform);
            }

            // DIAMONDS
            for (int i = 0; i < colI.Length; i++)
            {
                CollectibleRepresentation diamond = colI[i];

                Node diamondNode = new Node((int)diamond.X, (int)diamond.Y, Node.Type.Diamond);
                this.addNode(diamondNode);
                this.diamondNodes.Add(diamondNode);
            }
        }
예제 #6
0
 public override void Setup(CountInformation nI, RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area, double timeLimit)
 {
     //convert to old way in order to maintain compatibility
     DeprecatedSetup(
         nI.ToArray(),
         rI.ToArray(),
         cI.ToArray(),
         ObstacleRepresentation.RepresentationArrayToFloatArray(oI),
         ObstacleRepresentation.RepresentationArrayToFloatArray(rPI),
         ObstacleRepresentation.RepresentationArrayToFloatArray(cPI),
         CollectibleRepresentation.RepresentationArrayToFloatArray(colI),
         area,
         timeLimit);
 }
        public HeightRule(float coopX, float coopY, CollectibleRepresentation diamond) : base()
        {
            this.coopX = coopX;
            this.coopY = coopY;

            this.diamond = diamond;

            actionStatesCircle    = new List <ActionState>();
            actionStatesRectangle = new List <ActionState>();

            actionStatesCircle.Add(new ActionState());
            actionStatesCircle.Add(new CircleGoTo(coopX, coopY, true));
            actionStatesCircle.Add(new CircleStay(coopX, coopY));
            actionStatesCircle.Add(new CircleGoTo(diamond, true));

            actionStatesRectangle.Add(new MorphDown());
            actionStatesRectangle.Add(new RectangleGoToAndStay(coopX, coopY));
            actionStatesRectangle.Add(new MorphUp());
            actionStatesRectangle.Add(new RectangleGoToAndStay(coopX, coopY));
        }
예제 #8
0
        private Moves RollToPosition(float x, float y)
        {
            Moves move = Moves.NO_ACTION;

            Status circleStatus = new Status();
            CollectibleRepresentation target = new CollectibleRepresentation(x, y);

            circleStatus.Update(circleInfo, rectangleInfo, target, AgentType.Circle, currentAction);

            Utils.Direction  rollDirection;
            Utils.Quantifier distanceFromTarget;

            //Definition of rollDirection and distanceFromTarget
            if (circleStatus.LEFT_FROM_TARGET != Utils.Quantifier.NONE)
            {
                rollDirection      = Utils.Direction.RIGHT;
                distanceFromTarget = circleStatus.LEFT_FROM_TARGET;
            }
            else if (circleStatus.RIGHT_FROM_TARGET != Utils.Quantifier.NONE)
            {
                rollDirection      = Utils.Direction.LEFT;
                distanceFromTarget = circleStatus.RIGHT_FROM_TARGET;
            }
            else
            {
                rollDirection      = Utils.Direction.LEFT; //Just default value
                distanceFromTarget = Utils.Quantifier.NONE;
            }

            //Move decision
            if (distanceFromTarget != Utils.Quantifier.NONE)
            {
                move = Roll(rollDirection, distanceFromTarget);
            }
            else
            {
                move = HoldGround();
            }

            return(move);
        }
예제 #9
0
        public Moves MoveToPosition(float x)
        {
            Moves move            = Moves.NO_ACTION;
            float arbitrary_value = 300;

            Status rectangleStatus           = new Status();
            CollectibleRepresentation target = new CollectibleRepresentation(x, arbitrary_value);

            rectangleStatus.Update(this.circleInfo, this.rectangleInfo, target, AgentType.Rectangle, currentAction);

            Utils.Direction  moveDirection;
            Utils.Quantifier distanceFromTarget;

            if (rectangleStatus.LEFT_FROM_TARGET != Utils.Quantifier.NONE)
            {
                moveDirection      = Utils.Direction.RIGHT;
                distanceFromTarget = rectangleStatus.LEFT_FROM_TARGET;
            }
            else if (rectangleStatus.RIGHT_FROM_TARGET != Utils.Quantifier.NONE)
            {
                moveDirection      = Utils.Direction.LEFT;
                distanceFromTarget = rectangleStatus.RIGHT_FROM_TARGET;
            }
            else
            {
                moveDirection      = Utils.Direction.LEFT; //Just default value
                distanceFromTarget = Utils.Quantifier.NONE;
            }

            if (distanceFromTarget != Utils.Quantifier.NONE)
            {
                move = Move(moveDirection, distanceFromTarget);
            }
            else
            {
                move = HoldGround();
            }

            return(move);
        }
예제 #10
0
        public static Matrix generateMatrixFomGameInfo(RectangleRepresentation rI, CircleRepresentation cI, ObstacleRepresentation[] oI, ObstacleRepresentation[] rPI, ObstacleRepresentation[] cPI, CollectibleRepresentation[] colI, Rectangle area)
        {
            Matrix matrix = new Matrix(area.Width + 1, area.Height + 1);

            int rectangleX     = (int)rI.X;
            int rectangleY     = (int)rI.Y;
            int rectangleWidth = (int)rI.Height; // TODO: calculate width from height

            int circleX      = (int)cI.X;
            int circleY      = (int)cI.Y;
            int circleRadius = (int)cI.Radius - 20;

            // RECTANGLE
            for (int x = rectangleX - rectangleWidth / 2; x < rectangleX + rectangleWidth / 2; x++)
            {
                for (int y = rectangleY - 10 / 2; y < rectangleY + 10 / 2; y++)
                {
                    if (!matrix.inBounds(x, y)) // x and y out of bounds
                    {
                        continue;
                    }
                    else
                    {
                        matrix.getPixel(x, y).type = Pixel.Type.Rectangle;
                    }
                }
            }

            // CIRCLE -- let's pretende the circle is a square for now
            for (int x = circleX - circleRadius / 2; x < circleX + circleRadius / 2; x++)
            {
                for (int y = circleY - circleRadius / 2; y < circleY + circleRadius / 2; y++)
                {
                    if (!matrix.inBounds(x, y)) // x and y out of bounds
                    {
                        continue;
                    }
                    else
                    {
                        matrix.getPixel(x, y).type = Pixel.Type.Circle;
                    }
                }
            }

            // OBSTACLE
            for (int i = 0; i < oI.Length; i++)
            {
                ObstacleRepresentation obstacle = oI[i];

                for (int x = (int)(obstacle.X - obstacle.Width / 2); x < (int)(obstacle.X + obstacle.Width / 2); x++)
                {
                    for (int y = (int)(obstacle.Y - obstacle.Height / 2); y < (int)(obstacle.Y + obstacle.Height / 2); y++)
                    {
                        if (!matrix.inBounds(x, y)) // x and y out of bounds
                        {
                            continue;
                        }
                        else
                        {
                            matrix.getPixel(x, y).type = Pixel.Type.Obstacle;
                        }
                    }
                }
            }

            // CIRCLE PLATFORM
            for (int i = 0; i < cPI.Length; i++)
            {
                ObstacleRepresentation circlePlatform = cPI[i];

                for (int x = (int)(circlePlatform.X - circlePlatform.Width / 2); x < (int)(circlePlatform.X + circlePlatform.Width / 2); x++)
                {
                    for (int y = (int)(circlePlatform.Y - circlePlatform.Height / 2); y < (int)(circlePlatform.Y + circlePlatform.Height / 2); y++)
                    {
                        if (!matrix.inBounds(x, y)) // x and y out of bounds
                        {
                            continue;
                        }
                        else
                        {
                            matrix.getPixel(x, y).type = Pixel.Type.CirclePlatform;
                        }
                    }
                }
            }

            // RECTANGLE PLATFORM
            for (int i = 0; i < rPI.Length; i++)
            {
                ObstacleRepresentation rectanglePlatform = rPI[i];

                for (int x = (int)(rectanglePlatform.X - rectanglePlatform.Width / 2); x < (int)(rectanglePlatform.X + rectanglePlatform.Width / 2); x++)
                {
                    for (int y = (int)(rectanglePlatform.Y - rectanglePlatform.Height / 2); y < (int)(rectanglePlatform.Y + rectanglePlatform.Height / 2); y++)
                    {
                        if (!matrix.inBounds(x, y)) // x and y out of bounds
                        {
                            continue;
                        }
                        else
                        {
                            matrix.getPixel(x, y).type = Pixel.Type.RectanglePlatform;
                        }
                    }
                }
            }

            // DIAMONDS
            for (int i = 0; i < colI.Length; i++)
            {
                CollectibleRepresentation diamond = colI[i];
                int diamondWidth = 40;

                for (int x = (int)(diamond.X - diamondWidth / 2); x < (int)(diamond.X + diamondWidth / 2); x++)
                {
                    for (int y = (int)(diamond.Y - diamondWidth / 2); y < (int)(diamond.Y + diamondWidth / 2); y++)
                    {
                        if (!matrix.inBounds(x, y)) // x and y out of bounds
                        {
                            continue;
                        }
                        else
                        {
                            matrix.getPixel(x, y).type = Pixel.Type.Diamond;
                        }
                    }
                }
            }

            return(matrix);
        }
        public override ActionRule filter(RectangleRepresentation r, CircleRepresentation c, CollectibleRepresentation diamond)
        {
            ObstacleRepresentation closestAbove = new ObstacleRepresentation(diamond.X, getArea().Y, 0, 0), closestBelow = new ObstacleRepresentation(diamond.X, getArea().Height + getArea().Y, 0, 0);

            // Might be able to be changed into logarithmic complexity
            // Might not work for some combinations of Circle and regular platforms
            foreach (ObstacleRepresentation platform in yPlatforms)
            {
                // Check that diamond is above or below platform (same X)
                if (platform.X - platform.Width / 2 < diamond.X && diamond.X < platform.X + platform.Width / 2)
                {
                    // Since its ordered the first below is the closest
                    if (platform.Y > diamond.Y && platform.Y < closestBelow.Y)
                    {
                        closestBelow = platform;
                        break;
                    }
                    else if (platform.Y < diamond.Y && platform.Y > closestAbove.Y)
                    {
                        closestAbove = platform;
                    }
                }
            }

            // Either rectangle or coop
            if (closestBelow.Y - closestBelow.Height / 2 - closestAbove.Y - closestAbove.Height / 2 <= getMaxRadius() * 2)
            {
                // If rectangle is on top of the platform below, it can get there alone
                if (r.Y + (r.Height / 2) - closestBelow.Y + closestBelow.Height / 2 <= 10)
                {
                    return(new RectangleSingleplayerRule(diamond));
                }
                // Else, it needs the help from the circle
                else
                {
                    return(new TightSpaceRule());
                }
            }

            return(null);
        }
예제 #12
0
 public abstract ActionRule filter(RectangleRepresentation rI, CircleRepresentation cI, CollectibleRepresentation diamond);
 public CircleGoTo(CollectibleRepresentation objectiveDiamond) : this(objectiveDiamond, false)
 {
 }
        /*
         *  Filtering accuracy could be improved by accounting for max sideways jump as well as max vertical jump
         */
        public override ActionRule filter(RectangleRepresentation r, CircleRepresentation c, CollectibleRepresentation diamond)
        {
            float varY = diamond.Y;
            float coopX = diamond.X, coopY = getArea().Height + getArea().Y - rectangleMinHeight - c.Radius;

            ObstacleRepresentation previousPlatform = new ObstacleRepresentation(-10f, -10f, 0, 0);

            foreach (ObstacleRepresentation platform in yPlatforms)
            {
                if (c.Y - varY < getMaxJump())
                {
                    return(null);
                }

                if (varY >= platform.Y)
                {
                    continue;
                }
                else if (platform.Y - varY < getMaxJump())
                {
                    if (previousPlatform.X >= 0)
                    {
                        // If next platform down is to the left
                        if (Math.Max(previousPlatform.X - previousPlatform.Width / 2, getArea().X) - Math.Max(platform.X - platform.Width / 2, getArea().X) > getMaxRadius() / 2)
                        {
                            previousPlatform = platform;
                            varY             = platform.Y;
                            coopX            = previousPlatform.X - previousPlatform.Width / 2 - ((10000 / rectangleMinHeight) / 2);
                            coopY            = platform.Y - platform.Height / 2 - rectangleMinHeight - c.Radius;
                        }
                        // If next platform down is to the right
                        else if (Math.Min(platform.X + platform.Width / 2, getArea().Width + getArea().X) - Math.Min(previousPlatform.X + previousPlatform.Width / 2, getArea().Width + getArea().X) > getMaxRadius() / 2)
                        {
                            previousPlatform = platform;
                            varY             = platform.Y;
                            coopX            = previousPlatform.X + previousPlatform.Width / 2 + ((10000 / rectangleMinHeight) / 2);
                            coopY            = platform.Y - platform.Height / 2 - rectangleMinHeight - c.Radius;
                        }
                    }
                    else if (diamond.X - platform.X + platform.Width / 2 >= 0 && platform.X + platform.Width / 2 - diamond.X >= 0)
                    {
                        // Platform directly bellow diamond
                        varY             = platform.Y;
                        previousPlatform = platform;

                        if (platform.X - (platform.Width / 2) <= getArea().X + (10000 / rectangleMinHeight))
                        {
                            coopX = platform.X + platform.Width / 2 + ((10000 / rectangleMinHeight) / 2);
                        }
                        else
                        {
                            coopX = platform.X - platform.Width / 2 - ((10000 / rectangleMinHeight) / 2);
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            return(new HeightRule(coopX, coopY, diamond));
        }