So I am trying to code an AI for a connect 4 game I made, and I’m using alert boxes as I go to make sure everything is working as it should (as by play testing you cannot tell if most changes are working properly). When you are playing the game the ‘P’ variable will change, but this is all that is needed to create the issue. The alert should produce 7 alerts with scores each time the function is called, this happens the first time the function is called, but after that no alert box pops up, and no issues in the console (when using actual game files they pop up but say ‘undefined’, figured it is the same issue). Any ideas why?
var P = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,2,0];
var a = 0;
var c = 0;
var L = 0;
var move = [0, 0, 0, 0, 0, 0, 0];
var loc = [35, 36, 37, 31, 39, 33, 41];
var score = 0;
function error(){
while( a < 7){
var c = 0;
L = loc[a] + 7;
while( c < 3){
if(L > 34){
c = 4;
}
if(P[L] == 2){
score = score + 1;
}
c = c + 1;
L = L + 7;
}
move[a] = score;
alert(move[a]);
score = 0;
a = a + 1;
}
}