function checkWin(col, row) {
ply = ply == 0 ? 1 : 0
var connected = 1
var connected1 = 1
var curCol = col
var type = board[index(col,row)].type
var connArr = new Array()
connArr.push(board[index(col,row)])
var ind;
// go left
for(var i = col-1; i>=0; i--) {
ind = index(i,row)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
// console.log(board.toString());
connected++;
connected1++;
}
for(var i = col+1; i<=7; i++) {
ind = index(i,row)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
connected++;
connected1++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
connected = 1
}
// go up
for(var i = row-1; i>=0; i--) {
ind = index(col,i)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
connected++;
connected1++;
}
for(var i = row+1; i<=6; i++) {
ind = index(col,i)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push( board[ind])
connected++;
connected1++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
}
// go left-up
for(var i = 1; col-i>=0 && row-i>=0; i++) {
ind = index(col-i,row-i)
if(board[index(col-i,row-i)]==null) break;
if(board[index(col-i,row-i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var i = 1; col+i<=5 && row+i<=5; i++) {
ind = index(col+i,row+i)
if(board[index(col+i,row+i)]==null) break;
if(board[index(col+i,row+i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
}
// go right-up
for(var i = 1; col+i<=6 && row-i>=0; i++) {
ind = index(col+i,row-i)
if(board[index(col+i,row-i)]==null) break;
if(board[index(col+i,row-i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var i = 1; col-i>=0 && row+i<=5; i++) {
ind = index(col-i,row+i)
if(board[index(col-i,row+i)]==null) break;
if(board[index(col-i,row+i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var u=0;u<=42;u++)
{
if(connArr.length==4 && ply==0)
{
connArr[u].state="red"
mainMenu.opacity=0;
playAgain.opacity=1;
help.opacity=0;
quit.opacity=1;
gameFinished1();
scoreBoard.scorer();
}
else if(connArr.length==4 && ply!=0)
{
connArr[u].state="black"
mainMenu.opacity=0;
playAgain.opacity=1;
help.opacity=0;
quit.opacity=1;
gameFinished();
scoreBoard.scoreb();
}
}
function checkWin(col, row) {
ply = ply == 0 ? 1 : 0
var connected = 1
var connected1 = 1
var curCol = col
var type = board[index(col,row)].type
var connArr = new Array()
connArr.push(board[index(col,row)])
var ind;
// go left
for(var i = col-1; i>=0; i--) {
ind = index(i,row)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
// console.log(board.toString());
connected++;
connected1++;
}
for(var i = col+1; i<=7; i++) {
ind = index(i,row)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
connected++;
connected1++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
connected = 1
}
// go up
for(var i = row-1; i>=0; i--) {
ind = index(col,i)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push(board[ind])
connected++;
connected1++;
}
for(var i = row+1; i<=6; i++) {
ind = index(col,i)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArr.push( board[ind])
connected++;
connected1++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
}
// go left-up
for(var i = 1; col-i>=0 && row-i>=0; i++) {
ind = index(col-i,row-i)
if(board[index(col-i,row-i)]==null) break;
if(board[index(col-i,row-i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var i = 1; col+i<=5 && row+i<=5; i++) {
ind = index(col+i,row+i)
if(board[index(col+i,row+i)]==null) break;
if(board[index(col+i,row+i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
if(connected<4) {
connArr = []
connArr.push(board[index(col,row)])
connected = 1
}
// go right-up
for(var i = 1; col+i<=6 && row-i>=0; i++) {
ind = index(col+i,row-i)
if(board[index(col+i,row-i)]==null) break;
if(board[index(col+i,row-i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var i = 1; col-i>=0 && row+i<=5; i++) {
ind = index(col-i,row+i)
if(board[index(col-i,row+i)]==null) break;
if(board[index(col-i,row+i)].type != type)
break;
connArr.push( board[ind])
connected++;
}
for(var u=0;u<=42;u++)
{
if(connArr.length==4 && ply==0)
{
connArr[u].state="red"
mainMenu.opacity=0;
playAgain.opacity=1;
help.opacity=0;
quit.opacity=1;
gameFinished1();
scoreBoard.scorer();
}
else if(connArr.length==4 && ply!=0)
{
connArr[u].state="black"
mainMenu.opacity=0;
playAgain.opacity=1;
help.opacity=0;
quit.opacity=1;
gameFinished();
scoreBoard.scoreb();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks