Ejemplo n.º 1
0
 public SunkSubmarine(Cell cell, Color color)
 {
     Texture = LogicService.sunk;
     this.color = color;
     this.Cell = cell;
     Order = 2;
 }
Ejemplo n.º 2
0
 public BaseC(Cell cell, Team team)
 {
     Cell = cell;
     Parent = team;
     Texture = LogicService.baseC;
     Order = 1;
 }
Ejemplo n.º 3
0
 public Boom(Cell cell, GameTime gameTime, EntityCollection parent)
 {
     Texture = LogicService.boom;
     this.Cell = cell;
     startedTime = gameTime.Total.TotalSeconds;
     this.parent = parent;
     Order = 6;
 }
Ejemplo n.º 4
0
 public static CustomMarker getMarker(String name, Cell cell)
 {
     Texture2D texture;
     if (textures.TryGetValue(name, out texture))
         return new CustomMarker(texture, cell);
     else
         return null;
 }
Ejemplo n.º 5
0
 internal Mine(Cell cell, Team team)
 {
     Texture = LogicService.mine;
     Parent = team;
     Cell = cell;
     _noise = Config.NOISE_BOOM_MINE;
     Order = 3;
 }
Ejemplo n.º 6
0
 public Move(Entity sub, Cell to, ActionsQueue queue, float speed, double noise)
 {
     k++;
     Entity = sub;
     this.to = to;
     ActionsQueue = queue;
     Noise = noise;
     _speed = speed;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 //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);
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 public Flag(Cell cell)
     : base(LogicService.flag, cell)
 {
 }
Ejemplo n.º 14
0
 private CustomMarker(Texture2D texture, Cell cell)
     : base(texture, cell)
 {
 }
Ejemplo n.º 15
0
 public Marker(Texture2D texture, Cell cell)
 {
     Texture = texture;
     Cell = cell;
     Order = 0;
 }
Ejemplo n.º 16
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>();
 }
Ejemplo n.º 17
0
 internal void addNeighbor(Cell cell)
 {
     neighbours.Add(cell);
 }
Ejemplo n.º 18
0
 public List<Cell> getPath(Cell from, Cell to, Func<Cell, Cell, float> weightFunc = null)
 {
     return new AStar().FindPath(this, from, to, weightFunc);
 }
Ejemplo n.º 19
0
 public List <Cell> getPath(Cell from, Cell to, Func <Cell, Cell, float> weightFunc = null)
 {
     return(new AStar().FindPath(this, from, to, weightFunc));
 }
Ejemplo n.º 20
0
 private int GetHeuristicPathLength(Cell from, Cell to)
 {
     return Math.Abs(from.I - to.I) + Math.Abs(from.J - to.J);
 }
Ejemplo n.º 21
0
        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));
            }
        }
Ejemplo n.º 22
0
 public Circle(Cell cell)
     : base(LogicService.circle, cell)
 {
 }
Ejemplo n.º 23
0
 internal void addNewNoise(Cell cell, double noise)
 {
     if (primalNoise[cell.I, cell.J] < noise) primalNoise[cell.I, cell.J] = noise;
 }
Ejemplo n.º 24
0
 public Check(Cell cell)
     : base(LogicService.check, cell)
 {
 }
Ejemplo n.º 25
0
 public Aim(Cell cell)
     : base(LogicService.aim, cell)
 {
 }
Ejemplo n.º 26
0
 public XMark(Cell cell)
     : base(LogicService.xMark, cell)
 {
 }
Ejemplo n.º 27
0
        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]);
                    }
                }
        }