is there a better fuction then check4winner() for my tictactoe board

Posted by Hespino on Stack Overflow See other posts from Stack Overflow or by Hespino
Published on 2012-10-04T01:08:05Z Indexed on 2012/10/04 3:37 UTC
Read the original article Hit count: 81

Filed under:
function check4Winner(){    
    winningCombinations = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]];     
    for(var a = 0; a < winningCombinations.length; a++){
        if(squares[winningCombinations[a][0]]==currentPlayer&&
           squares[winningCombinations[a][1]]==currentPlayer&&
           squares[winningCombinations[a][2]]==currentPlayer){
             winner=true;
             alert(currentPlayer+ " WON!");              
        }           
    }//forloop  
}//end check4Winner().

© Stack Overflow or respective owner

Related posts about JavaScript