コード例 #1
0
ファイル: GameState.cs プロジェクト: idg10/AoC2018
        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));
        }
コード例 #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);
        }
コード例 #3
0
ファイル: GameState.cs プロジェクト: idg10/AoC2018
 private GameState(
     GridPair gridPair,
     IImmutableDictionary <int, int> elfHitPoints,
     IImmutableDictionary <int, int> goblinHitPoints,
     int elfAttackPower)
 {
     ElfHitPoints    = elfHitPoints;
     GoblinHitPoints = goblinHitPoints;
     ElfAttackPower  = elfAttackPower;
     _gridPair       = gridPair;
 }