Commit 0589aa52 by Josebaezx

Mejora en la creacion de numeros aleatorios

parent 57e00f26
......@@ -39,7 +39,7 @@ public class Carta {
}
public void valorAleatorio(){
int max = 14;
int max = 13;
int min = 1;
int range = max - min + 1;
int rand = (int)(Math.random() * range) + min;
......@@ -56,9 +56,6 @@ public class Carta {
else if(rand==13){
this.valor="K";
}
else if(rand==14){
this.valor="A";
}
else if (rand==1) {
this.valor="A";
} else {
......
import org.w3c.dom.ls.LSOutput;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Juego {
List<Integer> valores = null;
final int MAX=3;
final int MIN=1;
final int MAX = 3;
final int MIN = 1;
public Juego() {
}
......@@ -337,74 +337,29 @@ public class Juego {
return value;
}
public int isRepetidos(Carta[] m1, Carta[] m2) {
public boolean 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) {
cartas.add(m1[i]);
m3[i] = (m1[i]);
} else if (i > 4) {
cartas.add(m2[i - c]);
}
}
return cartas.size();
}
public Carta[] cambiarMano1(Carta[] m1) {
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 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("5D"),
new Carta("TH"),
new Carta("JH")};
m3[i] = (m2[i - c]);
}
}
List<Carta> cartas = new ArrayList(Arrays.asList(m3));
List<Carta> distinctElementList = cartas.stream()
.distinct()
.collect(Collectors.toList());
if (distinctElementList.size() < 10) {
return false;
}
return true;
}
}
......@@ -26,23 +26,23 @@ public class MyClass {
MyClass mc = new MyClass();
List<Carta[]> jugadas = new ArrayList<Carta[]>();
Carta[] m1 = new Carta[5];
Carta[] m2 = new Carta[5];
boolean respuesta=false;
do {
m1[0] = new Carta();
m1[1] = new Carta();
m1[2] = new Carta();
m1[3] = new Carta();
m1[4] = new Carta();
Carta[] m2 = new Carta[5];
m2[0] = new Carta();
m2[1] = new Carta();
m2[2] = new Carta();
m2[3] = new Carta();
m2[4] = new Carta();
respuesta = j.isRepetidos(m1,m2);
}while (respuesta==false);
//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(m2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment