ovolve
Joined 14 years ago
Joined 14 years ago
Check out the eval function, and specifically the function smoothness() in grid.js. It implements the edge weighting you describe!
The basic idea is minimax search. Googling that will get you started, but basically the algorithm plays out the game and keeps a score of the position after every move. Then it just makes the move that leads to the best score.
The "score" here is basically a count of how many free squares there are (with a little extra to keep things aligned if possible).
One major thing with these search algorithms is that the game tree grows exponentially as you move forward. To combat that, implemented alpha-beta pruning and a heuristic to only search the nastier computer moves rather than all of the possibilities.
BTW, congrats on the whole thing; what a ride. I remember staying up all night implementing the AI after seeing it here, and the rush of seeing it win the first time, plus the added rush of seeing the AI post right next to the original post on here. Thanks for the fun!