private void DrawGoals(Graphics g) { Point[] uprights = new Point[8]; for (int i = 0; i < 4; ++i) { Coords temp = StaticMathFunctions.SpacePointToDisplayPointTransform(Constants.Uprights[i]); uprights[i] = new Point((Int32)(temp.X * _zoom), (Int32)(temp.Y * _zoom)); } double zmultiplierTop = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalTop); double zmultiplierBottom = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalBottom); uprights[4] = new Point(uprights[0].X, (Int32)(uprights[0].Y - Constants.GoalHeight * zmultiplierTop * _zoom)); uprights[5] = new Point(uprights[1].X, (Int32)(uprights[1].Y - Constants.GoalHeight * zmultiplierBottom * _zoom)); uprights[6] = new Point(uprights[2].X, (Int32)(uprights[2].Y - Constants.GoalHeight * zmultiplierTop * _zoom)); uprights[7] = new Point(uprights[3].X, (Int32)(uprights[3].Y - Constants.GoalHeight * zmultiplierBottom * _zoom)); Pen drawPen = new Pen(Color.Red); // Uprights g.DrawLine(drawPen, uprights[0], uprights[4]); g.DrawLine(drawPen, uprights[1], uprights[5]); g.DrawLine(drawPen, uprights[2], uprights[6]); g.DrawLine(drawPen, uprights[3], uprights[7]); // Crossbars g.DrawLine(drawPen, uprights[4], uprights[5]); g.DrawLine(drawPen, uprights[6], uprights[7]); drawPen.Dispose(); }
/* * // Used for displaying the grid. * private void TileDrawRectangle(Graphics graphicsObj, Coords position) * { * RectangleF box = GetRectangle(position); * graphicsObj.DrawRectangle(new Pen(Color.Black), box.X, box.Y, box.Width, box.Height); * } */ /* * private void TileDrawCoordinates(Graphics g, Coords position) * { * StringFormat strFormat = new StringFormat(); * strFormat.Alignment = StringAlignment.Center; * * * g.DrawString(position.ToString(), new Font("Tahoma", Constants.FontSize / 2), Brushes.Black, * new PointF((position.X + 0.5f) * Constants.TileBitmapSize * this._zoom, (position.Y + 0.5f) * * Constants.TileBitmapSize * this._zoom), strFormat); * } */ #endregion #region Pixel drawers private void DrawBitmapAtPixel(Graphics g, Coords pixel, Bitmap image) { Coords screenPos = StaticMathFunctions.SpacePointToDisplayPointTransform(pixel.X, pixel.Y); Point anchor = new Point((Int32)(screenPos.X * _zoom - 0.5f * image.Width), (Int32)(screenPos.Y * _zoom - image.Height)); // This should be at the middle of the bottom of the image. //Point anchor = new Point((Int32)(pixel.X * this._zoom - 0.5f * image.Width), (Int32)(pixel.Y * this._zoom - image.Height)); g.DrawImageUnscaled(image, anchor); }
// Draws an upper label on a tile (or rather Footballer). Should make it // nicer later with color choice, etc. private void DrawLabel(Graphics graphicsObj, Vector2d position, String label) { Coords transformed = StaticMathFunctions.SpacePointToDisplayPointTransform(position.X, position.Y); StringFormat strFormat = new StringFormat(); strFormat.Alignment = StringAlignment.Center; graphicsObj.DrawString(label, new Font("Tahoma", Constants.FontSize), Brushes.Black, new PointF(transformed.X * this._zoom, transformed.Y * this._zoom), strFormat); }
private Coords PixelUnderMousecursor() { Point mousePosition = this.PointToClient(Cursor.Position); //return TransformInverseScreenpointToCoords(mousePosition.X, mousePosition.Y); //Vector pointOnDisplay = TransformInverseScreenpointToVector(mousePosition.X, mousePosition.Y); Coords pointOnDisplay = TransformInverseScreenpointToCoords(mousePosition.X, mousePosition.Y); Coords returnVal = new Coords(StaticMathFunctions.DisplayPointToSpacePoint(pointOnDisplay)); return(new Coords(StaticMathFunctions.DisplayPointToSpacePoint(pointOnDisplay))); }
private void DrawLine(Graphics g, Vector2d a, Vector2d b) { Coords start = StaticMathFunctions.SpacePointToDisplayPointTransform(a.X, a.Y); PointF anchorA = new PointF((start.X * _zoom), (start.Y * _zoom)); Coords end = StaticMathFunctions.SpacePointToDisplayPointTransform(b.X, b.Y); PointF anchorB = new PointF((end.X * _zoom), (end.Y * _zoom)); Pen drawPen = new Pen(Color.Red); g.DrawLine(drawPen, anchorA, anchorB); drawPen.Dispose(); }
private void FillPlayerEllipse(Graphics g, Vector2d center, double radx, double rady, Color teamColor) { Coords transformedCenter = StaticMathFunctions.SpacePointToDisplayPointTransform(center.X, center.Y); Point anchor = new Point((Int32)(transformedCenter.X * _zoom), (Int32)(transformedCenter.Y * _zoom)); Color TransparentColor = Color.FromArgb(80, teamColor.R, teamColor.G, teamColor.B); Brush myBrush = new SolidBrush(TransparentColor); g.FillEllipse(myBrush, (Int32)(anchor.X - radx), (Int32)(anchor.Y - rady), (Int32)(radx * 2), (Int32)(rady * 2)); myBrush.Dispose(); }
private void DrawNetZAxis(Graphics g, UInt16 Xposition) { Pen drawPen = new Pen(Constants.NetsColor); // y -axis for (sbyte i = 0; i <= (Constants.GoalBottom - Constants.GoalTop) / Constants.NetsSpacing; ++i) { Int32 yval = Constants.GoalTop + i * Constants.NetsSpacing; Coords leftEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, yval); Coords rightEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition + Constants.NetsDepth, yval); PointF anchorLeft = new PointF((leftEnd.X * _zoom), (leftEnd.Y * _zoom)); PointF anchorRight = new PointF((rightEnd.X * _zoom), (rightEnd.Y * _zoom)); //Coords threadEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Constants.GoalTop + i * Constants.NetsSpacing); double zmultiplier = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(yval); float Zoffset = (float)(Constants.GoalHeight * _zoom * zmultiplier); g.DrawLine(drawPen, anchorLeft.X, anchorLeft.Y - Zoffset, anchorRight.X, anchorRight.Y - Zoffset); } // x-axis double zmultiplierNear = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalBottom); double zmultiplierFar = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalTop); float ZoffsetNear = (float)(Constants.GoalHeight * _zoom * zmultiplierNear); float ZoffsetFar = (float)(Constants.GoalHeight * _zoom * zmultiplierFar); for (sbyte i = 0; i <= Constants.NetsDepth / Constants.NetsSpacing; ++i) { Coords postNear = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition + i * Constants.NetsSpacing, Constants.GoalBottom); Coords postFar = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition + i * Constants.NetsSpacing, Constants.GoalTop); PointF anchorNear = new PointF((postNear.X * _zoom), (postNear.Y * _zoom)); PointF anchorFar = new PointF((postFar.X * _zoom), (postFar.Y * _zoom)); g.DrawLine(drawPen, anchorNear.X, anchorNear.Y - ZoffsetNear, anchorFar.X, anchorFar.Y - ZoffsetFar); } drawPen.Dispose(); }
private void DrawNetXAxis(Graphics g, UInt16 Xposition, UInt16 Yposition) { Pen drawPen = new Pen(Constants.NetsColor); double zmultiplier = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Yposition); float Zoffset = (float)(Constants.GoalHeight * _zoom * zmultiplier); // Vertical for (sbyte i = 0; i <= (Constants.NetsDepth) / Constants.NetsSpacing; ++i) { //Int32 yval = Constants.GoalTop + i * Constants.NetsSpacing; Coords threadStart = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition + i * Constants.NetsSpacing, Yposition); PointF anchor = new PointF((threadStart.X * _zoom), (threadStart.Y * _zoom)); //Coords threadEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Constants.GoalTop + i * Constants.NetsSpacing); g.DrawLine(drawPen, anchor.X, anchor.Y, anchor.X, anchor.Y - Zoffset); } // Horizontal Coords leftEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Yposition); Coords rightEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition + Constants.NetsDepth, Yposition); PointF anchorLeft = new PointF((leftEnd.X * _zoom), (leftEnd.Y * _zoom)); PointF anchorRight = new PointF((rightEnd.X * _zoom), (rightEnd.Y * _zoom)); //double zmultiplierLeft = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalBottom); //double zmultiplierRight = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalTop); for (sbyte i = 0; i <= Constants.GoalHeight / Constants.NetsSpacing; ++i) { float delataZoffset = (float)(i * Constants.NetsSpacing * _zoom * zmultiplier); //float ZoffsetFar = (float)(i * Constants.NetsSpacing * _zoom * zmultiplier); g.DrawLine(drawPen, anchorLeft.X, anchorLeft.Y - delataZoffset, anchorRight.X, anchorRight.Y - delataZoffset); } drawPen.Dispose(); }
private void DrawNetYAxis(Graphics g, UInt16 Xposition) { Pen drawPen = new Pen(Constants.NetsColor); // Vertical for (sbyte i = 0; i <= (Constants.GoalBottom - Constants.GoalTop) / Constants.NetsSpacing; ++i) { Int32 yval = Constants.GoalTop + i * Constants.NetsSpacing; Coords threadStart = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, yval); PointF anchor = new PointF((threadStart.X * _zoom), (threadStart.Y * _zoom)); //Coords threadEnd = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Constants.GoalTop + i * Constants.NetsSpacing); double zmultiplier = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(yval); float Zoffset = (float)(Constants.GoalHeight * _zoom * zmultiplier); g.DrawLine(drawPen, anchor.X, anchor.Y, anchor.X, anchor.Y - Zoffset); } // Horizontal Coords postNear = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Constants.GoalBottom); Coords postFar = StaticMathFunctions.SpacePointToDisplayPointTransform(Xposition, Constants.GoalTop); PointF anchorNear = new PointF((postNear.X * _zoom), (postNear.Y * _zoom)); PointF anchorFar = new PointF((postFar.X * _zoom), (postFar.Y * _zoom)); double zmultiplierNear = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalBottom); double zmultiplierFar = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(Constants.GoalTop); for (sbyte i = 0; i <= Constants.GoalHeight / Constants.NetsSpacing; ++i) { float ZoffsetNear = (float)(i * Constants.NetsSpacing * _zoom * zmultiplierNear); float ZoffsetFar = (float)(i * Constants.NetsSpacing * _zoom * zmultiplierFar); g.DrawLine(drawPen, anchorNear.X, anchorNear.Y - ZoffsetNear, anchorFar.X, anchorFar.Y - ZoffsetFar); } drawPen.Dispose(); }
private void DrawSomeBall(Graphics g, Ball someball, Image ballImage) { Coords ballPos = StaticMathFunctions.SpacePointToDisplayPointTransform(someball.Position3d.X, someball.Position3d.Y); Point anchor = new Point((Int32)(ballPos.X * _zoom), (Int32)(ballPos.Y * _zoom)); Int32 radiusX = (Int32)(0.5 * ballImage.Width); Int32 radiusY = (Int32)(0.5 * ballImage.Height); double zmultiplier = 0.5 + 0.5 * StaticMathFunctions.SpacePointToDisplayPointZAxis(someball.Position3d.Y); Int32 Zoffset = (Int32)(someball.Position3d.Z * _zoom * zmultiplier); Color color = Color.Black; Color TransparentColor = Color.FromArgb(150, color.R, color.G, color.B); // draw shadow. g.FillEllipse(new SolidBrush(TransparentColor), (Int32)(anchor.X - radiusX * zmultiplier), (Int32)(anchor.Y), (Int32)(radiusX * 2 * zmultiplier), (Int32)(radiusY * zmultiplier)); // draw ball g.DrawImage(ballImage, (float)(anchor.X - radiusX * zmultiplier), (float)(anchor.Y - (radiusY) * zmultiplier) - Zoffset, (float)(2 * radiusX * zmultiplier), (float)(2 * radiusX * zmultiplier)); }
private double EvaluatorShot() { double evaluation = 0; // large bonus for proximity to goal (1,e). Vector2d goalPosition = Constants.Uprights[0]; //upper-left post if (!_owner.Team.AttackingLeft) { goalPosition = Constants.Uprights[2]; //upper-right post } Vector2d goalVector = goalPosition - _owner.PositionDouble; double maxShotDistance = 2000; if (goalVector.Length() < maxShotDistance) { evaluation += Math.Pow(Math.E, (1 - goalVector.Length() / maxShotDistance)); } // large bonus for clear line of shot // add large bonus if lane of passing is empty (0,3). List <Coords> lane = _owner.InhabitedMap.RayTracer(_owner.PositionOnInfMap(), StaticMathFunctions.PositionOnFieldToInfMapCoords(goalPosition)); InfluenceMap enemyMap = _owner.EnemyTeam.TeamInfluenceMap; double interdiction = 0; for (int i = 0; i < lane.Count; ++i) { // these should be weighted somehow double toAdd = enemyMap.GetMapValue(lane[i]); if (toAdd > 0.7) { evaluation += toAdd; } } if (interdiction < 3) { evaluation += (3 - interdiction); } // there should be a bonus for easy shots // there should be a monster bonus for when the GK is out of position return(evaluation); }
/// <summary> /// Generates the influence map. /// Uses a silly recursive algorithm. /// Stopping conditions: Let's use two, to avoid stupid infinite loops. /// One is a distance threshold check. /// Second is a min influence threshold check. /// </summary> public float[,] GenerateInfluenceMap(UInt16 sizex, UInt16 sizey, Coords source, InfluenceSpreadFunction f) { float[,] influenceMap = new float[sizex, sizey]; // boolean array to keep note of which tiles have been processed BitArray[] takenCareOf = new BitArray[sizex]; for (int i = 0; i < sizex; ++i) { takenCareOf[i] = new BitArray(sizey); } takenCareOf[source.X][source.Y] = true; // sets up two queues - one for the current pass, one for the next one // distance increments by one at each pass // if too slow, the process should be broken up so it does a number of passes each tick Queue <Coords> currentQueue = new Queue <Coords>(); Queue <Coords> nextQueue = new Queue <Coords>(); currentQueue.Enqueue(source); UInt32 currentDistance = 0; // main loop // Stopping conditions: the two queues are exhausted, OR InfluenceMapMaxDistance is reached while ( ((currentQueue.Count > 0) & (nextQueue.Count > 0)) | (currentDistance < Constants.InfluenceMapMaxDistance) ) { // Checks if it's time to start the next pass if (currentQueue.Count == 0) { currentQueue = nextQueue; nextQueue = new Queue <Coords>(); currentDistance++; continue; } Coords currentCoords = currentQueue.Peek(); // Analyzes the neighbors of the current Tile for possible additions to nextQueue for (byte i = 0; i < 8; i++) { Direction currentDir = (Direction)i; Coords toCheck = StaticMathFunctions.CoordsNeighboringInDirection(currentCoords, currentDir); if (toCheck.X >= 0 && toCheck.X < sizex && toCheck.Y >= 0 && toCheck.Y < sizey) { if (!takenCareOf[toCheck.X][toCheck.Y]) { nextQueue.Enqueue(toCheck); takenCareOf[toCheck.X][toCheck.Y] = true; } } } float newVal = f(currentDistance); // Check to avert infnite / excessively deep loop if (newVal > Constants.InfluenceMapMinThreshold) { influenceMap[currentCoords.X, currentCoords.Y] = newVal; } currentQueue.Dequeue(); } return(influenceMap); }