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 4534480
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:17:10+00:00 2026-05-21T14:17:10+00:00

First off, I am a noob. I am also a Janitor that has never

  • 0

First off, I am a noob. I am also a Janitor that has never made a dime writing code. This is just something that I love doing. It is for fun:) That being said, I wrote this console based tic-tak-toe game that has enough ai to not lose every game. (I guess ai is what it should be called.) It has something like 70 if/else if statements for the computers turn. I used 3 int arrays like so:

int L[2], M[2], R[2];

0 = blank;
1 = X;
2 = O;
The board then ‘Looks’ like
L[0] | M[0] | R[0]
L[1] | M[1] | R[1]
L[2] | M[2] | R[2]

So I basically wrote out every possible scenario I could think something like:

if(M[0]==1 & M[1]==1 & M[2]==0){M[2] = 2;}//here the computer prevents a win 
else if(L[0] ==2&M[1]==2&R[2]==0){R[2]=2;}//here the computer wins
//and so on....68 more times!

I guess my question(s) is(are):
Is there a better way?
Is there a way to achieve the same result with less lines of code?
Is this considered Artificial Intelligence?

  • 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-05-21T14:17:10+00:00Added an answer on May 21, 2026 at 2:17 pm

    The standard algorithm for this is called Minimax. It basically builds a tree, where the beginning of the game is the root, and then the children represent every possible move X can make on the first turn, then the children of each of those nodes are all the moves O can make in response, etc. Once the entire tree is filled (which is possible for Tic-Tac-Toe, but for games like Chess computers still don’t have enough memory), you work your way back up, assuming both players are smart enough to make the best move, and arrive at the optimal move. Here is another explanation of Minimax specifically using Tic Tac Toe as an example.

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

Sidebar

Related Questions

First off, this example will only work in a browser that supports :nth-child ,
first off this is a class assignment so i would appreciate help but just
First off I apologize if there is another post out there that answers this,
First off, apologies if this is a complete noob question which could easily be
First off, I'm using Access 2000 and DAO. I have code that executes a
First off - apologies if this or a similar question has been asked before.
First off... i'm only just coming to jquery, so... if anyone has time to
First off, just wanted to say I'm a novice at this type of coding,
First off, I'm sure this is a simple question. I'm just getting started with
First off, apologies if this question has been asked before but I couldn't find

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.