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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:29:31+00:00 2026-05-14T19:29:31+00:00

I’m generating a Tic-Tac-Toe game tree (9 seconds after the first move), and I’m

  • 0

I’m generating a Tic-Tac-Toe game tree (9 seconds after the first move), and I’m told it should take only a few milliseconds. So I’m trying to optimize it, I ran it through CodeAnalyst and these are the top 5 calls being made (I used bitsets to represent the Tic-Tac-Toe board):

std::_Iterator_base::_Orphan_me

std::bitset<9>::test

std::_Iterator_base::_Adopt

std::bitset<9>::reference::operator bool

std::_Iterator_base::~_Iterator_base

void BuildTreeToDepth(Node &nNode, const int& nextPlayer, int depth)
{
   if (depth > 0)
   {
      //Calculate gameboard states
      int evalBoard = nNode.m_board.CalculateBoardState();
      bool isFinished = nNode.m_board.isFinished();
      if (isFinished || (nNode.m_board.isWinner() > 0))
      {
         nNode.m_winCount = evalBoard;
      }
      else
      {
         Ticboard tBoard = nNode.m_board;
         do
         {
            int validMove = tBoard.FirstValidMove();
            if (validMove != -1)
            {
               Node f;
               Ticboard tempBoard = nNode.m_board;
               tempBoard.Move(validMove, nextPlayer);
               tBoard.Move(validMove, nextPlayer);
               f.m_board = tempBoard;
               f.m_winCount = 0;
               f.m_Move = validMove;
               int currPlay = (nextPlayer == 1 ? 2 : 1);
               BuildTreeToDepth(f,currPlay, depth - 1);
               nNode.m_winCount += f.m_board.CalculateBoardState();
               nNode.m_branches.push_back(f);
            }
            else
            {
               break;
            }
         }while(true);
      }
   }
}

Where should I be looking to optimize it? How should I optimize these 5 calls (I don’t recognize them=.

  • 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-14T19:29:31+00:00Added an answer on May 14, 2026 at 7:29 pm

    The tic-tac-toe game tree is very redundant. Eliminating rotated and mirrored boards will reduce the final ply of the game tree by 3 or 4 orders of magnitude. No amount of optimizations will make bubblesort as fast as introsort.

    struct Game_board;
    
    struct Node
    {
       Game_board game_board;
       Node* parent;
       std::vector<Node*> children;
       enum { X_Win, Y_Win, Draw, Playing } outcome;
    };
    
    // returns the same hash value for all "identical" boards.
    // ie boards that can be rotated or mirrored to look the
    // same will have the same hash value
    int hash( const Game_board& game_board );
    
    // uses hash() function to generate hashes from Node*
    struct Hash_functor;
    
    // nodes yet to be explored.
    std::hash_set<Node*,Hash_functor> open;
    
    //nodes already explored.
    std::hash_set<Node*,Hash_functor> closed;
    
    while( ! open.empty() )
    {
       Node* node_to_expore = get_a_node( open );
       assert( node_to_expore not in close or open sets )
       if( node_to_expore is win lose or draw )
       {
          Mark node as win lose or draw
          add node to closed set
       }
       loop through all children of node_to_expore
       {
          if( child in close )
          {
             add node from closed set to children list of node_to_expore
          }
          else if( child in open )
          {
             add node from open set to children list of node_to_explore
          }
          else
          {
             add child to open set
             add child to children list of node_to_expore
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.