Example #1
0
        public void PlaceShips(System.Collections.ObjectModel.ReadOnlyCollection <Ship> ships)
        {
            BoardView <bool> board = new BoardView <bool>(size);
            var AllOrientations    = new[] {
                ShipOrientation.Horizontal,
                ShipOrientation.Vertical
            };

            foreach (var ship in ships)
            {
                int avoidTouching = 3;
                while (!ship.IsPlaced)
                {
                    var l = rand.Pick(board.Select(c => c.Location));
                    var o = rand.Pick(AllOrientations);
                    if (ship.IsLegal(ships, size, l, o))
                    {
                        if (ship.IsTouching(ships, l, o) && --avoidTouching > 0)
                        {
                            continue;
                        }
                        ship.Place(l, o);
                    }
                }
            }
        }
        public BoardView <U> Transform <U>(Func <T, U> transform)
        {
            var result = new BoardView <U>(new Size(Columns, Rows));

            for (int y = 0; y < Rows; y++)
            {
                for (int x = 0; x < Columns; x++)
                {
                    result[x, y] = transform(this[x, y]);
                }
            }
            return(result);
        }
 public Cell(BoardView <T> view, int x, int y)
 {
     this.view = view; this.X = x; this.Y = y; this.Bias = 1.0;
 }
Example #4
0
 public void NewGame(System.Drawing.Size size, TimeSpan timeSpan)
 {
     this.size           = size;
     this.opponentsBoard = new BoardView <OpponentsBoardState>(size);
     this.gridOddEven    = rand.Pick(new[] { 0, 1 });
 }