public void PlaceShips(IPlayerView playerView, ICollection<IVessel> ships) { InitializeAI(playerView); int x, y; Orientation orient; #if DEBUG Visualizer viz = new Visualizer(_xMax, _yMax); #endif foreach (IVessel ship in ships) { do { x = _rand.Next(0, _xMax) + 1; y = _rand.Next(0, _yMax) + 1; orient = (_rand.NextDouble() < 0.5) ? Orientation.Horizontal : Orientation.Vertical; } while (!playerView.PutShip(ship.SailTo(x, y, orient))); #if DEBUG for (int i = 0; i < ship.Length; i++) { if (orient == Orientation.Horizontal) viz.SetSquare(x + i, y, false); else viz.SetSquare(x, y - i, false); } #endif } #if DEBUG Console.WriteLine("Ships:"); Console.WriteLine(viz.FieldView()); #endif }
public static void ConsolePrintField(int xMax, int yMax, List<Coordinate> coordinates) { Visualizer viz = new Visualizer(xMax, yMax); foreach (Coordinate coord in coordinates) { viz.SetSquare(coord.X, coord.Y, true); } Console.WriteLine(viz.FieldView()); Console.WriteLine(); }