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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:05+00:00 2026-05-26T15:26:05+00:00

Hi I am a beginner and I am making a console tic tac toe

  • 0

Hi I am a beginner and I am making a console tic tac toe c++ before I try to get it done in unity3d but that’s another story, I got stuck on the get_move1() function, as far as how can I check if the array has a 1 or a -1 if it does then is full and the function should say in an invalid move, can this be done any other way besides 2d array, my program just hangs with no error, I haven’t work on the other functions yet so they are just empty for now. Thanks for your help.

*init_board and board_state array
get_move function to determine if the move is legal if it is then
fill board_state array and show X or O on the board with another array
check_win
*/

/* layout of board
cout <<  "   1 | 2 | 3  \n"
         "     |   |    \n"
       "  - - - - - -   \n"
         "   4 | 5 | 6  \n"
         "     |   |    \n"
       "  - - - - - -   \n"
         "   7 | 8 | 9  \n"
         "     |   |    \n" << endl;

 cout << "   " <<board_array[0] <<" | " <<  board_array[1] << " | " << board_array[2] <<    "\n"
         "     |   |    \n"
       "  - - - - - -   \n"
         "   " <<board_array[3] <<" | " <<  board_array[4] << " | " << board_array[5] <<    "\n"
         "     |   |    \n"
       "  - - - - - -   \n"
         "   " <<board_array[6] <<" | " <<  board_array[7] << " | " << board_array[8] <<    "\n"
         "     |   |    \n" << endl;

         */

#include <iostream>

using namespace std;

//declare global variables

int board_state[3][3] = { {0,0,0},  //here the 2d array is initialized and set to 0 for empty
                          {0,1,0},
                          {0,0,0} };

char gui_state[3][3];               //2d array to represent the X and O on the board




//declare functions

void init_board();
void get_move1();



int main()
{
    init_board();
        get_move1();
}

void init_board()
{
    cout << "   1 | 2 | 3 \n"
            "     |   |   \n"
            "  - - - - - -  \n"
            "   4 | 5 | 6 \n"
            "     |   |   \n"
            "  - - - - - -  \n"
            "   7 | 8 | 9 \n"
            "     |   |   \n"
            " **Tic Tac Toe ** " << endl;
}

void get_move1() // In this function player's moves are taken and make sure they are valid if so update arrays
{
    int player1_move;
    int i;
    int j;
    bool invalid_move;


    cout << "Player 1 enter move" << endl;
    cin >> player1_move;

    //need to check if the players's move is valid

    for (i=0; i < 3; i++)          //if array is 1 or -1 then move is invalid
    {
        for(j = 0; j < 3; i++)
            if (board_state[i][j] == 1 || board_state[i][j] == -1)
            {
                invalid_move = true;
            }


    } cout << "You entered an invalid move" << endl;

}

void get_move2()
{

}

void game_state()
{

}

void check_win()
{

}

so I decided to go for a one dimensional array to keep it simple for now

int board_state[9] = {0,1,0,0,0,0,0,0,0};  //here the 1d array is initialized and set to 0 for empty

void get_move1() // In this function player's moves are taken and make sure they are valid if so update arrays
{
    int player1_move;
    int array_index;
    int player1_fill = 1;


    cout << "Player 1 enter move" << endl;
    cin >> player1_move;

    //need to check if the players's move is valid

    array_index = player1_move -1;

    if (board_state[array_index] == 1 || board_state[array_index] == -1)
    {
        cout << "Invalid move" << endl;
    }

    else board_state[array_index] = player1_fill;

Thanks for the help guys.

  • 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-26T15:26:06+00:00Added an answer on May 26, 2026 at 3:26 pm

    This line:

    for(j = 0; j < 3; i++)
    

    should be:

    for(j = 0; j < 3; j++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in C# , and making a calculator . But i
I understand that the title might not be descriptive enough, but I'm making a
i am a beginner in making website, i learned things at msdn only, but
I'm a beginner and there's something that's not making much sense to me. Please
I'm probably making a stupid beginner mistake here but SQL isn't one of my
Can anybody point me to a good beginner's guide for making Facebook apps?
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Absolute beginner question: I have a template file index.html that looks like this: ...
I'm not a beginner at C# but I really need to increase my understanding,
Beginner question. I'm making a simple Gtk notepad in C# and MonoDevelop and everything

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.