Exemple #1
0
 private MyShipPosition GetNewShip(List <MyShipPosition> positionsSoFar, int length)
 {
     while (true)
     {
         Square         startSquare = Square.randomSquare();
         bool           horizontal  = r.Next(2) == 1;
         MyShipPosition shipAttempt;
         if (horizontal)
         {
             shipAttempt =
                 new MyShipPosition(
                     startSquare.x,
                     startSquare.y,
                     startSquare.x,
                     startSquare.y + length - 1);
         }
         else
         {
             shipAttempt =
                 new MyShipPosition(
                     startSquare.x,
                     startSquare.y,
                     startSquare.x + length - 1,
                     startSquare.y);
         }
         if (isLegal(shipAttempt, positionsSoFar))
         {
             return(shipAttempt);
         }
     }
 }