Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wu_009
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
William Gonzalez
wu_009
Commits
7db1fb5f
Commit
7db1fb5f
authored
Oct 28, 2021
by
willgonzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
0 deletions
+173
-0
Tablero.java
+47
-0
Tateti.java
+126
-0
No files found.
Tablero.java
0 → 100644
View file @
7db1fb5f
import
java.util.Scanner
;
public
class
Tablero
{
public
static
void
main
(
String
[]
args
)
{
Tateti
t
=
new
Tateti
();
int
gano
=
0
;
int
jugadaValida
=
0
;
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
jugada
;
int
I1
;
int
I2
;
char
caracter
;
for
(
int
i
=
0
;
i
<
9
;
i
++){
jugadaValida
=
0
;
if
(
i
%
2
==
0
){
caracter
=
'X'
;
}
else
{
caracter
=
'O'
;
}
while
(
jugadaValida
==
0
){
System
.
out
.
println
(
"Ingrese la jugada:"
);
jugada
=
scanner
.
nextLine
();
I1
=
Tateti
.
convertirChar
(
jugada
.
charAt
(
0
));
// System.out.println(I1);
I2
=
Tateti
.
convertirInt
(
jugada
.
charAt
(
1
));
// System.out.println(I2);
if
(
I1
==-
1
||
I2
==-
1
){
System
.
out
.
println
(
"Jugada Invalida"
);
}
else
{
if
(
t
.
setJugada
(
I1
,
I2
,
caracter
)==
0
){
System
.
out
.
println
(
"Jugada Invalida"
);
}
else
{
t
.
imprimirTablero
();
gano
=
t
.
verificaJugada
();
jugadaValida
=
1
;
}
}
}
if
(
gano
==
1
){
System
.
out
.
println
(
"Gano"
);
break
;
}
}
}
}
\ No newline at end of file
Tateti.java
0 → 100644
View file @
7db1fb5f
import
javax.lang.model.util.ElementScanner6
;
import
java.util.Scanner
;
public
class
Tateti
{
char
[][]
tateti
={{
' '
,
' '
,
' '
},{
' '
,
' '
,
' '
},{
' '
,
' '
,
' '
}};
public
Tateti
(){
}
public
static
int
convertirInt
(
char
a
){
if
(
a
==
'1'
||
a
==
'2'
||
a
==
'3'
){
return
((
Character
.
getNumericValue
(
a
))-
1
);
}
else
{
return
-
1
;
}
}
public
static
int
convertirChar
(
char
a
){
if
(
a
==
'A'
){
return
0
;
}
else
if
(
a
==
'B'
){
return
1
;
}
else
if
(
a
==
'C'
){
return
2
;
}
else
{
return
-
1
;
}
}
public
int
setJugada
(
int
a
,
int
b
,
char
j
){
if
(
tateti
[
a
][
b
]==
' '
){
tateti
[
a
][
b
]=
j
;
return
1
;
}
else
{
return
0
;
}
}
public
int
verificaJugada
(){
int
CF
[]=
new
int
[
3
];
int
CC
[]=
new
int
[
3
];
int
CDI
=
0
,
CDD
=
0
,
gano
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++){
for
(
int
j
=
0
;
j
<
2
;
j
++){
if
(
tateti
[
i
][
j
]==
tateti
[
i
][
j
+
1
]
&&
Character
.
compare
(
tateti
[
i
][
j
],
' '
)!=
0
&&
Character
.
compare
(
tateti
[
i
][
j
+
1
],
' '
)!=
0
){
CF
[
i
]++;
}
if
(
tateti
[
j
+
1
][
i
]==
tateti
[
j
][
i
]
&&
Character
.
compare
(
tateti
[
j
+
1
][
i
],
' '
)!=
0
&&
Character
.
compare
(
tateti
[
j
][
i
],
' '
)!=
0
){
CC
[
i
]++;
}
}
}
if
(
CF
[
0
]==
2
){
System
.
out
.
println
(
"A1-A2-A3"
);
gano
=
1
;
}
else
if
(
CF
[
1
]==
2
){
System
.
out
.
println
(
"B1-B2-B3"
);
gano
=
1
;
}
else
if
(
CF
[
2
]==
2
){
System
.
out
.
println
(
"C1-A2-A3"
);
gano
=
1
;
}
else
if
(
CC
[
0
]==
2
){
System
.
out
.
println
(
"A1-B1-C1"
);
gano
=
1
;
}
else
if
(
CC
[
1
]==
2
){
System
.
out
.
println
(
"A2-B2-C2"
);
gano
=
1
;
}
else
if
(
CC
[
2
]==
2
){
System
.
out
.
println
(
"A3-B3-C3"
);
gano
=
1
;
}
else
if
(
tateti
[
0
][
0
]==
tateti
[
1
][
1
]
&&
tateti
[
0
][
0
]==
tateti
[
2
][
2
]&&
Character
.
compare
(
tateti
[
0
][
0
],
' '
)!=
0
&&
Character
.
compare
(
tateti
[
1
][
1
],
' '
)!=
0
){
System
.
out
.
println
(
"A1-B2-C3"
);
gano
=
1
;
}
else
if
(
tateti
[
0
][
2
]==
tateti
[
1
][
1
]
&&
tateti
[
2
][
0
]==
tateti
[
1
][
1
]&&
Character
.
compare
(
tateti
[
0
][
2
],
' '
)!=
0
&&
Character
.
compare
(
tateti
[
1
][
1
],
' '
)!=
0
){
System
.
out
.
println
(
"A3-B2-C1"
);
gano
=
1
;
}
return
gano
;
}
public
void
imprimirTablero
(){
for
(
int
i
=
0
;
i
<
3
;
i
++){
for
(
int
j
=
0
;
j
<
3
;
j
++){
System
.
out
.
print
(
"| "
+
tateti
[
i
][
j
]+
" |"
);
}
System
.
out
.
println
();
}
}
/*public static void main(String[] args) {
Tateti t=new Tateti();
int gano=0;
int jugadaValida=0;
Scanner scanner=new Scanner(System.in);
String jugada;
int I1;
int I2;
char caracter;
for(int i=0;i<9;i++){
jugadaValida=0;
if(i%2==0){
caracter='X';
}else{
caracter='O';
}
while(jugadaValida==0){
System.out.println("Ingrese la jugada:");
jugada=scanner.nextLine();
I1=convertirChar(jugada.charAt(0));
// System.out.println(I1);
I2= convertirInt(jugada.charAt(1));
// System.out.println(I2);
if(I1==-1||I2==-1){
System.out.println("Jugada Invalida");
}else{
if(t.setJugada(I1,I2,caracter)==0){
System.out.println("Jugada Invalida");
}else{
t.imprimirTablero();
gano=t.verificaJugada();
jugadaValida=1;
}
}
}
if(gano==1){
System.out.println("Gano");
break;
}
}
}*/
}
\ No newline at end of file
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