As my first game ive decided to attempt TTT, im fairly sure i can do the board, input, etc. The parts that baffle me are the AI and Checking for a win.
I pondered to check for a win via a 'if a O is found look for an adjacent one' but a:
Arrangement would confuse it, bearing in mind ill be using an array for the board, can someone point me in the right direction with the AI and Checking for a win ?
Any help appreciated
The easiest way to check for a win is to just hard code all the possible ways to win. It's infallible. Have the array hold whether the space is occupied and by whom. On my tic-tac-toe game I made two bool arrays in two dimentions, like this:
The 9 is for the number of pieces and the two is for the things above. Checking it is simple then. This is just how I made my game, there are many ways that will work just as good/better.
As for AI, I hardcoded a functions to check if the computer or the user could win on that turn. If so, win or block the user. Also, I made the computer take the center if it was open because that presents the most options for winning, but some people think it's not always the best idea. Then I made some pretty rough coded functions to see what space would be the best to take. They weren't very great, so I won't post them. That part of making the AI has to be the hardest, because it involves some higher level "thinking", vs. just blocking spaces. I hope this helps you. Good luck!
cheers, ill give it a try.