Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the current diffusion scores for layer 2.
        /// </summary>
        /// <param name="state">The state.</param>
        public void diffuseTwo(GameState state)
        {
            for (int row = 0; row < state.Height; row++)
            {
                for (int col = 0; col < state.Width; col++)
                {
                    if (state.map[row, col] == Tile.Water) state.diffusionTwo[row, col] = WATER_SCORE;

                    else if (state.map[row, col] == Tile.Ant
                        && state.ants.ContainsKey(new Location(row, col))
                        && state.ants[new Location(row, col)].Team != 0)
                    {
                        state.diffusionTwo[row, col] = ENEMY_ANT_SCORE_D2;
                    }
                    else if (state.map[row, col] == Tile.Unseen)
                    {
                        state.diffusionTwo[row, col] = UNSEEN_SCORE_D2;
                    }
                    else if (state.isEnemyHill(row, col))
                    {
                        state.diffusionTwo[row, col] = ENEMYHILL_SCORE_D2;
                    }
                    else if (state.isMyHill(row, col))
                    {
                        state.diffusionTwo[row, col] = MYHILL_SCORE;
                    }
                    else
                    {
                        double u = state.diffusionTwo[row, col];
                        Location location = new Location(row, col);
                        Location up = state.GetDestination(location, Direction.North);
                        Location right = state.GetDestination(location, Direction.East);
                        Location left = state.GetDestination(location, Direction.West);
                        Location down = state.GetDestination(location, Direction.South);
                        state.diffusionTwo[row, col] = u + D2_COEFFICIENT * (1
                                                     + state.diffusionTwo[up.Row, up.Col]
                                                     + state.diffusionTwo[down.Row, down.Col]
                                                     + state.diffusionTwo[left.Row, left.Col]
                                                     + state.diffusionTwo[right.Row, right.Col]
                                                     - u * 4);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the current diffusion scores for layer 1.
        /// </summary>
        /// <param name="state">The state.</param>
        public void diffuseOne(GameState state)
        {
            for (int row = 0; row < state.Height; row++)
            {
                for (int col = 0; col < state.Width; col++)
                {
                    if (state.map[row, col] == Tile.Water)
                    {
                        state.diffusionOne[row, col] = WATER_SCORE;
                    }

                    else if (state.map[row, col] == Tile.Ant)
                    {
                        state.diffusionOne[row, col] = MY_ANT_SCORE_D1;

                        Location location = new Location(row, col);
                        if (state.ants.ContainsKey(location))
                        {
                            Ant ant = state.ants[location];

                            if (ant.Team != 0)
                            {
                                List<AntHill> myHills = state.MyHills;
                                foreach (AntHill myHill in myHills)
                                {
                                    if (state.GetDistance(myHill, ant) <= 12)
                                    {
                                        state.diffusionOne[row, col] = HILL_IN_DANGER;

                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if (state.map[row, col] == Tile.Food)
                    {
                        state.diffusionOne[row, col] = FOOD_SCORE_D1;
                    }
                    else if (state.map[row, col] == Tile.Unseen)
                    {
                        state.diffusionOne[row, col] = UNSEEN_SCORE_D1;
                    }
                    else if (state.isEnemyHill(row, col))
                    {
                        state.diffusionOne[row, col] = ENEMYHILL_SCORE_D1;
                    }
                    else if (state.isMyHill(row, col))
                    {
                        state.diffusionOne[row, col] = MYHILL_SCORE;
                    }
                    else
                    {
                        double u = state.diffusionOne[row, col];
                        Location L = new Location(row, col);
                        Location up = state.GetDestination(L, Direction.North);
                        Location right = state.GetDestination(L, Direction.East);
                        Location left = state.GetDestination(L, Direction.West);
                        Location down = state.GetDestination(L, Direction.South);
                        state.diffusionOne[row, col] = u + D1_COEFFICIENT * (1
                                                     + state.diffusionOne[up.Row, up.Col]
                                                     + state.diffusionOne[down.Row, down.Col]
                                                     + state.diffusionOne[left.Row, left.Col]
                                                     + state.diffusionOne[right.Row, right.Col]
                                                     - u * 4);
                    }
                }
            }
        }