...
<script src="js/jquery-2.1.3.js">
</script>
<script type="text/javascript" src="js/lib.js"></script>
...
<script>
if(begin(x,y) == true){
$(this).toggleClass('selected');
}
<script>
function begin(x,y){
/*** Проверка соседних ячеек к угловым ***/
if(x == 0 && y == 0) {
if(cell[1][0] == "ship" && cell[0][1] == "ship" && cell[1][1] == "ship"){
return false;
}
else {
return true;
}
}
...
}