conditions

This commit is contained in:
gnieark 2016-06-07 22:06:23 +02:00
parent eb1174066b
commit fca8ca780d

View File

@ -125,10 +125,7 @@ function playingAT(col){
return; return;
} }
//diagonals //diagonal \
//\
//for (var kx=x, var ky=y; kx < 7, ky
/* /*
5|X| | | | | | 5|X| | | | | |
4| |X| | | | | 4| |X| | | | |
@ -136,21 +133,65 @@ function playingAT(col){
2| | | |X| | | 2| | | |X| | |
1| | | | |X| | 1| | | | |X| |
0|1|2|3|4|5|X| 0|1|2|3|4|5|X|
y=ax+b
1 = a *5 + b diagonal is an affin function:
5 = a * 1 +b y=-x+b
b = 1 - 5a
5= a + 1 - 5a
5 = -4a + 1
-4a = 4
a = -1
b = 6
ky=akx+b
*/ */
//find b
var b= y + x;
if (b < 6){
//first point of the diagonal has x=0;
var kx = 0;
var ky = b; //:aga:
}else{
//first point of the diagonal has y=5
var kx = b - 5;
var ky = 5;
}
var line="";
for (var lx = kx, var ly = ky; (lx < 7) && (ly > -1); lx++, ly--;){
if( grid[ly][lx] == ""){
line += " ";
}else{
line += grid[ly][lx];
}
}
if (line.indexOf(searchValue) > -1){
wins(currentPlayer);
return;
}
//diagonal / affin function like y=x+b
b = y - x;
if( b > -1){
//first point has x=0
kx = 0;
ky = b
}else{
//first point has y=0
ky = 0;
kx = -b;
}
var line="";
for (var lx = kx, var ly = ky; (lx < 7) && (ly < 6); lx++, ly++;){
if( grid[ly][lx] == ""){
line += " ";
}else{
line += grid[ly][lx];
}
}
if (line.indexOf(searchValue) > -1){
wins(currentPlayer);
return;
}
//change player //change player
if(currentPlayer == 1){ if(currentPlayer == 1){
play(2); play(2);