private void SpawnShadow(CartesianArray<MapElementStatus> viewport, Point point, Area area, MapElementStatus elementType, double ratio, Modifiers modifier, bool increaseX) { int xdistance = 0; int ydistance = 0; bool first = true; var curentPoint = new Point(point.X + xdistance, point.Y + ydistance); Point lastPoint = null; do { viewport[curentPoint] = first ? elementType : (viewport[curentPoint] == MapElementStatus.Undiscovered ? MapElementStatus.Shadowed: viewport[curentPoint] ); first = false; if (increaseX) { xdistance += modifier.X; ydistance = Convert.ToInt32(Math.Floor(ratio * xdistance * modifier.X * modifier.Y)); } else { ydistance += modifier.Y; xdistance = Convert.ToInt32(Math.Floor(ratio * ydistance * modifier.X * modifier.Y)); } lastPoint = curentPoint; curentPoint = new Point(point.X + xdistance, point.Y + ydistance); if (Math.Abs(lastPoint.X - curentPoint.X) > 1 || Math.Abs(lastPoint.Y -curentPoint.Y) > 1) { } } while (IsInbound(curentPoint, area)); }
private static bool IsInbound(Point point, Area area) { return (point.X > area.LeftEdge && point.X < area.RightEdge) && (point.Y > area.BottomEdge && point.Y < area.TopEdge); }
private void SpawnShadow(CartesianArray<MapElementStatus> viewport, Point point, Area area, MapElementStatus elementType) { bool increaseX = Math.Abs(point.X) > Math.Abs(point.Y); double ratio = 0.0; var modifier = new Modifiers(point.X > 0 ? 1 : -1, point.Y > 0 ? 1 : -1); if (point.X != 0 && point.Y != 0) { double x = Math.Abs(point.X); double y = Math.Abs(point.Y); ratio = Math.Abs(increaseX ? y / x : x / y); } SpawnShadow(viewport, point, area, elementType, ratio, modifier, increaseX); }
private void SpawnShadow(CartesianArray<MapElementStatus> viewport, Point point, Area area, double direction) { double ratio = GetYRatio(direction); bool increaseX = Math.Abs(ratio) < 1; var modifier = GetModifiersForDirection(direction); ratio = Math.Abs(increaseX ? ratio : 1/ratio); SpawnShadow(viewport, point, area, MapElementStatus.Shadowed, ratio, modifier, increaseX); }
private void HandlePoint(Queue<Point> queue, CartesianArray<MapElementStatus> viewport, Point point, Area area) { if (viewport[point] == MapElementStatus.Undiscovered) { queue.Enqueue(point); viewport[point] = MapElementStatus.Discovered; } if (viewport[point] == MapElementStatus.Blocked || viewport[point] == MapElementStatus.Target) { SpawnShadow(viewport, point, area, GetStatusToSpawnFor(viewport[point])); } }
public CartesianArray<MapElementStatus> GetView() { var currentViewPort = GetRobotCenteredMapCopy(Robot, BaseArea.Value); Area area = new Area( topEdge: currentViewPort.TopRightCoordinate.Y + 1, rightEdge: currentViewPort.TopRightCoordinate.X, bottomEdge: currentViewPort.BottomLeftCoordinate.Y, leftEdge: currentViewPort.BottomLeftCoordinate.X - 1); SetSensorAngleBoundaries(map: currentViewPort, area: area); Queue<Point> pointQueue = new Queue<Point>(); pointQueue.Enqueue(GetStartPoint(Robot.CartasianDirection)); while(pointQueue.Count > 0) { Point curPoint = pointQueue.Dequeue(); Point topPoint = new Point(curPoint.X, curPoint.Y + 1); Point rightPoint = new Point(curPoint.X + 1, curPoint.Y); Point bottomPoint = new Point(curPoint.X, curPoint.Y - 1); Point leftPoint = new Point(curPoint.X - 1, curPoint.Y); if (IsInbound(bottomPoint, area)) { HandlePoint(pointQueue, currentViewPort, bottomPoint, area); } if (IsInbound(topPoint, area)) { HandlePoint(pointQueue, currentViewPort, topPoint, area); } if (IsInbound(rightPoint, area)) { HandlePoint(pointQueue, currentViewPort, rightPoint, area); } if (IsInbound(leftPoint, area)) { HandlePoint(pointQueue, currentViewPort, leftPoint, area); } } return currentViewPort; }
private void SetSensorAngleBoundaries(CartesianArray<MapElementStatus> map, Area area) { SpawnShadow(map, new Point(0, 0), area, (Robot.CartasianDirection + (Sight.Angle / 2)) % 360); SpawnShadow(map, new Point(0, 0), area, (Robot.CartasianDirection - (Sight.Angle / 2)) % 360); }