Advertisement

Writing a 6 by 6 grid version of tic tac toe AI

Started by July 17, 2019 01:25 AM
4 comments, last by Mauricio Pastana 5 years, 3 months ago

   Hello guys,

 

Please forgive me if I look flustered as I am trying to express what is in my mind in words and it may come out a little scrambled. I am writing a special version of tic tac toe to enhance my programming skills, especially in the AI side of things. The grid is 6 by 6. The player must form 5 lines in a row in order to win, same must apply to the opposing team. Right now the game is like 98% complete except when it comes to the AI. I have started writing my very first AI four days ago, I have done lots of bug fixes and debugging and the AI is at it's infancy. Right now it moves randomly and puts it randomly in the board...but it is not a smart AI. It is not smart enough to block my attempt from winning and it is not smart enough to form it's own lines to win and also not tactful enough to form line where it wins even if I attempt to block it in one side. I want to make my AI smart but beatable but at the same time smart enough to beat me. I want the AI to think much like the AI of chess or checker to think when it does it's move.

 

Can someone help me in this please? How do I make an unpredictable AI but smart enough to make the game fun and challenging but not impossible or not too dumb either. I want the computer to take it's time..think of the best move for it to win and also blocks me from winning, but if it had a choice of winning and blocks me, it goes for winning, but also make a strategical move to attempt to win even if I blocked it from one end but also unpredictable. Like I do not want it to do the same moves again and again...

 

Remember this is not an average tic tac toe it is a 6 by 6 so it have 36 grids to move about and you need to form five rows to win. CAN SOMEONE HELP ME ON THIS? 

 

THANKS IN ADVANCE!

The odds of getting 5 of 6 rows are zero to none. Each player has a maximum of 18 plays and can only get 3 rows at most. Most likely no player would ever complete a row.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

I think he means "5 in a row", not "five rows". It's not a tic-tac-toe game, it's a Connect Five game on a 6x6 board.

"Connect 4" is a pretty popular game with this gameplay, just with slightly different parameters, so you should be able to use the same well-established solutions to that game. Google "connect 4 ai", and you'll see quite a few approaches pretty quick.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

5 in a row on a 6x6 board is most likely a draw. It's typically played on a 15x15 or 19x19 board (https://en.wikipedia.org/wiki/Gomoku).

Writing an AI for this game based on a list of rules is possible. So you play a winning move if available; if not, play a move that blocks the opponent from winning, if available; if not; make a move that creates two winning threats; etc.

Of course you can also use alpha-beta search (traditional technique for games like chess and checkers) or MCTS. There is plenty of information online on how to do those things.

 

Maybe I am slightly late, but if you do read this, I recommend taking a look at the minimax algorithm.

https://en.wikipedia.org/wiki/Minimax

Minimax is basically this, you make a decision tree that counts the number of turns and possible plays, he evaluates the best play to win on turn 1(his turn), then the best play to not lose on turn 2 (it would be your turn), and then after those decisions the best play to win t3 and so on. Minimax leads to the almost perfect A.I in board games if you make the tree until the last level, in your case turn 36, it traces every single possible movement. Being realistic for a good A.I, you probably can make him track just 3-4 levels of decisions, you can also randomize from the top 3 decisions and so on to make it more natural. I have used for card games, tracking 2-3 turns only and it really works wonders in being competitive enough and not un-human.

 

 

This topic is closed to new replies.

Advertisement