tic-tac-toe trouble!

tic-tac-toe trouble! I was really hesitant on posting this wall of code, but i think that you need to be able to see the big picture.how do I get it so that the everytime the playcom() function is called, the plyrchoice becomes 5? It seems as if I've tried everything. (playing with two humans works fine)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  // a game by ASCII14
#include <iostream>
#include <string>
#include <stdio.h>      
#include <stdlib.h>
#include <time.h> 
using namespace std;
//cpu's move
int move;
//ai difficulty
//current turn number
int turnnum;
//game boolean
bool game = true;
//board array
char square[10] = {'0','1','2','3','4','5','6','7','8','9'};

//checks current player and declares victor
int checkplyr(int turnnum);
int checkplyr(int turnnum)
{
    if(turnnum %2 == 0)
    {   
        cout<<"player 2 won!"<<endl;
        return 2;
    }
    
    else
    {  
        cout<<"player 1 won!"<<endl;
        return 1;
    }
}

//checks for a victory
bool checkwin(bool game);
bool checkwin(bool game)
{
    if (square[1] == square[2] && square[2] == square[3])
    {
        checkplyr(turnnum);
        return true;
    }    
    else if (square[4] == square[5] && square[5] == square[6])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[7] == square[8] && square[8] == square[9])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[1] == square[4] && square[4] == square[7])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[2] == square[5] && square[5] == square[8])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[3] == square[6] && square[6] == square[9])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[1] == square[5] && square[5] == square[9])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[3] == square[5] && square[5] == square[7])
    {    
        checkplyr(turnnum);
        return true;
    }
    else if (square[1] != '1' && square[2] != '2' && square[3] != '3' 
             && square[4] != '4' && square[5] != '5' && square[6] != '6' 
             && square[7] != '7' && square[8] != '8' && square[9] != '9')
    {
        cout<<"tie game"<<endl;
        return true;
    }
    else
    {
        return false;
    }
}

//draws board
void drawboard();
void drawboard()
{
    cout <<""<<endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;
	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;
	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;
	cout << "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;
	cout << "     |     |     " << endl << endl;
}

//sets ai difficulty
void aiset();
void aiset()
{
        char aidiff;
        cout<<"easy or hard mode?"<<endl;
        string easyhard;
        cin>>easyhard;
        if(easyhard == "e", "easy")
        {
            aidiff = 'e';
        }
        else
        {
           aidiff = 'h';
        }
}
int playcom(char aidiff, int square[10]);
int playcom(char aidiff, int square[10])
{
    if(aidiff == 'e'){
        int move = 5;
        return move;
    
    }
    if(aidiff == 'h'){
        int move = 5;
        return move;
    }
}

//main function
int main()
{
    int plyrchoice;
    string hvcpu;
    cout<<"do you want to play another human, or against the computer?"<<endl;
    cin >>hvcpu;
    if(hvcpu=="computer")
    {
        aiset();
    }
    if (hvcpu=="human")
        cout<<"TICTACTOE GO!!!!"<<endl;
        checkwin(game);
        drawboard();
        while(checkwin(game) == false)
        {
            cout<<"tic-tac-toe"<<endl;
            char xo;
            turnnum++;
                if(turnnum%2 == 0)
                {
                    if(hvcpu == "human")
                    {
                        cout<<"player 2 choose a square"<<endl;
                        cin >> plyrchoice;                    }
                    if(hvcpu == "computer")
                    {
                        /*???*/
                    }
                    xo = 'X';
                }
                else if(turnnum%2 != 0)
                {
                    cout<<"player 1 choose a square"<<endl;
                    cin >> plyrchoice;
                    xo = 'O';                
                }
                if (plyrchoice == 1 && square[1] == '1')
                    square[1] = xo;
                else if (plyrchoice == 2 && square[2] == '2')
                    square[2] = xo;
                else if (plyrchoice == 3 && square[3] == '3')
                    square[3] = xo;
                else if (plyrchoice == 4 && square[4] == '4')
                    square[4] = xo;
                else if (plyrchoice == 5 && square[5] == '5')
                    square[5] = xo;
                else if (plyrchoice == 6 && square[6] == '6')
                    square[6] = xo;
                else if (plyrchoice == 7 && square[7] == '7')
                    square[7] = xo;
                else if (plyrchoice == 8 && square[8] == '8')
                    square[8] = xo;
                else if (plyrchoice == 9 && square[9] == '9')
                    square[9] = xo;
                else
                {
                    cout<<"invalid move";
                } 
            drawboard();
        }//while
}//main 
Topic archived. No new replies allowed.