| 111 | |
| 112 | } |
| 113 | const checkWinner = (states)=>{ |
| 114 | // check rows |
| 115 | for(let i=0;i<grid_side;i++){ |
| 116 | if(states[i][0] == states[i][1] && states[i][1] == states[i][2] && states[i][0]!=0){ |
| 117 | return states[i][0] |
| 118 | } |
| 119 | if(states[0][i] == states[1][i] && states[1][i] == states[2][i] && states[0][i]!=0){ |
| 120 | return states[0][i] |
| 121 | } |
| 122 | } |
| 123 | if(states[0][0] == states[1][1] && states[1][1] == states[2][2] && states[0][0]!=0){ |
| 124 | return states[0][0] |
| 125 | } |
| 126 | if(states[0][2] == states[1][1] && states[1][1] == states[2][0] && states[0][2]!=0){ |
| 127 | return states[0][2] |
| 128 | } |
| 129 | //check if there is a tie |
| 130 | let isTie = true |
| 131 | for(let i=0;i<grid_side;i++){ |
| 132 | for(let j=0;j<grid_side;j++){ |
| 133 | if(states[i][j]==0){ |
| 134 | isTie = false |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | if(isTie){ return "tie"} |
| 139 | return null |
| 140 | } |
| 141 | return {pickMove} |
| 142 | })() |
| 143 | let gameBoard = (()=>{ |