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
2307da70
Commit
2307da70
authored
Apr 28, 2022
by
Emanuel Lugo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pokerGame2 terminado
parent
63e14615
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
302 additions
and
91 deletions
+302
-91
.vscode/settings.json
+4
-0
poker/Carta.java
+51
-2
poker/pokerGame.java
+14
-26
poker2/PokerGame2.java
+233
-63
No files found.
.vscode/settings.json
0 → 100644
View file @
2307da70
{
"java.jdt.ls.vmargs"
:
"-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m"
}
\ No newline at end of file
poker/Carta.java
View file @
2307da70
package
poker
;
import
java.util.Objects
;
public
class
Carta
{
public
String
valor
;
...
...
@@ -40,10 +41,39 @@ public class Carta {
return
this
.
valor
+
this
.
palo
;
}
//VER OPCINES DE SOLUCIONAR LETRAS
public
int
getValorInt
()
{
int
aux
=
Integer
.
parseInt
(
this
.
valor
);
int
result
=
0
;
try
{
int
aux
=
Integer
.
parseInt
(
this
.
valor
);
return
aux
;
}
catch
(
Exception
e
)
{
switch
(
this
.
valor
)
{
case
"T"
:
result
=
10
;
break
;
case
"J"
:
result
=
11
;
break
;
case
"Q"
:
result
=
12
;
break
;
case
"K"
:
result
=
13
;
break
;
case
"A"
:
result
=
14
;
break
;
}
return
result
;
}
}
...
...
@@ -52,4 +82,23 @@ public class Carta {
}
public
void
setValor
(
String
nuevoValor
){
this
.
valor
=
String
.
valueOf
(
nuevoValor
.
charAt
(
0
));
this
.
palo
=
String
.
valueOf
(
nuevoValor
.
charAt
(
1
));
}
@Override
public
boolean
equals
(
Object
b
)
{
Carta
cartab
=
(
Carta
)
b
;
if
(
this
.
valor
.
equals
(
cartab
.
valor
)
&&
(
this
.
palo
.
equals
(
cartab
.
palo
)))
{
return
true
;
}
else
return
false
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
this
.
valor
,
this
.
palo
);
}
}
poker/pokerGame.java
View file @
2307da70
...
...
@@ -19,6 +19,18 @@ public class pokerGame {
// COMPROBACIÓN DE CASOS DE CARTAS EN SECUENCIA - ESCALERA COLOR - ESCALERA -
// COLOR
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
}
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");
...
...
@@ -36,7 +48,7 @@ public class pokerGame {
}
if
(
contadorValor
==
3
&&
mano
.
get
(
0
).
getValorInt
()
==
1
&&
mano
.
get
(
4
).
getValorInt
()
==
13
)
{
return
resultado
=
"ESCALERA
COLOR
"
;
return
resultado
=
"ESCALERA"
;
}
if
(
contadorValor
==
4
&&
contadorPalo
==
4
)
{
return
resultado
=
"ESCALERA COLOR"
;
...
...
@@ -107,27 +119,3 @@ public class pokerGame {
}
}
\ No newline at end of file
/*
* PARA TESTEAR
* Collections.sort(mano, new SortbyPalo());
*
* System.out.println("");
*
* for (i = 0; i < mano.size(); i++)
* 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());
*
* Collections.sort(mano, new SortbyValor());
*
* System.out.println("");
*
* for (i = 0; i < mano.size(); i++)
* System.out.println(mano.get(i).valorPalo());
*/
\ No newline at end of file
poker2/PokerGame2.java
View file @
2307da70
...
...
@@ -3,96 +3,108 @@ package poker2;
import
poker.*
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Random
;
public
class
PokerGame2
{
public
String
ganadores
(
List
<
Carta
[]>
jugadas
)
{
System
.
out
.
println
(
"Cantidad de jugadas: "
+
jugadas
.
size
());
for
(
Carta
[]
mano
:
jugadas
)
{
System
.
out
.
println
(
"JUGADA ======================"
);
for
(
Carta
c
:
mano
)
{
System
.
out
.
println
(
c
.
valorPalo
());
}
}
return
"0"
;
}
public
static
void
main
(
String
args
[])
{
int
puntosMano1
,
puntosMano2
;
ArrayList
[]
manos
;
public
String
ganadores
(
ArrayList
<
Carta
>
[]
jugadas
)
{
int
puntosMano1
=
0
;
int
puntosMano2
=
0
;
PokerGame2
pokerGanador
=
new
PokerGame2
();
pokerGame
pokerJugadas
=
new
pokerGame
();
ArrayList
<
Carta
>
mano1
=
new
ArrayList
<
Carta
>();
ArrayList
<
Carta
>
mano2
=
new
ArrayList
<
Carta
>();
// agregamos la mano 1
Carta
carta1
=
new
Carta
(
"2S "
);
Carta
carta2
=
new
Carta
(
"2C "
);
Carta
carta3
=
new
Carta
(
"4H "
);
Carta
carta4
=
new
Carta
(
"5D "
);
Carta
carta5
=
new
Carta
(
"5C "
);
mano1
.
add
(
carta1
);
mano1
.
add
(
carta2
);
mano1
.
add
(
carta3
);
mano1
.
add
(
carta4
);
mano1
.
add
(
carta5
);
// agregamos la mano2
Carta
carta6
=
new
Carta
(
"AS "
);
Carta
carta7
=
new
Carta
(
"AC "
);
Carta
carta8
=
new
Carta
(
"AH "
);
Carta
carta9
=
new
Carta
(
"4D "
);
Carta
carta10
=
new
Carta
(
"4C "
);
mano2
.
add
(
carta6
);
mano2
.
add
(
carta7
);
mano2
.
add
(
carta8
);
mano2
.
add
(
carta9
);
mano2
.
add
(
carta10
);
// IMPRIMIMOS LAS MANOS
System
.
out
.
println
(
"MANO1:"
);
for
(
Carta
c1
:
mano1
)
{
System
.
out
.
print
(
c1
.
valorPalo
()
+
" "
);
puntosMano1
=
pokerGanador
.
valorJugada
(
pokerJugadas
.
jugadas
(
jugadas
[
0
]));
puntosMano2
=
pokerGanador
.
valorJugada
(
pokerJugadas
.
jugadas
(
jugadas
[
1
]));
System
.
out
.
println
(
" "
);
//IMPRIMIR CARTAS Y JUGADAS
System
.
out
.
println
(
"JUGADOR 1 :"
);
for
(
Carta
it
:
jugadas
[
0
])
{
System
.
out
.
print
(
it
.
valorPalo
()
+
" "
);
}
System
.
out
.
println
(
"--> "
+
pokerJugadas
.
jugadas
(
jugadas
[
0
]));
System
.
out
.
println
(
" "
);
System
.
out
.
println
(
"
MANO2
:"
);
for
(
Carta
c2
:
mano2
)
{
System
.
out
.
print
(
c
2
.
valorPalo
()
+
" "
);
System
.
out
.
println
(
"
JUGADOR 2
:"
);
for
(
Carta
it2
:
jugadas
[
1
]
)
{
System
.
out
.
print
(
it
2
.
valorPalo
()
+
" "
);
}
puntosMano1
=
pokerGanador
.
valorJugada
(
pokerJugadas
.
jugadas
(
mano1
));
puntosMano2
=
pokerGanador
.
valorJugada
(
pokerJugadas
.
jugadas
(
mano2
));
System
.
out
.
println
(
"--> "
+
pokerJugadas
.
jugadas
(
jugadas
[
1
]
));
System
.
out
.
println
(
" "
);
/*
* System.out.println(" \nPuntos Mano1 = " + puntosMano1);
* System.out.println(pokerJugadas.jugadas(mano1));
*
* System.out.println(" \nPuntos Mano2 = " + puntosMano2);
* System.out.println(pokerJugadas.jugadas(mano2));
*/
// FUNCION QUE COMPARA LAS JUGADAS
//IMPRIMIR LA MANO GANADORA
if
(
puntosMano1
>
puntosMano2
)
{
System
.
out
.
println
(
"
LA MANO GANADORA ES:
"
);
System
.
out
.
println
(
"
GANA LA MANO DEL JUGADOR 1 !!!
"
);
for
(
Carta
c1
:
mano1
)
{
for
(
Carta
c1
:
jugadas
[
0
]
)
{
System
.
out
.
print
(
c1
.
valorPalo
()
+
" "
);
}
System
.
out
.
println
(
pokerJugadas
.
jugadas
(
mano1
));
System
.
out
.
println
(
pokerJugadas
.
jugadas
(
jugadas
[
0
]));
}
else
if
(
puntosMano1
<
puntosMano2
){
System
.
out
.
println
(
"GANA LA MANO DEL JUGADOR 2 !!!"
);
for
(
Carta
c2
:
jugadas
[
1
]
)
{
System
.
out
.
print
(
c2
.
valorPalo
()
+
" "
);
}
System
.
out
.
println
(
pokerJugadas
.
jugadas
(
jugadas
[
1
]));
}
else
{
int
totalValorMano1
=
0
;
int
totalValorMano2
=
0
;
System
.
out
.
println
(
"LA MANO GANADORA ES:"
);
for
(
Carta
c1
:
jugadas
[
0
])
{
totalValorMano1
=
totalValorMano1
+
c1
.
getValorInt
();
}
for
(
Carta
c2
:
jugadas
[
1
]
)
{
totalValorMano2
=
totalValorMano2
+
c2
.
getValorInt
();
}
if
(
totalValorMano1
>
totalValorMano2
)
{
System
.
out
.
println
(
"LUGO DEL EMPATE - GANA LA MANO DEL JUGADOR 1 !!!"
);
for
(
Carta
c1
:
jugadas
[
0
])
{
System
.
out
.
print
(
c1
.
valorPalo
()
+
" "
);
System
.
out
.
print
(
""
);
}
System
.
out
.
println
();
//System.out.println("Valor TOTAL:"+totalValorMano1);
for
(
Carta
c2
:
mano2
)
{
}
else
{
System
.
out
.
println
(
"LUGO DEL EMPATE - GANA LA MANO DEL JUGADOR 2 !!!"
);
for
(
Carta
c2
:
jugadas
[
1
])
{
System
.
out
.
print
(
c2
.
valorPalo
()
+
" "
);
}
System
.
out
.
println
();
System
.
out
.
print
(
""
);
//System.out.println("Valor TOTAL:"+totalValorMano2);
}
System
.
out
.
println
(
pokerJugadas
.
jugadas
(
mano2
));
}
return
"0"
;
}
public
static
void
main
(
String
args
[])
{
PokerGame2
pokerGanador
=
new
PokerGame2
();
pokerGame
pokerJugadas
=
new
pokerGame
();
ArrayList
<
Carta
>
[]
manoGenerada
=
(
ArrayList
<
Carta
>[])
new
ArrayList
[
2
];
manoGenerada
=
pokerGanador
.
generarMano
();
pokerGanador
.
ganadores
(
manoGenerada
)
;
}
public
int
valorJugada
(
String
jugada
)
{
int
result
;
switch
(
jugada
)
{
...
...
@@ -131,4 +143,162 @@ public class PokerGame2 {
}
public
static
ArrayList
<
Carta
>[]
generarMano
()
{
int
i
;
Carta
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
,
c8
,
c9
,
c10
;
ArrayList
<
Carta
>
mano1
=
new
ArrayList
<
Carta
>
()
;
ArrayList
<
Carta
>
mano2
=
new
ArrayList
<
Carta
>
()
;
ArrayList
<
Carta
>
[]
dualMano
=
(
ArrayList
<
Carta
>[])
new
ArrayList
[
2
];
ArrayList
<
Carta
>
mazo
=
new
ArrayList
<
Carta
>()
;
c1
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c2
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c3
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c4
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c5
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c6
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c7
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c8
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c9
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
c10
=
new
Carta
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)))
;
mazo
.
add
(
c1
);
mazo
.
add
(
c2
);
mazo
.
add
(
c3
);
mazo
.
add
(
c4
);
mazo
.
add
(
c5
);
mazo
.
add
(
c6
);
mazo
.
add
(
c7
);
mazo
.
add
(
c8
);
mazo
.
add
(
c9
);
mazo
.
add
(
c10
);
i
=
0
;
while
(
i
<
5
){
if
(!
(
mano1
.
contains
(
mazo
.
get
(
i
))
)
)
{
mano1
.
add
(
mazo
.
get
(
i
));
i
++;
}
else
{
mazo
.
get
(
i
).
setValor
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)));
}
}
i
=
5
;
while
(
i
<
10
){
if
(!
(
mano2
.
contains
(
mazo
.
get
(
i
))
||
mano1
.
contains
(
mazo
.
get
(
i
)))
)
{
mano2
.
add
(
mazo
.
get
(
i
));
i
++;
}
else
{
mazo
.
get
(
i
).
setValor
(
forNumbertoValor
(
numeroRandom
(
1
,
14
))
+
forNumbertoPalo
(
numeroRandom
(
1
,
4
)));
}
}
dualMano
[
0
]
=
mano1
;
dualMano
[
1
]
=
mano2
;
return
dualMano
;
}
public
static
int
numeroRandom
(
int
min
,
int
max
){
int
valor
,
minimo
,
maximo
;
minimo
=
min
;
maximo
=
max
;
Random
ran
=
new
Random
();
valor
=
ran
.
nextInt
(
maximo
)
+
minimo
;
return
valor
;
}
public
static
String
forNumbertoPalo
(
int
numero
)
{
String
result
=
" "
;
switch
(
numero
)
{
case
1
:
result
=
"S"
;
break
;
case
2
:
result
=
"C"
;
break
;
case
3
:
result
=
"H"
;
break
;
case
4
:
result
=
"D"
;
break
;
default
:
result
=
"X"
;
break
;
}
return
result
;
}
public
static
String
forNumbertoValor
(
int
numero
)
{
String
result
=
" "
;
switch
(
numero
)
{
case
1
:
result
=
"A"
;
break
;
case
2
:
result
=
"2"
;
break
;
case
3
:
result
=
"3"
;
break
;
case
4
:
result
=
"4"
;
break
;
case
5
:
result
=
"5"
;
break
;
case
6
:
result
=
"6"
;
break
;
case
7
:
result
=
"7"
;
break
;
case
8
:
result
=
"8"
;
break
;
case
9
:
result
=
"9"
;
break
;
case
10
:
result
=
"T"
;
break
;
case
11
:
result
=
"J"
;
break
;
case
12
:
result
=
"Q"
;
break
;
case
13
:
result
=
"K"
;
break
;
case
14
:
result
=
"A"
;
break
;
default
:
result
=
"/"
;
break
;
}
return
result
;
}
}
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