Ejemplo n.º 1
0
 public Intelligence(int coordY, int coordX)
 {
     _targetDirection       = RandomCoords.GetRandomDirection();
     _counterSuccessfulShot = 0;
     _cleanShotPosition     = new Position(coordY, coordX);
     _isTargetPlayer        = false;
 }
Ejemplo n.º 2
0
        public virtual void MakeTheShot(ref bool isAlivePlayerAfterShoot, Sea playerMap)
        {
            if (!isAlivePlayerAfterShoot)
            {
                RandomCoords.SearchRandomCoords(playerMap);
                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);

                if (_isTargetPlayer)
                {
                    SaveCoordsSuccessfulTarget(playerMap);
                }
            }
            else
            {
                GetTargetCoords(playerMap);
                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);
            }
        }
Ejemplo n.º 3
0
        public override void MakeTheShot(ref bool isAlivePlayerAfterShoot, Sea playerMap)
        {
            bool wasShot = false;

            if (!isAlivePlayerAfterShoot)
            {
                do
                {
                    if (_plentyShots.Count <= 0)
                    {
                        RandomCoords.SearchRandomCoords(playerMap);
                        //break;//
                    }
                    else
                    {
                        Position currentPos = _plentyShots.Dequeue();

                        playerMap.TargetCoordX = currentPos.OX;
                        playerMap.TargetCoordY = currentPos.OY;

                        wasShot = playerMap.WasShot();
                    }
                } while (wasShot);


                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);

                if (_isTargetPlayer)
                {
                    SaveCoordsSuccessfulTarget(playerMap);
                }
            }
            else
            {
                GetTargetCoords(playerMap);

                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);
            }
        }
Ejemplo n.º 4
0
 public AdvancedIntelligence(int coordY, int coordX)
     : base(coordY, coordX)
 {
     _playerShips = (BitShipType)Constants.COUNT_SHIPS_TYPE;
     _plentyShots = RandomCoords.BuildShootsLine();
 }
Ejemplo n.º 5
0
        public static Queue <Position> BuildShootsLine()
        {
            bool             isFromTop;
            int              countShootsInLine;
            Position         startPosition;
            Queue <Position> plentyShoots = new Queue <Position>();

            ShotDirection[] directionsOrder = RandomCoords.GetLineDirectionForShoot();

            for (int i = 0; i < directionsOrder.Length; i++)
            {
                switch (directionsOrder[i])
                {
                case ShotDirection.TwoCellWestNorth:
                    startPosition     = new Position(Constants.SECOND_CELL, 0);
                    countShootsInLine = TWO_SHOTS;
                    isFromTop         = false;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.FourCellWestNorth:
                    startPosition     = new Position(0, Constants.FOURTH_CELL);
                    countShootsInLine = FOUR_SHOTS;
                    isFromTop         = true;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.SixCellWestNorth:
                    startPosition     = new Position(Constants.SIXTH_CELL, 0);
                    countShootsInLine = SIX_SHOTS;
                    isFromTop         = false;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.EightCellWestNorth:
                    startPosition     = new Position(0, Constants.EIGHTH_CELL);
                    countShootsInLine = EIGTH_SHOTS;
                    isFromTop         = true;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.Center:
                    startPosition     = new Position(Constants.TENTH_CELL, 0);
                    countShootsInLine = TEN_SHOTS;
                    isFromTop         = false;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.EightCellEastSouth:
                    startPosition     = new Position(Constants.THIRD_CELL, Constants.TENTH_CELL);
                    countShootsInLine = EIGTH_SHOTS;
                    isFromTop         = true;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.SixCellEastSouth:
                    startPosition     = new Position(Constants.TENTH_CELL, Constants.FIFTH_CELL);
                    countShootsInLine = SIX_SHOTS;
                    isFromTop         = false;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.FourCellEastSouth:
                    startPosition     = new Position(Constants.SEVENTH_CELL, Constants.TENTH_CELL);
                    countShootsInLine = FOUR_SHOTS;
                    isFromTop         = true;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                case ShotDirection.TwoCellEastSouth:
                    startPosition     = new Position(Constants.TENTH_CELL, Constants.NINTH_CELL);
                    countShootsInLine = TWO_SHOTS;
                    isFromTop         = false;
                    CalculateCoordsForShoot(countShootsInLine, startPosition, isFromTop, ref plentyShoots);
                    break;

                default:
                    break;
                }
            }

            return(plentyShoots);
        }