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

The Archive Base Latest Questions

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

I wrote a program to determine the game tree for tic-tac-toe. I believe most

  • 0

I wrote a program to determine the game tree for tic-tac-toe.
I believe most of the code is in good order.
I wrote a function that compares elements of a vector to determine if any elements are duplicates.
Duplicate items can either be truly identical or they can be symmetrical.
Duplicate elements are deleted from the vector.
My compare function appears to have a problem where it incorrectly eliminates elements.
Please take a look at how I iterate through the vector and see if the syntax/logic seems reasonable.

My guess is that using < > operators may be part of the problem.
The basic logic of the function is to compare the first element with the last element, then the next to last element and so on. After comparing the first element with all elements you start again comparing the second element to the other elements and so on…

void compareAllGames(move& aMove) { /* aMove is a vector of games. games are a struct of data */
    vector<game>:: iterator frontIter = aMove.begin();
    vector<game>:: iterator rearIter = aMove.end() - 1;
    vector<game>:: iterator compIter;
    for (; frontIter < rearIter; frontIter++) { /* move along the games from first to last */
        for (compIter = aMove.end(); compIter > frontIter; ) { /* move along the games from last to first */
            /* checkForSymmetry compares *frontIter to all symmetries of *compIter */
            if (checkForSymmetry(*frontIter, *compIter)) {
                compIter--;
                aMove.erase(compIter + 1);
            }
            else {
                compIter--;
            }
        } /* reset iterators for next loop */
        compIter = aMove.end();
        rearIter = aMove.end();
    }
}
  • 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-21T05:17:07+00:00Added an answer on May 21, 2026 at 5:17 am

    Thanks for all the comments. In the end I simplified my function that had the two confusing loops and determined that instead of adding all games to a move and then check for duplicates/symmetry, I could add a single game and compare it to the current list. This has two advantages: simpler coding that is easy to understand and a much lower number of comparisons. It doesn’t hurt that this code actually works too. These changes led me to find a couple of bugs in my symmetry functions.

    Here is the final function that I used:

    bool compareAllGames(move& aMove) {
        vector<game>:: iterator frontIter = aMove.begin();
        vector<game>:: iterator rearIter = aMove.end() - 1;
    
        for (; frontIter != rearIter; ++frontIter) { // move along the games from first to last
            if (checkForSymmetry(*frontIter, aMove.back())) {
                aMove.pop_back();
                return true;
            }
        }
        return false;
    }
    

    Now I just need to add my code back in that accounts for winners and I will have a proper adjusted count for the tic tac toe game tree. The unadjusted count (ignoring winners) by move is: 1, 2, 12, 38, 108, 174, 228, 174, 89, and 23.

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

Sidebar

Related Questions

I wrote a sample program at http://codepad.org/ko8vVCDF that uses a template function. How do
I wrote up a program that can sort words and determine any anagrams. I
I am trying to write a C++ program that works like the game 24.
Just because I've never read binary files before I wrote a program that reads
I wrote a program that worked perfectly until the market required me to add
I wrote a program that runs fine, however packaging the file into a jar
I wrote a program in C with Ubuntu Linux and now I need to
I wrote a program which includes writing and reading from database. When I run
I wrote a program using AutoIT to fetch information from a number of websites
I wrote a program out, which was all in one file, and the methods

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.