Why doesn't this work?

It worked fine when I had each spot it's on string, but when I changed it into an array for other stuff in the code it stopped working. I don't get errors or anything, it just doesn't do what I'm trying to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
std::string Amove[9] =  {" "," "," "," "," "," "," "," "," "};
    srand(time(0));

    while(WindowOpen)
    {
        if(Menu)
        {
            std::cout << "1-9 to mark position, press enter to begin." << std::endl;
            UpdateMove = false;
            while(Menu2)
            {
                if(GetAsyncKeyState(VK_RETURN))
                {
                    Menu = false;
                    UpdateMove = true;
                    Menu2 = false;
                    Gamestarted = true;
                    if(rand() % 2 == 0)
                    {
                        Player1 = true;
                        secondturn = true;
                        PlayerTurn = true;
                        AiMark =  "X";
                    }
                    if(rand() % 2 == 1)
                    {
                        firstturn = true;
                        Player2 = true;
                        AiTurn = true;
                        AiMark =  "O";
                    }
                }
            }
        }
        while(Gamestarted)
        {
            if(UpdateMove)
            {
                system("cls");
                std::cout << "|" << Amove[0] << "|" << Amove[1] << "|" << Amove[2] << "|\n-------\n|" << Amove[3] << "|" << Amove[4] << "|" << Amove[5] << "|\n-------\n|" << Amove[6] << "|" << Amove[7] << "|" << Amove[8] << "|\n-------" << std::endl;
                std::cout << PlayerTurn;
                UpdateMove = false;
            }

            while(PlayerTurn)
            {
                if(GetAsyncKeyState('1'))
                {
                    if(Player1)
                    {
                        Amove[0] = "O";
                    }
                    if(Player2)
                    {
                        Amove[0] = "X";
                    }
                    UpdateMove = true;
                    PlayerTurn = false;
                }
Last edited on
Change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
                    if(rand() % 2 == 0)
                    {
                        Player1 = true;
                        secondturn = true;
                        PlayerTurn = true;
                        AiMark =  "X";
                    }
                    if(rand() % 2 == 1)
                    {
                        firstturn = true;
                        Player2 = true;
                        AiTurn = true;
                        AiMark =  "O";
                    }
with
1
2
3
4
5
6
7
8
9
10
11
12
13
14
                    if(rand() % 2 == 0)
                    {
                        Player1 = true;
                        secondturn = true;
                        PlayerTurn = true;
                        AiMark =  "X";
                    }
                    else
                    {
                        firstturn = true;
                        Player2 = true;
                        AiTurn = true;
                        AiMark =  "O";
                    }

First has a 50% chance of doing the first if, then a 50% chance of doing the second (25% for both at the same time, 50% for one at the time and 25% for none)
The second one has a 50% chance of doing the first if, and if that doesn't happen it does the second if.
Last edited on
Thanks, but that wasn't really the problem. When I press 1 or any of the other keys I have coded it doesn't put O or X it just does nothing. I probably should have been more clear about what the problem was.
bump
Still no responses? ;/
try to put UpdateMove = true at the beginning of while(GameStarted) to see if types
| | | |
---------
| | | |
, if it doesn't the problem lies before that.

Does it output the
"1-9 to mark position, press enter to begin." part ?
Topic archived. No new replies allowed.