Tic Tac Toe 4X4 issue

Hi.
I´m trying to program a Tic Tac Toe 4X4. I almost get the code, but i got the following error when I try to compile it in the line 118:

¨error iso c++ forbids comparison between pointer and integer -fpermissive ".

Could you help me please :)?

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
//Proyecto Final Tic - Tac - Toe

#include <iostream>
#include <stdio.h>
#include <fstream>


using namespace std;

//En este espacio se enuncian las funciones y variables que se utilizaran en el programa.

void tablero_de_juego();
void turno_del_jugador();
bool fin_del_juego();

char turno;
char tablero[4][4] = {{'A', 'B', 'C', 'D'}, {'E', 'F', 'G', 'H'}, {'I', 'J', 'K', 'L'}, {'M', 'N', 'O', 'P'}};
bool empate = false;


//Aqui se empieza a desarrollar el programa.
int main()
{

    cout<<endl;
    cout<<"               Juego de Tic - Tac - Toe              "<<endl;
    cout<<endl;
    cout<<"Instrucciones:"<<endl;
    cout<<endl;
    cout<<"El Tic - Tac - Toe es un juego para dos jugadores,"<<endl;
    cout<<"X y O, que se turnan y marcan los espacios en una"<<endl;
    cout<<"cuadrícula de 3 x 3. El jugador que logre colocar"<<endl;
    cout<<"tres de sus marcas en una fila horizontal, vertical"<<endl;
    cout<<"o diagonal, gana el juego."<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;

    turno = 'X';

    while (!fin_del_juego()){
            
        tablero_de_juego();
        turno_del_jugador();
        fin_del_juego();
    }

    if (turno == 'O' && !empate){
        tablero_de_juego();
        cout << endl << endl << "Player 1 [X] Wins! Game Over!\n";
    }
    else if (turno == 'X' && !empate){
        tablero_de_juego();
        cout << endl << endl << "Player 2 [O] Wins! Game Over!\n";
    }
    else{
        tablero_de_juego();
        cout << endl << endl << "It's a draw! Game Over!\n";
    }
}


//Aqui se degine la funcion que muestra el tablero de juego
void tablero_de_juego(){

int i;
int j;
 for (int i = 0; i < 4; i++){
      for (int j = 0; j < 4; j++){
        cout<<"   "<<tablero[i][j]<<"   ||";
    }
    cout<<endl;
    cout<<"______________________________________"<<endl;
    cout<<endl;
   }

}

//Aqui se define los turnos de los juagadores
void turno_del_jugador(){

    int decicion;
    int fila = 0, columna = 0;

    if (turno == 'X')
    {
        cout << "Player 1 turn [X]: ";
    }
    else if (turno == 'O')
    {
        cout << "Player 2 turn [O]: ";
    }
    cin >> decicion;

    switch (decicion)
    {
         case 1: fila = 0; columna = 0; break;
         case 2: fila = 0; columna = 1; break;
         case 3: fila = 0; columna = 2; break;
         case 4: fila = 0; columna = 3; break;
         case 5: fila = 1; columna = 0; break;
         case 6: fila = 1; columna = 1; break;
         case 7: fila = 1; columna = 2; break;
         case 8: fila = 1; columna = 3; break;
         case 9: fila = 2; columna = 0; break;
        case 10: fila = 2; columna = 1; break;
        case 11: fila = 2; columna = 2; break;
        case 12: fila = 2; columna = 3; break;
        case 13: fila = 3; columna = 0; break;
        case 14: fila = 3; columna = 1; break;
        case 15: fila = 3; columna = 2; break;
        case 16: fila = 3; columna = 3; break;
        default:
            cout << "You didn't enter a correct number! Try again\n";
            turno_del_jugador();
    }

 118 -->   if (turno == 'X' && tablero_de_juego[fila][columna] != 'X' && tablero_de_juego[fila][columna] != 'O'){
        tablero_de_juego[fila][columna] = 'X';
        turno = 'O';
    }
    else if (turno == 'O' && tablero_de_juego[fila][columna] != 'X' && tablero_de_juego[fila][columna] != 'O')
    {
        tablero_de_juego[fila][columna] = 'O';
        turno = 'X';
    }
    else
    {
        cout << "The cell you chose is used! Try again\n";
        turno_del_jugador();
    }

}

//Aqui se define quien gana la partida

bool fin_del_juego(){

    for (int i = 0; i < 4; i++){

        if ((tablero_de_juego[i][0] == tablero_de_juego[i][1] && tablero_de_juego[i][1] == tablero_de_juego[i][2]) || (tablero_de_juego[0][i] == tablero_de_juego[1][i] && tablero_de_juego[1][i] == tablero_de_juego[2][i]) || (tablero_de_juego[0][0] == tablero_de_juego[1][1] && tablero_de_juego[1][1] == tablero_de_juego[2][2]) || (tablero_de_juego[0][2] == tablero_de_juego[1][1] && tablero_de_juego[1][1] == tablero_de_juego[2][0]))
        {
            return true;
        }
    }

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (tablero_de_juego[i][j] != 'X' && tablero_de_juego[i][j] != 'O')
            {
                return false;
            }
        }
    }
    empate = true;
    return true;
}
Last edited on
line 12: tablero_de_juego is declared as a void function.

Line 118,119,122,124,141,151: You're trying to make a doubly sub-scripted reference to a function pointer. Did you mean tablero here?


Last edited on
As AbstractionAnon said. You are using tablero_de_juego[][] when tablero_dejuego is a function and not an array of chars.

Swap all of your:
tablero_de_juego[fila][columna]

With your array of chars identifier:
tablero[fila][columna]
Thanks AbstractionAnon for the advice ;). I just identify the problem and I solved it. Now the game is working well :)
Thanks Mr Impact :).
I have already solved the problem. You are the best :)
Topic archived. No new replies allowed.