From bdddb4d508f5dafd48cc899eb14cdc2e767e1312 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 25 Oct 2021 11:53:50 -0300 Subject: [PATCH] dia 6 --- .gitignore | 1 + Poker.java | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ eje1.html | 38 ++++++++++++++++++++++++++++++++++++++ eje2.html | 40 ++++++++++++++++++++++++++++++++++++++++ eje3.html | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 39 +++++++++++++++++++++++++++++++++++++++ trigger.sql | 26 ++++++++++++++++++++++++++ 7 files changed, 449 insertions(+) create mode 100644 .gitignore create mode 100644 Poker.java create mode 100644 eje1.html create mode 100644 eje2.html create mode 100644 eje3.html create mode 100644 index.html create mode 100644 trigger.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5241a72 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.class \ No newline at end of file diff --git a/Poker.java b/Poker.java new file mode 100644 index 0000000..0aeca05 --- /dev/null +++ b/Poker.java @@ -0,0 +1,244 @@ +import java.util.Arrays; +import java.util.HashMap; + +public class Poker{ + final static int MANO_CAPACIDAD = 5; + final static int PALO_CAPACIDAD = Carta.valores.length;//13 + static int nroJugadas = 0; + static HashMap cadaJugada = new HashMap<>(); + public static void main(String[] args) { + Carta [] mazo = new Carta[PALO_CAPACIDAD * Color.values().length]; + int c = 0; + for (Color color : Color.values()) { + for (int i = 1; i <= PALO_CAPACIDAD; i++) { + mazo[c] = new Carta(i,color); + c++; + } + } + Carta [] mano = new Carta[MANO_CAPACIDAD]; + jugadasPosibles(0,0,mazo,mano); + System.out.println(nroJugadas); + cadaJugada.entrySet().forEach(k -> System.out.printf("%s : %.5f%%\n",k.getKey(),100*k.getValue()/(float)nroJugadas)); + } + + public static String comprobarJugada(Carta [] mano) { + Carta [] mano1 = mano.clone(); + Arrays.sort(mano1); + if (esEscaleraColor(mano1)) return "Escalera color"; + if (esPoker(mano1)) return "Poker"; + if (esFull(mano1)) return "Full"; + if (esColor(mano1)) return "Color"; + if (esEscalera(mano1)) return "Escalera"; + if (esTrio(mano1)) return "Trio"; + if (esDoblePareja(mano1)) return "Doble Pareja"; + if (esDoble(mano1)) return "Doble"; + + return "Carta Alta"; + } + + public static boolean esPoker(Carta[] mano) { + + return mano[0].getValor()==mano[mano.length-2].getValor()||mano[1].getValor()==mano[mano.length-1].getValor(); + } + + public static boolean esFull(Carta[] mano) { + int conta = 0; + int contb = 0; + int i; + for (i = 0; i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + conta++; + } + else{ + break; + } + } + for (i=i+1 ;i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + contb++; + } + else{ + break; + } + } + + + return conta*contb==2; + } + + public static boolean esTrio(Carta[] mano) { + int conta = 0; + int i; + for (i = 0; i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + conta++; + } + else{ + break; + } + } + return (conta)==2; + } + + public static boolean esDoblePareja(Carta[] mano) { + int conta = 0; + int contb = 0; + int i; + for (i = 0; i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + conta++; + } + else{ + break; + } + } + for (i=i+1 ;i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + contb++; + } + else{ + break; + } + } + + + return conta==contb&&conta==1; + } + + public static boolean esDoble(Carta[] mano) { + int conta = 0; + int i; + for (i = 0; i < mano.length-1; i++) { + if(mano[i].getValor() == mano[i+1].getValor()){ + conta++; + } + else{ + break; + } + } + return (conta)==1; + } + + public static boolean esColor(Carta[] mano) { + for (int i = 0; i < mano.length-1; i++) { + if(mano[i].getColor() != mano[i+1].getColor()) return false; + } + return true; + } + + public static boolean esEscalera(Carta[] mano) { + int cont=0; + for (int i = 1; i < mano.length-1; i++) { + if(mano[i+1].getValor()==mano[i].getValor()+1){ + cont++; + } + else{ + break; + } + } + return cont==3&&(mano[0].getValor()+12==mano[mano.length-1].getValor()||mano[1].getValor()==mano[0].getValor()+1); + + } + + + public static boolean esEscaleraColor(Carta[] mano) { + for (int i = 1; i < mano.length-1; i++) { + if(mano[i+1].getColor()!= mano[i].getColor()){ + return false; + } + } + return mano[mano.length-1].getValor()-mano[1].getValor()==3&&(mano[0].esElSiguienteDe(mano[mano.length-1])||mano[1].esElSiguienteDe(mano[0])); + } + + + + public static void jugadasPosibles(int cartaNro, int posicion, Carta [] mazo, Carta [] mano) { + if(posicion < MANO_CAPACIDAD && cartaNro <= (PALO_CAPACIDAD * Color.values().length - (MANO_CAPACIDAD-posicion))){ + mano[posicion] = mazo[cartaNro]; + if (posicion==MANO_CAPACIDAD-1) { + //comprobar_jugada + //System.out.printf("%d %d\n",cartaNro,posicion); + String tipo = comprobarJugada(mano); + int cant = cadaJugada.get(tipo)==null?0:cadaJugada.get(tipo); + cadaJugada.put(tipo, cant+1); + nroJugadas++; + } + jugadasPosibles(cartaNro+1, posicion+1, mazo, mano);//siguiente carta en la siguiente posicion + jugadasPosibles(cartaNro+1, posicion, mazo, mano);//siguiente carta en esta posicion + } + } + + +} + +class Carta implements Comparable{ + private int valor;//del 1 al 13 + private Color color; + public final static String [] valores = {"A","2","3","4","5","6","7","8","9","T","J","Q","K"}; + + public Carta(int valor, Color color) { + this.valor = valor; + this.color = color; + } + + public Color getColor() { + return color; + } + public int getValor() { + return valor; + } + public void setColor(Color color) { + this.color = color; + } + public void setValor(int valor) { + this.valor = valor; + } + + /** + * Comprueba si la carta actual es la siguiente carta con respecto a la otra carta + * @param otro la carta anterior supuestamente + * @return + */ + public boolean esElSiguienteDe(Carta otro){ + if(otro.getColor()!=this.getColor()) return false; + if(otro.valor+1==valor || (otro.valor==13&&this.valor==1)) return true; + return false; + } + + @Override + public String toString() { + return valores[valor-1] + this.color; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Carta other = (Carta) obj; + if (color != other.color) + return false; + if (valor != other.valor) + return false; + return true; + } + + @Override + public int compareTo(Carta o) { + return this.getValor() - o.getValor(); + + } + + +} + + +enum Color{ + S,C,H,D; + + + +} \ No newline at end of file diff --git a/eje1.html b/eje1.html new file mode 100644 index 0000000..df6ad94 --- /dev/null +++ b/eje1.html @@ -0,0 +1,38 @@ + + + js exercises + + +
+
+ Email subscriptions +

+ +

+

+ +

+
+ +
+ + + \ No newline at end of file diff --git a/eje2.html b/eje2.html new file mode 100644 index 0000000..7fb6a1c --- /dev/null +++ b/eje2.html @@ -0,0 +1,40 @@ + + + + + + + js exercises + + +
+ Billing Information + +

+ +

+

+ +
+ +

+
+ + + \ No newline at end of file diff --git a/eje3.html b/eje3.html new file mode 100644 index 0000000..16ae3d0 --- /dev/null +++ b/eje3.html @@ -0,0 +1,61 @@ + + + + + + + js ex3 + + + +
+
+ Personal details +

+ +

+

Please enter your name above

+

+ +

+

Please enter your address above

+
+ +
+ + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..20a0404 --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + + + +

+ + + \ No newline at end of file diff --git a/trigger.sql b/trigger.sql new file mode 100644 index 0000000..fa6ea3f --- /dev/null +++ b/trigger.sql @@ -0,0 +1,26 @@ +create table registro_inventory( + film_id integer, + store_id integer, + FOREIGN KEY (film_id) + REFERENCES film (film_id), + FOREIGN KEY (store_id) + REFERENCES store (store_id) +); + +CREATE OR REPLACE FUNCTION inventory_update() + RETURNS TRIGGER + LANGUAGE PLPGSQL + AS +$$ +BEGIN + + INSERT INTO registro_inventory(film_id,store_id) + VALUES(OLD.film_id,OLD.store_id); +END; +$$ + +CREATE TRIGGER inventory_log + AFTER UPDATE + ON inventory + FOR EACH ROW + EXECUTE PROCEDURE inventory_update(); \ No newline at end of file -- libgit2 0.26.0