public virtual Piece ChooseTarget(BattleBoard battleBoard) { Piece bestTarget = null; foreach (var piece in battleBoard.Pieces) { if (piece.teamColor != owner.teamColor) { if (bestTarget == null) { bestTarget = piece; Path = FindPathToTarget(piece, battleBoard); OpenNodes = CopyList(openNodes); ClosedNodes = CopyList(closedNodes); } else { Path comparePath = FindPathToTarget(piece, battleBoard); if (comparePath.Value > Path.Value) { Path = comparePath; bestTarget = piece; OpenNodes = CopyList(openNodes); ClosedNodes = CopyList(closedNodes); } } } } return(bestTarget); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Screen screen = Screen.AllScreens.First(e => e.Primary); camera = new Camera(new Vector2(0,0),new Vector2(screen.Bounds.Width,screen.Bounds.Height) ); battleBoard = new BattleBoard(Content); }
public Piece(Texture2D spriteTexture, Field field, int cellSize, int maxAP, bool clever, BattleBoard board) : base(spriteTexture, new Vector2(0, 0)) { this.battleBoard = board; this.Field = field; this.cellSize = cellSize; MaxActionPoints = maxAP; MoveVector = Vector2.Zero; if (clever) { AI = new CleverAI(this); } else { AI = new AI(this); } }
public List <Field> Neighbors(BattleBoard board, Field target) { List <Field> neighbors = new List <Field>(); for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (X + i >= 0 && X + i < 20 && Y + j >= 0 && Y + j < 20 && (i != 0 || j != 0)) { if (board.Fields[X + i, Y + j].Terrain != -1 && board.Fields[X + i, Y + j].Piece == null || (target.X == X + i && target.Y == Y + j)) { neighbors.Add(board.Fields[X + i, Y + j]); } } } } return(neighbors); }
public MapFactory(BattleBoard board) { _board = board; cleverAI = false; }
public PieceMover(BattleBoard battleBoard) { this.battleBoard = battleBoard; }
public virtual Path FindPathToTarget(Piece targetPiece, BattleBoard board) { Field origin = owner.Field; Field target = targetPiece.Field; Field currentNode; //create the open list of nodes, initially containing only our starting node //create the closed list of nodes, initially empty openNodes.Clear(); closedNodes.Clear(); openNodes.Add(origin); Path path = new Path(owner, targetPiece); board.ClearParents(); bool done = false; while (!done) { //consider the best node in the open list (the node with the lowest f value) float lowestF = openNodes[0].F(target); currentNode = openNodes[0]; foreach (var node in openNodes) { if (node.F(target) < lowestF) { currentNode = node; lowestF = node.F(target); } } if (currentNode.Equals(target)) { done = true; Console.WriteLine("Success"); path.Cost = (int)currentNode.PathCost; while (currentNode.PathParent != null) { path.Fields.Add(currentNode); currentNode = currentNode.PathParent; } return(path); } else { //move the current node to the closed list and consider all of its neighbors openNodes.Remove(currentNode); closedNodes.Add(currentNode); List <Field> neighbors = currentNode.Neighbors(board, target); foreach (var node in neighbors) { if (closedNodes.Contains(node) || openNodes.Contains(node)) { if (node.PathCost > currentNode.PathCost + node.StepCost(currentNode)) { node.PathCost = currentNode.PathCost + node.StepCost(currentNode); node.PathParent = currentNode; } } else { node.PathCost = currentNode.PathCost + node.StepCost(currentNode); node.PathParent = currentNode; openNodes.Add(node); } } } if (openNodes.Count == 0) { Console.WriteLine("No path found"); return(null); } } return(null); }