Beispiel #1
0
        public void PlaceShips(IPlayerView playerView, ICollection<IVessel> ships)
        {
            /* This AI places ships in the upper right corner and to the left.
             *
             * E.g.
             *
             * 10  #   #   #   #   #
             * 9   #   #   #   #   #
             * 8       #   #   #   #
             * 7               #   #
             * 6                   #
             * 5
             * 4
             * 3
             * 2
             * 1
             *   1 2 3 4 5 6 7 8 9 10
             */

            Placement place;
            Coordinate coord;
            int xMax = playerView.GetXMax();
            int yMax = playerView.GetYMax();

            int i = 0;
            foreach (IVessel ship in ships)
            {
                coord = new Coordinate(xMax - (2 * i), yMax);
                place = new Placement(ship, coord, Orientation.Vertical);
                playerView.PutShip(place);

                i++;
            }
        }
Beispiel #2
0
        public Shot YourTurn(IPlayerView playerView)
        {
            int xMax = playerView.GetXMax();
            int yMax = playerView.GetYMax();

            Shot fireZeMissles = new Shot(_nextShot.X, _nextShot.Y);

            _nextShot.X++;

            if (_nextShot.X > xMax)
            {
                _nextShot.Y++;
                _nextShot.X = 1;
            }

            if (_nextShot.Y > yMax)
                _nextShot.Y = 1;

            return fireZeMissles;
        }
Beispiel #3
0
        public void PlaceShips(IPlayerView playerView, ICollection<IVessel> ships)
        {
            int maxX = playerView.GetXMax();
            int maxY = playerView.GetYMax();

            Placement placement;
            int xPos;
            int yPos;
            Orientation direction;

            foreach (IVessel ship in ships)
            {
                do
                {
                    xPos = _rand.Next(maxX) + 1;
                    yPos = _rand.Next(maxY) + 1;
                    direction = _rand.NextDouble() > 0.5 ? Orientation.Horizontal : Orientation.Vertical;
                    placement = new Placement(ship, xPos, yPos, direction);
                } while (!playerView.PutShip(placement));
            }
        }
Beispiel #4
0
 public Shot YourTurn(IPlayerView playerView)
 {
     int x = _rand.Next(playerView.GetXMax()) + 1;
     int y = _rand.Next(playerView.GetYMax()) + 1;
     return new Shot(x, y);
 }
Beispiel #5
0
        private void InitializeAI(IPlayerView playerView)
        {
            _xMax = playerView.GetXMax();
              _yMax = playerView.GetYMax();
              byte[] randomBytes = new byte[1];
              System.Security.Cryptography.RNGCryptoServiceProvider.Create().GetNonZeroBytes(randomBytes);
              _rand = new Random(Environment.TickCount + 1337 + 42 + randomBytes[0]);

              SetUpStrategy();
        }