Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
poker
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
Emanuel Lugo
poker
Commits
c6175c7d
Commit
c6175c7d
authored
Apr 26, 2022
by
Emanuel Lugo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DETECTA MAS JUGADAS POSIBLES
parent
7116abc8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
25 deletions
+122
-25
Carta.java
+25
-4
SortbyPalo.java
+6
-3
SortbyValor.java
+9
-2
pokerGame.java
+82
-16
No files found.
Carta.java
View file @
c6175c7d
...
...
@@ -11,21 +11,42 @@ public class Carta {
public
Carta
(
String
completo
)
{
this
.
valor
=
String
.
valueOf
(
completo
.
charAt
(
0
));
if
(
completo
.
charAt
(
0
)
==
'A'
)
this
.
valor
=
"1"
;
else
if
(
completo
.
charAt
(
0
)
==
'T'
)
this
.
valor
=
"10"
;
else
if
(
completo
.
charAt
(
0
)
==
'J'
)
this
.
valor
=
"11"
;
else
if
(
completo
.
charAt
(
0
)
==
'Q'
)
this
.
valor
=
"12"
;
else
if
(
completo
.
charAt
(
0
)
==
'K'
)
this
.
valor
=
"13"
;
else
this
.
valor
=
String
.
valueOf
(
completo
.
charAt
(
0
));
this
.
palo
=
String
.
valueOf
(
completo
.
charAt
(
1
));
}
String
valorPalo
()
{
return
this
.
valor
+
this
.
palo
;
if
(
this
.
valor
.
equals
(
"1"
))
{
return
"A"
+
" "
+
this
.
palo
;
}
else
if
(
this
.
valor
.
equals
(
"10"
))
{
return
"T"
+
" "
+
this
.
palo
;
}
else
if
(
this
.
valor
.
equals
(
"11"
))
{
return
"J"
+
" "
+
this
.
palo
;
}
else
if
(
this
.
valor
.
equals
(
"12"
))
{
return
"Q"
+
" "
+
this
.
palo
;
}
else
if
(
this
.
valor
.
equals
(
"13"
))
{
return
"K"
+
" "
+
this
.
palo
;
}
else
return
this
.
valor
+
" "
+
this
.
palo
;
}
public
int
getValorInt
()
{
int
aux
=
Integer
.
parseInt
(
this
.
valor
);
return
aux
;
}
public
String
getPalo
()
{
return
this
.
palo
;
}
}
SortbyPalo.java
View file @
c6175c7d
...
...
@@ -5,7 +5,9 @@ class SortbyPalo implements Comparator<Carta>
// Used for sorting in ascending order of
// Ordenar por Palo
public
int
compare
(
Carta
a
,
Carta
b
)
{
return
a
.
palo
.
compareTo
(
b
.
palo
)
;
}
{
// int aux1, aux2;
return
a
.
palo
.
compareTo
(
b
.
palo
)
;
}
}
\ No newline at end of file
SortbyValor.java
View file @
c6175c7d
...
...
@@ -5,7 +5,13 @@ class SortbyValor implements Comparator<Carta>
// Used for sorting in ascending order of
// Ordenar por Palo
public
int
compare
(
Carta
a
,
Carta
b
)
{
return
a
.
valor
.
compareTo
(
b
.
valor
)
;
{
int
aux1
=
a
.
getValorInt
();
int
aux2
=
b
.
getValorInt
();
if
(
aux1
>
aux2
)
return
1
;
else
return
-
1
;
}
}
\ No newline at end of file
pokerGame.java
View file @
c6175c7d
/** */
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Scanner
;
import
java.util.*
;
public
class
pokerGame
{
public
String
jugadas
(
Carta
manoAux
[]){
public
String
jugadas
(
ArrayList
<
Carta
>
mano
){
String
resultado
;
Collections
.
sort
(
mano
,
new
SortbyValor
());
int
contadorValor
=
0
;
int
contadorPalo
=
0
;
int
valorCarta
,
valorSgteCarta
,
aux
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
//System.out.println(mano.get(i).getValorInt() + ": valor carta1");
//System.out.println(mano.get(i+1).getValorInt() + ": valor carta2");
valorCarta
=
mano
.
get
(
i
).
getValorInt
()
;
// trae el valor entero contenido en la carta
valorSgteCarta
=
mano
.
get
(
i
+
1
).
getValorInt
();
// trae el valor entero contenido en la carta siguiente
if
(
mano
.
get
(
i
).
palo
.
equals
(
mano
.
get
(
i
+
1
).
palo
))
contadorPalo
++
;
aux
=
valorCarta
+
1
;
if
(
aux
==
valorSgteCarta
)
contadorValor
++
;
System
.
out
.
println
(
"contador SECUENCIAL: "
+
contadorValor
);
System
.
out
.
println
(
"contador PALOSIGUALES: "
+
contadorPalo
);
}
/*
int contadorPalo = 0;
for (int i=0;i<4;i++) {
//System.out.println("PALO de la carta1: " +mano.get(i).getPalo());
//System.out.println("PALO de la carta2: " +mano.get(i+1).getPalo());
if (mano.get(i).palo.equals(mano.get(i+1).palo)) contadorPalo++ ; // CUENTA CUANTAS CARTAS SON DEL MISMO PALO
System.out.println("contador PALOSIGUALES: " + contadorPalo);
}
*/
if
(
contadorValor
==
3
&&
mano
.
get
(
0
).
getValorInt
()
==
1
&&
mano
.
get
(
4
).
getValorInt
()
==
13
){
return
resultado
=
"ESCALERA COLOR"
;
}
if
(
contadorValor
==
4
&&
contadorPalo
==
4
)
{
return
resultado
=
"ESCALERA COLOR"
;
}
else
if
(
contadorValor
==
4
){
return
resultado
=
"ESCALERA"
;
}
else
if
(
contadorPalo
==
4
){
return
resultado
=
"COLOR"
;
}
//CASOS PARA POKER Y FULL
int
valoresIguales
=
0
;
valoresIguales
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
if
(
mano
.
get
(
i
).
getValorInt
()
==
mano
.
get
(
i
+
1
).
getValorInt
()
){
valoresIguales
++;
}
}
if
(
valoresIguales
==
3
&&
mano
.
get
(
3
).
getValorInt
()
!=
mano
.
get
(
4
).
getValorInt
())
{
return
resultado
=
"POKER"
;
}
else
if
((
valoresIguales
==
2
&&
mano
.
get
(
3
).
getValorInt
()
==
mano
.
get
(
4
).
getValorInt
())
||
(
valoresIguales
==
2
&&
mano
.
get
(
0
).
getValorInt
()
==
mano
.
get
(
1
).
getValorInt
()))
{
return
resultado
=
"FULL"
;}
else
if
(
valoresIguales
==
2
){
return
resultado
=
"TRIO"
;
}
return
null
;
return
resultado
=
"CARTA ALTA"
;
}
public
static
void
main
(
String
[]
args
)
{
pokerGame
poker
=
new
pokerGame
();
String
resultado
;
int
i
;
Carta
carta1
,
carta2
,
carta3
,
carta4
,
carta5
;
ArrayList
<
Carta
>
mano
=
new
ArrayList
<
Carta
>();
carta1
=
new
Carta
(
"AS"
);
carta2
=
new
Carta
(
"
2
S"
);
carta3
=
new
Carta
(
"
3
S"
);
carta4
=
new
Carta
(
"
4
S"
);
carta5
=
new
Carta
(
"
5
S"
);
carta2
=
new
Carta
(
"
T
S"
);
carta3
=
new
Carta
(
"
J
S"
);
carta4
=
new
Carta
(
"
Q
S"
);
carta5
=
new
Carta
(
"
K
S"
);
mano
.
add
(
carta5
)
;
mano
.
add
(
carta4
)
;
mano
.
add
(
carta3
)
;
mano
.
add
(
carta2
)
;
mano
.
add
(
carta1
)
;
//
System.out.println(mano);
System
.
out
.
println
(
mano
);
for
(
i
=
0
;
i
<
mano
.
size
();
i
++)
System
.
out
.
println
(
mano
.
get
(
i
).
valorPalo
()
);
...
...
@@ -57,11 +115,19 @@ public class pokerGame {
System
.
out
.
println
(
""
)
;
for
(
i
=
0
;
i
<
mano
.
size
();
i
++)
System
.
out
.
println
(
mano
.
get
(
i
).
valorPalo
());
System
.
out
.
println
(
mano
.
get
(
i
).
valorPalo
());
Collections
.
sort
(
mano
,
new
SortbyValor
());
System
.
out
.
println
(
""
)
;
for
(
i
=
0
;
i
<
mano
.
size
();
i
++)
System
.
out
.
println
(
mano
.
get
(
i
).
valorPalo
());
resultado
=
poker
.
jugadas
(
mano
);
System
.
out
.
println
(
resultado
);
}
...
...
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