function Util() {}
 
 
Util.shuffle = function(array) {
    if (!Array.isArray(array)) {
        throw new UtilException("Аргумент не массив.");
    }
    array.sort(function() {
        return Math.random() - 0.5;
    });
    return array;
};
 
function Cell(x, y) {
    if (typeof x != "number" || y != "number") {
        throw new CellException("Аргументы не являются числами.");
    }
    this.x = x;
    this.y = y;
    this.nearMines = null;
    this.isMine    = null;
}
 
MinesweeperGame.prototype._createMines = function(firstClickedCell) {
    if (this._minesNumber > this._field.length) {
        throw new MinesweeperGameException("Мины > клетки.");
    }
    if (!(firstClickedCell instanceof Cell)) {
        throw new MinesweeperGameException("Аргумент firstClickedCell не Cell.");
    }
    var fieldCopy = this._field.slice();
    fieldCopy     = Util.shuffle(fieldCopy);
    for (var i = 0, counter = 0; i < fieldCopy.length; i++) {
        if (counter == this._minesNumber) {
            break;
        } else if (fieldCopy.x == firstClickedCell.x &&
                   fieldCopy.y == firstClickedCell.y) {
            continue;
        }
        fieldCopy.isMine = true;
        counter++;
    }
    if (counter != this._minesNumber) {
        throw new MinesweeperGameException("В создании мин что-то пошло не так..");
    }
};