Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:52:50+00:00 2026-06-15T23:52:50+00:00

I made a tic tac toe A.I. Given each board state, my A.I. will

  • 0

I made a tic tac toe A.I. Given each board state, my A.I. will return 1 exact place to move.
I also made a function that loops though all possible plays made with the A.I.

So it’s a recursive function that lets the A.I. make a move for a given board, then lets the other play make all possible moves and calls the recursive function in it self with a new board for each possible move.

I do this for when the A.I goes first, and when the other one goes first… and add these together. I end up with 418 possible wins and 115 possible ties, and 0 possible loses.

But now my problem is, how do I maximize the amount of wins? I need to compare this statistic to something, but I can’t figure out what to compare it to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:52:51+00:00Added an answer on June 15, 2026 at 11:52 pm

    You should start by observing that move 9 is always forced: there is only one empty square on the board. Move can be considered 8 forced as well, because after seven moves there could be exactly three situations:

    • O can win on the next move, in which case it takes the win
    • Placing an X in either one of the two remaining squares wins the game for X, in which case O has lost regardless of its next move
    • X has zero or one path to victory, in which case O blocks to force a draw

    This means that the game is over after at most seven moves.

    Also observe that there are only three opening moves: the center, a corner, or a side. It does not matter which of the four corners or sides you take, because the board can be rotated to match a “canonical” opening (the upper-left corner or the middle of the top side).

    You can now build your state analysis code. Starting with each of the three possible openings, search with backtracking up to six additional moves using all squares that are open by the time you make the move. After each move, analyze the position to see if X or O has already won; mark wins by X as Wx, and wins by O as Wo. The remaining positions are undecided.

    Do not explore positions after Wx or Wo: simply return to the prior step, reporting the win by the corresponding side.

    When you reach the seventh move, statically analyze the position to decide if it is one of the three situations described above is applicable, marking the position a Wx, Wo, or a Draw.

    Now to the most important step: when you backtrack to the move N-1 by the player p,

    • If one of the moves that you try is such that all position at the next level becomes Wp, declare the current position a Wp as well.
    • If all of the moves that you try lead to the win of the opponent, declare the current position a win for the opponent
    • Otherwise, declare the current position a Draw, and return to the prior level.

    If you do this right, all three opening positions will be classified as a Draw. You should see some forcible wins after three moves.

    Running this procedure classifies each position as a Wx, Wo, or a Draw. If your AI gets you a win for the player p in a position classified as Wp, or gets you a draw in a position classified as a Draw, then your AI is perfect. If, on the other hand, there are positions that are statically classified as Wp in which the AI gets p only a draw, then your AI engine needs an improvement.


    Additional reading: you can find additional insights into the game in this article describing methods of counting possible games of Tic-Tac-Toe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a tic tac toe A.I. Given each board state, my A.I. will
I'm trying to create a simple tic tac toe board made by 9x9 JButtons.
I made a tic-tac-toe game in c++ want to learn how to use SDL
I'm creating a Tic tac toe game, in that after click made by user
I'm generating a Tic-Tac-Toe game tree (9 seconds after the first move), and I'm
I have a tic tac toe game I made, I am not done yet,
I have made a simple tic tac toe app for Android which needs no
So I was working on a Tic-Tac-Toe game and for my input function I
My daughters have made a game not unlike tic-tac-toe. Of course as I played
I have made a Tic-Tac-Toe game for 2 players. Now, I want to give

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.