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

  • Home
  • SEARCH
  • 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 6582249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:15:25+00:00 2026-05-25T16:15:25+00:00

I would like to generate a text file containing all 19,683 Tic-Tac-Toe board layouts

  • 0

I would like to generate a text file containing all 19,683 Tic-Tac-Toe board layouts in the structure of 0 = Blank, 1 = X, and 2 = O. Unfortunately math is not my strong suit and I cannot seem to find any examples of this anywhere.

This isn’t for homework I assure you. I intend to run this data through a Minimax calculator in order to generate an image that contains RGB values representing the optimal move based on the board setup. I am developing Tic-Tac-Toe for a platform that does not support functions (it’s event-driven) so I will convert the board to a number in my game and then lookup the RGB of a pixel in an image which indicates what the best move is. It’s a cheeky workaround, but one that requires no more RAM than an 145×145 pixel image (145×145 = 21,025 so each pixel represents the recommended move based on the board effectively). This also means I won’t have to chew CPU time which is another plus.

  • 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-25T16:15:26+00:00Added an answer on May 25, 2026 at 4:15 pm

    Since you want board layouts, there’s only a small number of them (19683).

    You can just brute-force generate all of these. Each box only has 3 possibilities. And there are 9 boxes, just run through all of them.

    EDIT:

    int c = 0;
    while (c < 262144){
        bool valid = (c & 3) < 3;
        valid &= ((c >>  2) & 3) < 3;
        valid &= ((c >>  4) & 3) < 3;
        valid &= ((c >>  6) & 3) < 3;
        valid &= ((c >>  8) & 3) < 3;
        valid &= ((c >> 10) & 3) < 3;
        valid &= ((c >> 12) & 3) < 3;
        valid &= ((c >> 14) & 3) < 3;
        valid &= ((c >> 16) & 3) < 3;
    
        if (valid){
            int i = c;
            int j = 0;
            while (j < 9){
                cout << (i & 3) << " ";
                i >>= 2;
                j++;
            }
            cout << endl;
        }
    
        c++;
    }
    

    This will print out all 19,683 board layouts. I’m not sure what format you want, but it should be fairly easy to extract that from the output.

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

Sidebar

Related Questions

First I would like to generate a directory listing for all text files in
I would like to know how I could generate code from a text file
i would like to generate a very simple report with some images and text
I would like to generate a patch with all commits from a local branch.
I have a fairly large text file that I would like to convert into
I am trying to generate a plain text file containing a list of words
i have a javascript file with the following content and would like to generate
With a simple bash script I generate a text file with many lines like
I would like to generate a random text using letter frequencies from a book
I would like to generate a Tab Delimited file from excel (using a formula

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.