Condition

I'm writing a TicTacToe exercise, And i've narrowed it down to a condition that alway's read's false. I think the problem is in line 66.



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <array>

int Carr[9] = {3,3,3,3,3,3,3,3,3};
int ArrPos = 0;
int MoveNotLegal =1;
char LetInp;
char &LetRef = LetInp;
int LetConvRef = LetRef;
int Xcoord = 0;
int Ycoord = 0;


int RedrawBoard() // 1 = Plyr 1; 2 = Plyr 2; 3 = Blank
{
    int Column = 1;
    std::cout << std::endl;
    std::cout << "  A B C\n\n" << Column;
    int LineCount = 1;
        for (int y = 0; y <= 8; ++y, ++LineCount)
        {
            if (Carr[y] == 1)
            {
                std::cout << " X";
            }
            if (Carr[y] == 2)
                {
                     std::cout << " O";
                }
            if (Carr[y] == 3)
            {
                std::cout << " *";
            }
            if (LineCount == 3 && Column != 3)
            {

                LineCount = 0;
                std::cout << '\n';
                ++Column;
                std::cout << Column;
            }
        }
    return 0;
};

void resetBoard()
{
    for (int i = 0; i <= 8; ++i)
        Carr[i] = 3;
};

int GetPlayerMove(int Plyr)
{
    MoveNotLegal = 1;
    do
    {
            char LetInp;
            int Ycoord = 0;
            std::cout << "\nPlayer " << Plyr << " Enter column from (A - C): ";
            std::cin >> LetInp;
            std::cout << "\nPlayer " << Plyr << " Enter row from (1-3): ";
            std::cin >> Ycoord;
            --Ycoord;
            Xcoord = LetConvRef - 97;
            ArrPos = (3 * Xcoord) + Ycoord;
            if (Carr[ArrPos] == 3)
            {
                Carr[ArrPos] = Plyr;
                MoveNotLegal = 0;
            }
    }
    while (MoveNotLegal != 1);
    MoveNotLegal = 1;
    return 0;
}

int main()
{
    int Player =1;
    int GameLive = 1;
    char PlayAgain = 'y';
    RedrawBoard();
    do
    {
        GetPlayerMove(Player);
        ++Player;
        RedrawBoard();
        // Check for win
        if (GameLive == 1)
        {
            GetPlayerMove(Player);
            --Player;
            RedrawBoard();
            // Check for win
        }

        if (GameLive == 0)
            {
                std::cout << "\nWould you like to play again? (y or n) ";
                std::cin >> PlayAgain;
            }
    }
    while (PlayAgain == 'y' || PlayAgain == 'Y');
}
Last edited on
What is line 66 trying to say? It looks to me like you meant to say if(ArrPos == 3)
Thank's a bunch booradley60. I was writing several part's of the program at once, Got lost in my own logic :)
Topic archived. No new replies allowed.