there is no AI. yet. you can simulate the way of thinking human person, but you cant force the game think instead of you. and in the javasccript all you should use : functions, loops, variables, arrays strings. the computer shoudl check the game in one point of wiev, and calculate the best step. for example sort each solution descending by one propertyand add increase the rate of the first ten item. and then sort by other and rate again, and couple of these momentss the higest rated step will be the best.
other way to create a win strategy but this is even hard to a human not event to implement into js.
it will be better if i tell you an example
everybody know the XOX game
there is a 3x3 table and you should put 3 X or O in a row to win
_|_|_
_|_|_
| |
this is the map
and this is one way of win
x|o|_
_|x|o
|o|x
i think you remember now.
so what the AI at the server stands for.
when an user puts an X or O (now the user is X the server is O) the server has to calculate how desperathe his situation
is there 2 X in a row? if yes the machine must PUT an O into the midle or at the end of the 2 X.
if there is no 2 X in a row, the machine must calculate there is a trick somewhere?
for example
_|x|_
_|_|x
o| |
this is a trick because the computer must take the O to the top left corner or the machine will loose.
all of these are questions (if-else statements) what humans ask during the play.
if you want to implement you should realy force yourself to record your thinking.
what i first search for? hmmm.first i put the X to the middle because this has got a lot of possibility.
the most important to create an AI you should simulate your way of thinking. good luck.