Jump to content
  • Advertisement
foody1200

R&D Writing a 6 by 6 grid version of tic tac toe AI

Recommended Posts

   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!

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites
Posted (edited)

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.

 

 

Edited by Mauricio Pastana

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!