Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

TicTacToe minimax algorithm bug

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I made a TicTacToe game with an AI using minimax alrgorithm, but I seem to have misunderstood something and sometimes it doesn't choose the best move, so if someone knows where I made a mistake, help would be appreciated.



These are the two important methods that show how ai makes decisions.
It does well in most of the times, but sometimes there are chances of actually defeating it and that should not be possible.
I appreciate the help. Thank you!
 
Marshal
Posts: 15629
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might help people understand your intent by explaining what you mean by "minimax algorithm". Then they'll have a basis for analyzing your code to see what might be out of alignment with that algorithm.
 
Jebiga StaMozed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that is exactly the problem. I think that I might have misunderstood something about the algorithm and am looking for somebody who has already worked with that algorithm to tell me what i see wrong.
 
Junilu Lacar
Marshal
Posts: 15629
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And my point is that not everyone who looks at this thread will know offhand what that algorithm is. Giving people a link to more details about it or giving a short description of what it's supposed to do would be helpful and increase your chances of getting help. It would be the courteous thing to do.
 
Jebiga StaMozed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:And my point is that not everyone who looks at this thread will know offhand what that algorithm is. Giving people a link to more details about it or giving a short description of what it's supposed to do would be helpful and increase your chances of getting help. It would be the courteous thing to do.



Alright, here is a link explaining it: https://www.freecodecamp.org/news/how-to-make-your-tic-tac-toe-game-unbeatable-by-using-the-minimax-algorithm-9d690bad4b37/
 
Junilu Lacar
Marshal
Posts: 15629
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link, that is very helpful.

This minimax algorithm basically constructs what's called a game tree and is supposed to pick the branch that will lead to the best outcome. Unfortunately, the code you shared is difficult to follow and, frankly, quite a mess.

At this point, it might be helpful if you gave an example of where your code fails to find the optimal set of moves to play. The failure could come at any time so it will be most helpful to see it go through an entire game so it's easier to see the point where it goes wrong.
 
Paper beats rock. Scissors beats tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic