Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wu-e001
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Rolon
wu-e001
Commits
8062db37
Commit
8062db37
authored
6 years ago
by
Pedro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
se agregó el archivo de tateti
parents
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
267 additions
and
0 deletions
+267
-0
README.md
+5
-0
tateti.cpp
+262
-0
No files found.
README.md
0 → 100644
View file @
8062db37
#Instrucciones para compilar y ejecutar
*
En una terminal de linux utilizar en compilador g++ de la siguiente manera:
**g++ tateti.cpp**
*
Para ejecutar el archivo generado, escribir:
**./a.out**
(donde a.out es el archivo generado, es el nombre común).
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tateti.cpp
0 → 100644
View file @
8062db37
#include<bits/stdc++.h>
#define N 3 //Dimensiones de la matriz
using
namespace
std
;
void
imprimir_tateti
(
char
matriz
[
N
][
N
]);
void
marcar
(
char
matriz
[
N
][
N
],
int
x
,
int
y
,
char
marca
);
char
comprobar_ganador
(
char
m
[
N
][
N
]);
int
main
(){
bool
error_jugada
=
false
;
bool
jugada_acabada
=
false
;
string
jugada
;
char
tateti
[
N
][
N
]
=
{{
' '
,
' '
,
' '
},
{
' '
,
' '
,
' '
},
{
' '
,
' '
,
' '
}
};
//imprimir_tateti(tateti);
cout
<<
"Bienvenidos al TA-TE-TI de Pedro del Bootcamp 004 de Roshka"
<<
endl
;
int
i
=
0
;
char
turno
=
97
;
while
(
i
<
9
){
do
{
cout
<<
turno
<<
". X -> Ingrese jugada: "
;
cin
>>
jugada
;
int
a
=
jugada
[
0
];
int
b
=
jugada
[
1
];
a
=
a
-
64
;
//Para mapear a numeros del tablero
b
=
b
-
48
;
//Para lo mismo de arriba xd
//cout << a << endl;
//cout << b << endl;
//Comprobación de la entrada
if
((
a
<
1
or
a
>
3
)
and
(
b
<
1
or
b
>
3
)){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Fila y Columna Inválidas"
<<
endl
;
}
else
if
(
a
<
1
or
a
>
3
){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Fila Inválida"
<<
endl
;
}
else
if
(
b
<
1
or
b
>
3
){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Columna Inválida"
<<
endl
;
}
else
if
(
tateti
[
a
-
1
][
b
-
1
]
!=
' '
){
cout
<<
"> ERR: Jugada Inválida - Casilla Ocupada"
<<
endl
;
error_jugada
=
true
;
}
else
{
error_jugada
=
false
;
marcar
(
tateti
,
a
-
1
,
b
-
1
,
'X'
);
cout
<<
"> OK"
<<
endl
;
imprimir_tateti
(
tateti
);
i
++
;
turno
++
;
}
}
while
(
error_jugada
);
char
ganador
=
comprobar_ganador
(
tateti
);
if
(
ganador
!=
' '
){
//cout << "GANADOR " << ganador << endl;
//cout << "FIN DEL JUEGO";
break
;
}
if
(
i
==
9
){
cout
<<
"> EMPATE"
<<
endl
;
break
;
}
do
{
cout
<<
turno
<<
". O -> Ingrese jugada: "
;
cin
>>
jugada
;
int
a
=
jugada
[
0
];
int
b
=
jugada
[
1
];
a
=
a
-
64
;
//Para mapear a numeros del tablero
b
=
b
-
48
;
//Para lo mismo de arriba xd
//cout << a << endl;
//cout << b << endl;
//Comprobación de la entrada
if
((
a
<
1
or
a
>
3
)
and
(
b
<
1
or
b
>
3
)){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Fila y Columna Inválidas"
<<
endl
;
}
else
if
(
a
<
1
or
a
>
3
){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Fila Inválida"
<<
endl
;
}
else
if
(
b
<
1
or
b
>
3
){
error_jugada
=
true
;
cout
<<
"> ERR: Jugada Inválida - Columna Inválida"
<<
endl
;
}
else
if
(
tateti
[
a
-
1
][
b
-
1
]
!=
' '
){
cout
<<
"> ERR: Jugada Inválida - Casilla Ocupada"
<<
endl
;
error_jugada
=
true
;
}
else
{
error_jugada
=
false
;
marcar
(
tateti
,
a
-
1
,
b
-
1
,
'O'
);
cout
<<
"> OK"
<<
endl
;
imprimir_tateti
(
tateti
);
i
++
;
turno
++
;
}
}
while
(
error_jugada
);
ganador
=
comprobar_ganador
(
tateti
);
if
(
ganador
!=
' '
){
//cout << "GANADOR " << ganador << endl;
//cout << "FIN DEL JUEGO";
break
;
}
if
(
i
==
9
){
cout
<<
"> EMPATE"
<<
endl
;
break
;
}
}
//cout << "> EMPATE" << endl;
cout
<<
"> FIN DEL JUEGO
\n
"
;
return
0
;
}
//Función que imprime en consola el tablero del tateti
//Recibe como parámetro las coordenadas nuevas, si las hay
//y la ficha que debe colocar
void
imprimir_tateti
(
char
matriz
[
N
][
N
]){
printf
(
"|---|---|---|
\n
"
);
printf
(
"| %c | %c | %c |"
,
matriz
[
0
][
0
],
matriz
[
0
][
1
],
matriz
[
0
][
2
]);
printf
(
"
\n
|---|---|---|
\n
"
);
printf
(
"| %c | %c | %c |"
,
matriz
[
1
][
0
],
matriz
[
1
][
1
],
matriz
[
1
][
2
]);
printf
(
"
\n
|---|---|---|
\n
"
);
printf
(
"| %c | %c | %c |"
,
matriz
[
2
][
0
],
matriz
[
2
][
1
],
matriz
[
2
][
2
]);
printf
(
"
\n
|---|---|---|
\n
"
);
}
void
marcar
(
char
matriz
[
N
][
N
],
int
x
,
int
y
,
char
marca
){
matriz
[
x
][
y
]
=
marca
;
}
char
comprobar_ganador
(
char
m
[
N
][
N
]){
//string ganador;
//Comprobacion de ganador por fila
if
(
m
[
0
][
0
]
==
m
[
0
][
1
]
and
m
[
0
][
1
]
==
m
[
0
][
2
]){
if
(
m
[
0
][
0
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
0
][
0
];
cout
<<
": A1-A2-A3"
<<
endl
;
}
//string ganador = m[0][0];
return
m
[
0
][
0
];
}
if
(
m
[
1
][
0
]
==
m
[
1
][
1
]
and
m
[
1
][
1
]
==
m
[
1
][
2
]){
if
(
m
[
1
][
0
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
1
][
0
];
cout
<<
": B1-B2-B3"
<<
endl
;
}
//string ganador = m[1][0];
return
m
[
1
][
0
];
}
if
(
m
[
2
][
0
]
==
m
[
2
][
1
]
and
m
[
2
][
1
]
==
m
[
2
][
2
]){
if
(
m
[
2
][
0
]
!=
' '
){
cout
<<
"> GANADOR"
<<
m
[
2
][
0
];
cout
<<
": C1-C2-C3"
<<
endl
;
}
//string ganador = m[2][0];
return
m
[
2
][
0
];
}
//comprobacion de ganador por columna
if
(
m
[
0
][
0
]
==
m
[
1
][
0
]
and
m
[
1
][
0
]
==
m
[
2
][
0
]){
if
(
m
[
0
][
0
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
0
][
0
];
cout
<<
": A1-B1-C1"
<<
endl
;
}
//string ganador = m[0][0];
return
m
[
0
][
0
];
}
if
(
m
[
0
][
1
]
==
m
[
1
][
1
]
and
m
[
1
][
1
]
==
m
[
2
][
1
]){
if
(
m
[
0
][
1
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
0
][
1
];
cout
<<
": A2-B2-C2"
<<
endl
;
}
//string ganador = m[0][1];
return
m
[
0
][
0
];
}
if
(
m
[
0
][
2
]
==
m
[
1
][
2
]
and
m
[
1
][
2
]
==
m
[
2
][
2
]){
if
(
m
[
0
][
2
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
0
][
2
];
cout
<<
": A3-B3-C3"
<<
endl
;
}
//string ganador = m[0][2];
return
m
[
0
][
2
];
}
//Comprobacion de diagonales principales
if
(
m
[
0
][
0
]
==
m
[
1
][
1
]
and
m
[
1
][
1
]
==
m
[
2
][
2
]){
if
(
m
[
0
][
0
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
0
][
0
];
cout
<<
": A1-B2-C3"
<<
endl
;
}
//string ganador = m[0][0];
return
m
[
0
][
0
];
}
if
(
m
[
0
][
2
]
==
m
[
1
][
1
]
and
m
[
1
][
1
]
==
m
[
2
][
0
]){
if
(
m
[
2
][
0
]
!=
' '
){
cout
<<
"> GANADOR "
<<
m
[
2
][
0
];
cout
<<
": A3-B2-C1"
<<
endl
;
}
//string ganador = m[2][0];
return
m
[
2
][
0
];
}
return
' '
;
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment