Пример #1
0
    private bool TrySelectMinePosition(out Position position, out Direction direction)
    {
        position  = Position.None;
        direction = Direction.E;

        if (_gameState.MineAvailable == false)
        {
            return(false);
        }

        var myPosition             = MySubmarine.Position;
        var neighborWaterPositions = Map.GetNeighborPositions(myPosition);
        var placedMines            = MySubmarine.GetPlacedMines();

        foreach (var item in neighborWaterPositions)
        {
            var possibleMinePosition  = item.Value;
            var possibleMineDirection = item.Key;

            if (MySubmarine.HasPlacedMineAt(possibleMinePosition) == false)
            {
                var blastedPositions = GetBlastedPositions(possibleMinePosition);
                var blastOtherMines  = blastedPositions.Any(p => placedMines.Contains(p));

                if (blastOtherMines == false)
                {
                    position  = possibleMinePosition;
                    direction = possibleMineDirection;
                }
            }
        }

        return(position.IsNot(Position.None));
    }
Пример #2
0
    private bool TryTriggerMine(out Position bestMinePosition)
    {
        bestMinePosition = Position.None;

        var enemyPositions = OpponentSubmarine.PossiblePositions;

        if (enemyPositions.Count > 30)
        {
            return(false);
        }

        //Select the mine which blast the maximum opponent positions
        var minePositions            = MySubmarine.GetPlacedMines();
        var blastedOpponentPositions = 0;

        foreach (var minePosition in minePositions)
        {
            var blastedPositions = GetBlastedPositions(minePosition);

            if (blastedPositions.Contains(MySubmarine.Position) == false)
            {
                //Count how many possible positions are blasted
                var count = enemyPositions.Count(p => blastedPositions.Contains(p));

                if (count >= 6 || enemyPositions.Count <= 6)
                {
                    if (count > blastedOpponentPositions)
                    {
                        blastedOpponentPositions = count;
                        bestMinePosition         = minePosition;
                    }
                }
            }
        }

        return(bestMinePosition.IsNot(Position.None));
    }