public SunkSubmarine(Cell cell, Color color) { Texture = LogicService.sunk; this.color = color; this.Cell = cell; Order = 2; }
public BaseC(Cell cell, Team team) { Cell = cell; Parent = team; Texture = LogicService.baseC; Order = 1; }
public Boom(Cell cell, GameTime gameTime, EntityCollection parent) { Texture = LogicService.boom; this.Cell = cell; startedTime = gameTime.Total.TotalSeconds; this.parent = parent; Order = 6; }
public static CustomMarker getMarker(String name, Cell cell) { Texture2D texture; if (textures.TryGetValue(name, out texture)) return new CustomMarker(texture, cell); else return null; }
internal Mine(Cell cell, Team team) { Texture = LogicService.mine; Parent = team; Cell = cell; _noise = Config.NOISE_BOOM_MINE; Order = 3; }
public Move(Entity sub, Cell to, ActionsQueue queue, float speed, double noise) { k++; Entity = sub; this.to = to; ActionsQueue = queue; Noise = noise; _speed = speed; }
public Check(Entity entity, ActionsQueue queue, Double noise, Cell to, Cell from, float speed) { this.noise = noise; this.queue = queue; this.entity = entity; this.to = to; this.from = from; this.speed = speed; }
//float Critetion(Cell) { // return 0.5; //} private float GetDistanceBetweenNeighbours(Cell from, Cell to, Func<Cell, Cell, float> weightFunc = null) { //FindPath(0, 0, 0, Critetion); //return ((from.Type == CellType.DEEP) && (from.Type == to.Type)) ? 1 : 9999; if (weightFunc == null) { return 1; } return weightFunc.Invoke(from, to); }
internal Submarine(Cell cell, Team team, Texture2D texture, int number, int health, int tCount, int mCount) { this.Cell = cell; this.X = cell.X - Config.OffsetX; this.Y = cell.Y - Config.OffsetY; this.Parent = team; this._healths = health; this.Texture = texture; this._health = LogicService.health; Order = 5; _number = number; _torpedoCount = tCount; _minesCount = mCount; }
public Submarine(Cell cell, Team team, Texture2D texture) { this.Cell = cell; this.X = cell.X - Config.OffsetX; this.Y = cell.Y - Config.OffsetY; this.Parent = team; this._healths = 3; this.Texture = texture; this._health = LogicService.health; Order = 5; _number = count; count++; _torpedoCount = Config.TORPEDO_COUNT; _minesCount = Config.MINES_COUNT; }
private Collection<PathNode> GetNeighbours(PathNode pathNode, Cell goal, GameField field, Func<Cell, Cell, float> weightFunc = null) { var result = new Collection<PathNode>(); List<Cell> neighboursCell = pathNode.Position.Neighbours; foreach (var point in neighboursCell) { if (point.Type == CellType.LAND) continue; var neighbourNode = new PathNode() { Position = point, CameFrom = pathNode, PathLengthFromStart = pathNode.PathLengthFromStart + GetDistanceBetweenNeighbours(pathNode.Position, point, weightFunc), HeuristicEstimatePathLength = GetHeuristicPathLength(point, goal) }; result.Add(neighbourNode); } return result; }
public List<Cell> FindPath(GameField field, Cell start, Cell goal, Func<Cell, Cell, float> weightFunc = null) { var closedSet = new Collection<PathNode>(); var openSet = new Collection<PathNode>(); PathNode startNode = new PathNode() { Position = start, CameFrom = null, PathLengthFromStart = 0, HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal) }; openSet.Add(startNode); while (openSet.Count > 0) { var currentNode = openSet.OrderBy(node => node.EstimateFullPathLength).First(); if (currentNode.Position == goal) return GetPathForNode(currentNode); openSet.Remove(currentNode); closedSet.Add(currentNode); foreach (var neighbourNode in GetNeighbours(currentNode, goal, field, weightFunc)) { if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0) continue; var openNode = openSet.FirstOrDefault(node => node.Position == neighbourNode.Position); if (openNode == null) openSet.Add(neighbourNode); else if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart) { openNode.CameFrom = currentNode; openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart; } } } return null; }
public Flag(Cell cell) : base(LogicService.flag, cell) { }
private CustomMarker(Texture2D texture, Cell cell) : base(texture, cell) { }
public Marker(Texture2D texture, Cell cell) { Texture = texture; Cell = cell; Order = 0; }
internal void createTopology() { Cell[] temp = new Cell[6]; foreach (Cell neighbour in neighbours) { if (neighbour.Type == CellType.LAND) continue; if ((neighbour.I == I) && (neighbour.J == J + 1)) temp[0] = neighbour; if ((neighbour.I == I) && (neighbour.J == J - 1)) temp[3] = neighbour; if (I % 2 == 0) { if ((neighbour.I == I - 1) && (neighbour.J == J)) temp[1] = neighbour; if ((neighbour.I == I - 1) && (neighbour.J == J - 1)) temp[2] = neighbour; if ((neighbour.I == I + 1) && (neighbour.J == J - 1)) temp[4] = neighbour; if ((neighbour.I == I + 1) && (neighbour.J == J)) temp[5] = neighbour; } else { if ((neighbour.I == I - 1) && (neighbour.J == J + 1)) temp[1] = neighbour; if ((neighbour.I == I - 1) && (neighbour.J == J)) temp[2] = neighbour; if ((neighbour.I == I + 1) && (neighbour.J == J)) temp[4] = neighbour; if ((neighbour.I == I + 1) && (neighbour.J == J + 1)) temp[5] = neighbour; } } topology = temp.ToList<Cell>(); }
internal void addNeighbor(Cell cell) { neighbours.Add(cell); }
public List<Cell> getPath(Cell from, Cell to, Func<Cell, Cell, float> weightFunc = null) { return new AStar().FindPath(this, from, to, weightFunc); }
public List <Cell> getPath(Cell from, Cell to, Func <Cell, Cell, float> weightFunc = null) { return(new AStar().FindPath(this, from, to, weightFunc)); }
private int GetHeuristicPathLength(Cell from, Cell to) { return Math.Abs(from.I - to.I) + Math.Abs(from.J - to.J); }
void createBase(Cell initialCell) { List<Cell> basePoints = new List<Cell>(); Cell temp = initialCell; if (temp.Type == CellType.LAND) { List<Cell> queue = new List<Cell>(); queue.AddRange(temp.Neighbours); Boolean find = false; temp = queue[0]; while (!find) if (temp.Type != CellType.LAND) find = true; else { foreach (Cell neighbour in temp.Neighbours) if (!queue.Contains(neighbour)) queue.Add(neighbour); queue.RemoveAt(0); temp = queue[0]; } } basePoints.Add(temp); for (int i = 0; i < 2; i++) { Cell c = temp.Neighbours[rnd.Next(temp.Neighbours.Count)]; Boolean f = false; while ((c.Type == CellType.LAND) || (!f)) { c = temp.Neighbours[rnd.Next(temp.Neighbours.Count)]; f = true; foreach (Cell curBase in basePoints) if ((curBase.I == c.I) && (curBase.J == c.J)) { f = false; break; } } basePoints.Add(c); temp = c; } foreach (Cell cell in basePoints) { this.addToCollection(new BaseC(cell, this)); } }
public Circle(Cell cell) : base(LogicService.circle, cell) { }
internal void addNewNoise(Cell cell, double noise) { if (primalNoise[cell.I, cell.J] < noise) primalNoise[cell.I, cell.J] = noise; }
public Check(Cell cell) : base(LogicService.check, cell) { }
public Aim(Cell cell) : base(LogicService.aim, cell) { }
public XMark(Cell cell) : base(LogicService.xMark, cell) { }
void createField() { field = new Cell[_height, _width]; primalNoise = new double[_height, _width]; for (int i = 0; i < _height; i++) for (int j = 0; j < _width; j++) field[i, j] = new Cell(i, j, CellType.DEEP); for (int i = 0; i < _height; i++) for (int j = 0; j < _width; j++) { Cell cell = field[i, j]; if (i - 1 >= 0) cell.addNeighbor(field[i - 1, j]); if (i + 1 < _height) cell.addNeighbor(field[i + 1, j]); if (j - 1 >= 0) cell.addNeighbor(field[i, j - 1]); if (j + 1 < _width) cell.addNeighbor(field[i, j + 1]); if (i % 2 == 1) { if ((i - 1 >= 0) & (j + 1 < _width)) cell.addNeighbor(field[i - 1, j + 1]); if ((i + 1 < _height) & (j + 1 < _width)) cell.addNeighbor(field[i + 1, j + 1]); } else { if ((i - 1 >= 0) & (j - 1 >= 0)) cell.addNeighbor(field[i - 1, j - 1]); if ((i + 1 < _height) & (j - 1 >= 0)) cell.addNeighbor(field[i + 1, j - 1]); } } }