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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:50:21+00:00 2026-05-18T01:50:21+00:00

I am designing my implementation strategy for Tic-Tac-Toe game. Since this is my 1st

  • 0

I am designing my implementation strategy for Tic-Tac-Toe game. Since this is my 1st game implementation, I am a bit confused and need some general pointers.

Now, the total number of winning combinations in a Tic-Tac-Toe are 8. Currently, I plan to store these winning combinations in an array. Once the end user has made at least 3 moves, I would start checking if the Player has won the game by comparing the current positions used by a Player against this array. However, I am sure this is not an efficient way to check if the player has a winning combination.

Can anyone please suggest me on how to go about with design the logic for the game?

  • 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-18T01:50:22+00:00Added an answer on May 18, 2026 at 1:50 am

    Don’t worry about efficiency. I wrote a backtracking solution and there are only 549,945 possible game states. It takes less than 0.25 seconds to run through these on my laptop. Here was my logic to see if the game was over – clearly not very efficient, but it doesn’t matter:

    private boolean isWinningMove(int row, int col) {
        int piece = board[row][col];
    
        // check current row
        boolean w = true;
        for (int x = 0; x < 3; x++) { w = w && (board[row][x] == piece); }
        if (w) { return true; }
    
        // check current column
        w = true;
        for (int x = 0; x < 3; x++) { w = w && (board[x][col] == piece); }
        if (w) { return true; }
    
        // check 0,0 diagonal
        w = true;
        for (int x = 0; x < 3; x++) { w = w && (board[x][x] == piece); }
        if (w) { return true; }
    
        // check 0,2 diagonal
        w = true;
        for (int x = 0; x < 3; x++) { w = w && (board[x][2 - x] == piece); }
        return w;
    }
    

    Here were my results, which match data on the Wikipedia page for tic-tac-toe:

    Moves Simulated: 549945
    Draws=46080   Player1-Wins=131184   Player2-Wins=77904
    Perfect Strategy Implies: Always a tie.
    
    Games won in 0 moves? 0
    Games won in 1 moves? 0
    Games won in 2 moves? 0
    Games won in 3 moves? 0
    Games won in 4 moves? 0
    Games won in 5 moves? 1440
    Games won in 6 moves? 5328
    Games won in 7 moves? 47952
    Games won in 8 moves? 72576
    Games won in 9 moves? 81792
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a game engine in Java. At the core of this engine
I am designing a WCF service with callback, but my implementation of the callback
Im designing a website, and often I need to present information in a nice
I'm in the process of designing several classes that need to support operators !=
I am designing a Data Information Interface Layer. I want the users of this
I'm currently designing a list widget to add to my widget engine. Since every
I am designing a application where many clients connect to a central server. This
I'm loading images with this class. I need help on how to stop them
I'm having a bit of trouble designing the user login/logout mechanism of my website
I've been designing a card game in Java on Windows. It runs really well

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.