protected override void Intresst(Cell cell, SectorContent percivableObjects) { GameObject intresst = null; if (percivableObjects.All.Count > 0) { intresst = percivableObjects.All[0]; //gör intresset till det närmaste objectet av saker AI kan se foreach (GameObject g in percivableObjects.All) { if ( Math.Pow(g.Position.X - cell.Position.X, 2) + Math.Pow(g.Position.Y - cell.Position.Y, 2) <= Math.Pow(intresst.Position.X - cell.Position.X, 2) + Math.Pow(intresst.Position.Y - cell.Position.Y, 2) ) { intresst = g; } } } if (intresst == null) { intresst = idleDestination; } lastIntresst = intresst; Decision(cell, lastIntresst); }
/// <summary> /// Väljer vad som är intressant för AI /// </summary> protected virtual void Intresst(Cell cell, SectorContent percivableObjects) { GameObject intresst = null; lastIntresst = intresst; Decision(cell, intresst); }
//Perception void PerceptionCheck(List <GameObject> pc) { SectorContent percivableObjects = new SectorContent(); foreach (GameObject g in pc) { if (g != this) { if ( Math.Pow(g.Position.X - this.position.X, 2) + Math.Pow(g.Position.Y - this.position.Y, 2) <= Math.Pow(this.Detectionrange, 2) + Math.Pow(g.Size, 2) ) { percivableObjects.Add(g); } } } ai.AIR(this, percivableObjects); }
protected override void Intresst(Cell cell, SectorContent percivableObjects) { //Samlar val med mest poäng List <GameObject> bestIntrest = new List <GameObject>(); if (percivableObjects.All.Count > 0) { bestIntrest.Add(percivableObjects.All[0]); foreach (GameObject g in percivableObjects.All) { if (MemoryChoice(Data(cell, g)).Points > MemoryChoice(Data(cell, bestIntrest[0])).Points) { bestIntrest.Clear(); bestIntrest.Add(g); } else if (MemoryChoice(Data(cell, g)).Points == MemoryChoice(Data(cell, bestIntrest[0])).Points) { bestIntrest.Add(g); } } } //Om det inte finns minnen if (bestIntrest.Count <= 0) { bestIntrest.Add(idleDestination); } //För att hindra obeslutsamhet ska den fortsätta göra det den val att göra från början if (bestIntrest.Contains(lastIntresst)) { bestIntrest.Clear(); bestIntrest.Add(lastIntresst); } //Väljer slumpvalt val utifrån val med mest poäng lastIntresst = bestIntrest[StaticGlobal.Random.Next(bestIntrest.Count)]; Decision(cell, lastIntresst); }
protected override void Intresst(Cell cell, SectorContent percivableObjects) { Decision(cell, null); }
/// <summary> /// Standardiserad utgångspunkt för AI Processen (AI-Run (AIR)) /// </summary> public void AIR(Cell cell, SectorContent percivableObjects) { Intresst(cell, percivableObjects); }
public static void Draw(CellManager CM, GraphicsDevice GraphicsDevice) { byte gridWidth = (byte)(1 + StaticGlobal.Screen.Area.Width / (StaticGlobal.SectorSize * Camera.Zoom)), gridHeight = (byte)(1 + StaticGlobal.Screen.Area.Height / (StaticGlobal.SectorSize * Camera.Zoom)); float offset; // Drawing the Grid (vertical) for (int y = -(gridHeight >> 1) - 1; y < (gridHeight << 1); y++) { offset = y * StaticGlobal.SectorSize * Camera.Zoom - (Camera.Position.Y % StaticGlobal.SectorSize * Camera.Zoom) + (StaticGlobal.Screen.Area.Height >> 1); gridLine.SetLine( new Vector2(0, offset), new Vector2(StaticGlobal.Screen.Area.Width, offset), false ); gridLine.Render(GraphicsDevice); } // Drawing the Grid (horizontal) for (int x = -(gridWidth >> 1) - 1; x < (gridWidth << 1); x++) { offset = x * StaticGlobal.SectorSize * Camera.Zoom - (Camera.Position.X % StaticGlobal.SectorSize * Camera.Zoom) + (StaticGlobal.Screen.Area.Width >> 1); gridLine.SetLine( new Vector2(offset, 0), new Vector2(offset, StaticGlobal.Screen.Area.Height), false ); gridLine.Render(GraphicsDevice); } int xoff = (int)(Camera.Position.X / StaticGlobal.SectorSize) - (gridWidth >> 1) - 2, // - 2 because out of screen yoff = (int)(Camera.Position.Y / StaticGlobal.SectorSize) - (gridHeight >> 1) - 2 // - 2 because out of screen ; // Drawing content inside of Chunks for (int y = yoff; y < gridHeight + yoff + 3; y++) // + 3 because out of screen { for (int x = xoff; x < gridWidth + xoff + 3; x++) // + 3 because out of screen { Point p = new Point( x, y ); if (CM.Sectors.ContainsKey(p)) { SectorContent sector = CM.Sectors[p]; // draw code ... // Draw Food for (int i = 0; i < sector.Foods.Count; i++) { circleFood.Radius = sector.Foods[i].Size * Camera.Zoom; circleFood.Position = Camera.GetRelativePosition(sector.Foods[i].Position); circleFood.UpdateVertices(); circleFood.Render(GraphicsDevice); } // Draw Cells for (int i = 0; i < sector.Cells.Count; i++) { switch (sector.Cells[i].AI.family.Split(' ')[0]) { case "Red": circleCell.Color = Color.Red; break; case "Blue": circleCell.Color = Color.Blue; break; case "Green": circleCell.Color = Color.Green; break; case "Cyan": circleCell.Color = Color.Cyan; break; case "Magenta": circleCell.Color = Color.Magenta; break; case "Yellow": circleCell.Color = Color.Yellow; break; case "Black": circleCell.Color = Color.Black; break; case "White": circleCell.Color = Color.White; break; default: break; } ; circleCell.Radius = sector.Cells[i].Size * Camera.Zoom; circleCell.Position = Camera.GetRelativePosition(sector.Cells[i].Position); circleCell.UpdateVertices(); circleCell.Render(GraphicsDevice); } // Drawing Cells "destination"/"direction" for (int i = 0; i < sector.Cells.Count; i++) { line.SetLine( sector.Cells[i].Position, sector.Cells[i].Position + (sector.Cells[i].AI.Direction) ); line.Render(GraphicsDevice); } } } } // END OF Draw() }