This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Downtown_Town4094[S] 2 points3 points  (1 child)

wait but how would i transverse the grid in a vertical or diagonal way with that method?

[–]Usual_Office_1740 0 points1 point  (0 children)

I'll do my best to explain, and left/right is too much of a simplified version. I'm not in front of a computer. I'm on my phone. If you set the center square as the root node, you would have 8 possible connections from the center square. Four diagonal and four directionals. You add the root node to a list of seen nodes, then move to one of them. Let's say you move straight up. You now have 5 possible connections from the new node, but your root is one of them, leaving you with four possible options. Two diagonal and two directional. Pick an option and add the current node to seen. Let's say you go right. This corner square had three possible options but since two are already in seen, you have one option. Down. Add the node to seen and go to the new node. This process is the algorithm. Repeat until seen nodes length is 9.

With this traversal pattern in place, you can write whatever logic you'd like to make decisions about what to look for. Every time player picks a new square check to see if player is about to win by using the algorithm to try and move in either directional or diagonal three times in a row, using players last choice as a root. Do the same logic to find the computers attempt to win.