Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-e005-poker-02
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
Jose Baez
java-e005-poker-02
Commits
7fe40518
Commit
7fe40518
authored
Apr 28, 2022
by
Jose Baez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Poker2 final 1.0
parent
2f079f95
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
19 deletions
+152
-19
out/production/java-e005-poker-02/Carta.class
+0
-0
out/production/java-e005-poker-02/Juego.class
+0
-0
out/production/java-e005-poker-02/MyClass.class
+0
-0
src/Carta.java
+23
-2
src/Juego.java
+116
-16
src/MyClass.java
+13
-1
No files found.
out/production/java-e005-poker-02/Carta.class
View file @
7fe40518
No preview for this file type
out/production/java-e005-poker-02/Juego.class
View file @
7fe40518
No preview for this file type
out/production/java-e005-poker-02/MyClass.class
View file @
7fe40518
No preview for this file type
src/Carta.java
View file @
7fe40518
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
public
class
Carta
{
public
class
Carta
{
private
String
valor
;
private
String
valor
;
...
@@ -70,8 +71,8 @@ public class Carta {
...
@@ -70,8 +71,8 @@ public class Carta {
}
}
public
void
paloAleatorio
(){
public
void
paloAleatorio
(){
int
max
=
1
;
int
max
=
4
;
int
min
=
4
;
int
min
=
1
;
int
range
=
max
-
min
+
1
;
int
range
=
max
-
min
+
1
;
int
rand
=
(
int
)(
Math
.
random
()
*
range
)
+
min
;
int
rand
=
(
int
)(
Math
.
random
()
*
range
)
+
min
;
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
...
@@ -90,4 +91,24 @@ public class Carta {
...
@@ -90,4 +91,24 @@ public class Carta {
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Carta
carta
=
(
Carta
)
o
;
return
Objects
.
equals
(
valor
,
carta
.
valor
)
&&
Objects
.
equals
(
palo
,
carta
.
palo
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
valor
,
palo
);
}
@Override
public
String
toString
()
{
return
"Carta{"
+
"valor='"
+
valor
+
'\''
+
", palo='"
+
palo
+
'\''
+
'}'
;
}
}
}
src/Juego.java
View file @
7fe40518
import
java.util.ArrayLis
t
;
import
org.w3c.dom.ls.LSOutpu
t
;
import
java.util.Collections
;
import
java.util.
List
;
import
java.util.
*
;
public
class
Juego
{
public
class
Juego
{
List
<
Integer
>
valores
=
null
;
List
<
Integer
>
valores
=
null
;
public
Juego
()
{
public
Juego
()
{
}
}
public
String
mano1VsMano2
(
int
carta1
,
int
carta2
)
{
if
(
carta1
>
carta2
){
public
int
mano1VsMano2
(
int
carta1
,
int
carta2
)
{
return
"1"
;
if
(
carta1
>
carta2
)
{
}
else
if
(
carta1
<
carta2
){
return
1
;
return
"2"
;
}
else
if
(
carta1
<
carta2
)
{
}
else
if
(
carta1
==
carta2
)
{
return
2
;
return
"SON IGUALES"
;
}
else
if
(
carta1
==
carta2
)
{
return
0
;
}
return
0
;
}
public
void
desempateCarta
(
int
cartas1
,
int
cartas2
)
{
if
(
cartas1
>
cartas2
)
{
System
.
out
.
println
(
"1"
);
}
System
.
out
.
println
(
"2"
);
}
public
int
sumaManoValores
(
Carta
[]
cartas
)
{
List
<
Integer
>
valores
=
new
ArrayList
<>();
int
contador
=
0
;
for
(
Carta
c
:
cartas
)
{
valores
.
add
(
convertirValorStringAInteger
(
c
.
getValor
()));
contador
++;
}
}
return
"NO HAY GANADOR"
;
return
contador
;
}
}
public
int
juegosPosibles
(
List
<
Carta
>
cartas
)
{
public
int
juegosPosibles
(
List
<
Carta
>
cartas
)
{
boolean
siguiente
=
true
;
boolean
siguiente
=
true
;
if
(
escaleraColor
(
cartas
))
{
if
(
escaleraColor
(
cartas
))
{
...
@@ -31,7 +50,7 @@ public class Juego {
...
@@ -31,7 +50,7 @@ public class Juego {
}
}
if
(
siguiente
&&
full
(
cartas
))
{
if
(
siguiente
&&
full
(
cartas
))
{
siguiente
=
false
;
siguiente
=
false
;
System
.
out
.
println
(
"
ESCALERA COLOR
"
);
System
.
out
.
println
(
"
FULL
"
);
return
7
;
return
7
;
}
}
if
(
siguiente
&&
escalera
(
cartas
))
{
if
(
siguiente
&&
escalera
(
cartas
))
{
...
@@ -303,13 +322,13 @@ public class Juego {
...
@@ -303,13 +322,13 @@ public class Juego {
int
valor
=
0
;
int
valor
=
0
;
if
(
carta
.
equals
(
"A"
))
{
if
(
carta
.
equals
(
"A"
))
{
return
valor
=
1
;
return
valor
=
1
;
}
else
if
(
carta
.
equals
(
"T"
))
{
}
else
if
(
carta
.
equals
(
"T"
))
{
return
valor
=
10
;
return
valor
=
10
;
}
else
if
(
carta
.
equals
(
"J"
))
{
}
else
if
(
carta
.
equals
(
"J"
))
{
return
valor
=
11
;
return
valor
=
11
;
}
else
if
(
carta
.
equals
(
"Q"
))
{
}
else
if
(
carta
.
equals
(
"Q"
))
{
return
valor
=
12
;
return
valor
=
12
;
}
else
if
(
carta
.
equals
(
"K"
))
{
}
else
if
(
carta
.
equals
(
"K"
))
{
return
valor
=
13
;
return
valor
=
13
;
}
}
return
Integer
.
valueOf
(
carta
);
return
Integer
.
valueOf
(
carta
);
...
@@ -324,5 +343,86 @@ public class Juego {
...
@@ -324,5 +343,86 @@ public class Juego {
return
value
;
return
value
;
}
}
public
int
isRepetidos
(
Carta
[]
m1
,
Carta
[]
m2
)
{
Carta
[]
m3
=
new
Carta
[
10
];
Set
<
Carta
>
cartas
=
new
HashSet
<>();
int
c
=
5
;
for
(
int
i
=
0
;
i
<
m3
.
length
;
i
++)
{
if
(
i
<
5
)
{
//m3[i]=m1[i];
cartas
.
add
(
m1
[
i
]);
}
else
if
(
i
>
4
)
{
//m3[i]=m1[c];
cartas
.
add
(
m2
[
i
-
c
]);
//c++;
}
}
return
cartas
.
size
();
}
public
Carta
[]
cambiarMano1
(
Carta
[]
m1
)
{
int
max
=
3
;
int
min
=
1
;
int
range
=
max
-
min
+
1
;
int
rand
=
(
int
)
(
Math
.
random
()
*
range
)
+
min
;
if
(
rand
==
1
)
{
return
m1
=
new
Carta
[]{
new
Carta
(
"AS"
),
new
Carta
(
"2S"
),
new
Carta
(
"4S"
),
new
Carta
(
"6S"
),
new
Carta
(
"8S"
)};
}
else
if
(
rand
==
2
)
{
return
m1
=
new
Carta
[]{
new
Carta
(
"KH"
),
new
Carta
(
"2H"
),
new
Carta
(
"5C"
),
new
Carta
(
"TS"
),
new
Carta
(
"JS"
)};
}
else
{
return
m1
=
new
Carta
[]{
new
Carta
(
"JC"
),
new
Carta
(
"2H"
),
new
Carta
(
"5S"
),
new
Carta
(
"TC"
),
new
Carta
(
"JS"
)};
}
}
public
Carta
[]
cambiarMano2
(
Carta
[]
m2
)
{
int
max
=
3
;
int
min
=
1
;
int
range
=
max
-
min
+
1
;
int
rand
=
(
int
)
(
Math
.
random
()
*
range
)
+
min
;
if
(
rand
==
1
)
{
return
m2
=
new
Carta
[]{
new
Carta
(
"AK"
),
new
Carta
(
"TC"
),
new
Carta
(
"5H"
),
new
Carta
(
"TH"
),
new
Carta
(
"JH"
)};
}
else
if
(
rand
==
2
){
return
m2
=
new
Carta
[]{
new
Carta
(
"AC"
),
new
Carta
(
"6C"
),
new
Carta
(
"7H"
),
new
Carta
(
"8H"
),
new
Carta
(
"9H"
)};
}
else
{
return
m2
=
new
Carta
[]{
new
Carta
(
"TH"
),
new
Carta
(
"9C"
),
new
Carta
(
"5"
),
new
Carta
(
"TH"
),
new
Carta
(
"JH"
)};
}
}
}
}
src/MyClass.java
View file @
7fe40518
...
@@ -38,6 +38,12 @@ public class MyClass {
...
@@ -38,6 +38,12 @@ public class MyClass {
m2
[
3
]
=
new
Carta
();
m2
[
3
]
=
new
Carta
();
m2
[
4
]
=
new
Carta
();
m2
[
4
]
=
new
Carta
();
System
.
out
.
println
(
j
.
isRepetidos
(
m1
,
m2
));
if
(
j
.
isRepetidos
(
m1
,
m2
)
<
10
){
m1
=
j
.
cambiarMano1
(
m1
);
m2
=
j
.
cambiarMano2
(
m2
);
}
jugadas
.
add
(
m1
);
jugadas
.
add
(
m1
);
jugadas
.
add
(
m2
);
jugadas
.
add
(
m2
);
String
ganadores
=
mc
.
ganadores
(
jugadas
);
String
ganadores
=
mc
.
ganadores
(
jugadas
);
...
@@ -47,7 +53,12 @@ public class MyClass {
...
@@ -47,7 +53,12 @@ public class MyClass {
int
valor
=
j
.
juegosPosibles
(
Arrays
.
asList
(
m1
[
0
],
m1
[
1
]
,
m1
[
2
]
,
m1
[
3
]
,
m1
[
4
]
));
int
valor
=
j
.
juegosPosibles
(
Arrays
.
asList
(
m1
[
0
],
m1
[
1
]
,
m1
[
2
]
,
m1
[
3
]
,
m1
[
4
]
));
System
.
out
.
print
(
"Jugada 2 = "
);
System
.
out
.
print
(
"Jugada 2 = "
);
int
valor2
=
j
.
juegosPosibles
(
Arrays
.
asList
(
m2
[
0
],
m2
[
1
]
,
m2
[
2
]
,
m2
[
3
]
,
m2
[
4
]
));
int
valor2
=
j
.
juegosPosibles
(
Arrays
.
asList
(
m2
[
0
],
m2
[
1
]
,
m2
[
2
]
,
m2
[
3
]
,
m2
[
4
]
));
System
.
out
.
println
(
"GANADOR JUGADA # "
+
j
.
mano1VsMano2
(
valor
,
valor2
));
System
.
out
.
println
(
"GANADOR JUGADA # "
+
j
.
mano1VsMano2
(
valor
,
valor2
));
//Si son iguales realiza un desempate
if
(
j
.
mano1VsMano2
(
valor
,
valor2
)
==
0
){
System
.
out
.
print
(
"Desempate Gana jugada # "
);
j
.
desempateCarta
(
j
.
sumaManoValores
(
m1
),
j
.
sumaManoValores
(
m2
));
}
}
}
}
}
\ 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