Beispiel #1
0
        public static GameState Start(
            GridCell[,] grid,
            int elfAttackPower = 3)
        {
            var gridPair = GridPair.For(grid);

            GridOperations.CalculateCloseness(gridPair);
            var elfHitPoints    = ImmutableDictionary <int, int> .Empty;
            var goblinHitPoints = ImmutableDictionary <int, int> .Empty;
            int height          = gridPair.Primary.GetLength(0);
            int width           = gridPair.Primary.GetLength(1);

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    GridCell cell = gridPair.Primary[y, x];
                    if (cell.IsElf)
                    {
                        elfHitPoints = elfHitPoints.Add(cell.ElfId.Value, 200);
                    }
                    else if (cell.IsGoblin)
                    {
                        goblinHitPoints = goblinHitPoints.Add(cell.GoblinId.Value, 200);
                    }
                }
            }

            return(new GameState(gridPair, elfHitPoints, goblinHitPoints, elfAttackPower));
        }
Beispiel #2
0
        /// <summary>
        /// Populate a grid with information about the closest in range cells.
        /// </summary>
        /// <param name="grid">
        /// A grid array, which must not yet have any closeness information in it.
        /// </param>
        /// <returns>
        /// The grid, populated with closeness information. NOTE: this might be the same grid as was
        /// passed in - this method can operates in situ.
        /// </returns>
        public static void CalculateCloseness(GridPair gridPair)
        {
            bool workToDo;

            do
            {
                workToDo = ProcessOneClosenessStep(gridPair.Primary, gridPair.Secondary);
                gridPair = gridPair.Swap();
            } while (workToDo);
        }
Beispiel #3
0
 private GameState(
     GridPair gridPair,
     IImmutableDictionary <int, int> elfHitPoints,
     IImmutableDictionary <int, int> goblinHitPoints,
     int elfAttackPower)
 {
     ElfHitPoints    = elfHitPoints;
     GoblinHitPoints = goblinHitPoints;
     ElfAttackPower  = elfAttackPower;
     _gridPair       = gridPair;
 }