Generate a list of all unique Tic Tac Toe boards

前端 未结 7 2074

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 su

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 09:38

    There are 9 positions and an alphabet with 3 letters (X, O, empty). Total number of possible combinations is 3^9 = 19683.

    for(int i = 0; i < 19683; ++i)
    {
        int c = i;
        for (int j = 0; j < 9; ++j)
        {
            cout << (c % 3) << " ";
            c /= 3;
        }
    
        cout << endl;
    }
    

提交回复
热议问题