Commit bdddb4d5 by Joel Florentin

dia 6

parents
*.class
\ No newline at end of file
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<String, Integer> 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<Carta>{
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
<html>
<head>
<title>js exercises</title>
</head>
<body>
<form>
<fieldset>
<legend>Email subscriptions</legend>
<p id="Ross">
<label for="subscribe">
<input type="checkbox" name="subscribe" id="subscribe">
Yes! I would like to receive all of you free candy!
</label>
</p>
<p id="emailPara">
<label for="email">
Email Address:
<input type="text" name="email" id="email">
</label>
</p>
</fieldset>
</form>
<script>
email = document.querySelector("#emailPara");
subscribe = document.querySelector("#subscribe");
email.style.display = "none";
subscribe.parentElement.style.backgroundColor = "blue";
function toggleEmail(){
email.style.display = document.querySelector("[name=subscribe]").checked?null:"none"
}
subscribe.addEventListener('click',toggleEmail);
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js exercises</title>
</head>
<body>
<fieldset>
<legend>Billing Information</legend>
<p>
<label for="">
Postal Address:<br>
<input type="text" name="postaladdress" id="postaladdress">
</label>
</p>
<p>
<label for="">
Home Address:<br>
<input type="checkbox" name="homepostalcheck" id="homepostalcheck">
Same as above
</label>
<br>
<input type="text" name="homeaddress" id="homeaddress">
</p>
</fieldset>
<script>
homepostalcheck = document.querySelector("#homepostalcheck");
postaladdress = document.querySelector("#postaladdress");
homeaddress = document.querySelector("#homeaddress");
function setHomeAddress(){
homeaddress.value = homepostalcheck.checked?postaladdress.value:""
}
homepostalcheck.addEventListener('change',setHomeAddress)
homeaddress.disabled = true;
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js ex3</title>
<style>
.errormsg{
color: red;
}
.hide{
display: none;
}
</style>
</head>
<body>
<form action="mailto:me@fakeemail.com">
<fieldset>
<legend>Personal details</legend>
<p>
<label for="">
Full name:
<input type="text" name="fullname" id="fullname">
</label>
</p>
<p class="errormsg hide" id="nameerrormsg">Please enter your name above</p>
<p>
<label for="">
Street adrress:
<input type="text" name="streetaddr" id="streetaddr">
</label>
</p>
<p class="errormsg hide" id="addrerrormsg">Please enter your address above</p>
</fieldset>
<input type="submit" value="Submit it!">
</form>
<script>
form = document.querySelector("form");
function checkForm(){
let fullname = document.querySelector("#fullname");
if(fullname.value.trim().length == 0){
document.querySelector("#nameerrormsg").classList.remove("hide");
}
else{
document.querySelector("#nameerrormsg").classList.add("hide");
}
let street = document.querySelector("#streetaddr");
if(street.value.trim().length == 0){
document.querySelector("#addrerrormsg").classList.remove("hide");
}
else{
document.querySelector("#addrerrormsg").classList.add("hide");
}
}
form.addEventListener("submit",checkForm)
</script>
</body>
</html>
\ No newline at end of file
<html>
<head><title></title></head>
<body>
<ul id="menu">
<li>Services</li>
</ul>
<button id="btn">Click</button>
<p id="message"></p>
<script>
let ul = document.getElementById("menu")
let li = document.createElement("li");
li.textContent = "Home";
ul.appendChild(li);
let btn = document.querySelector("#btn");
btn.addEventListener("mousedown",evt => {
let message = document.querySelector("#message")
switch (evt.button) {
case 0:
message.textContent = `${evt.button}`
break;
case 1:
message.textContent = "Middle"
break;
case 2:
message.textContent = "Right"
break;
default:
message.textContent = "Left"
break;
}
})
</script>
</body>
</html>
\ No newline at end of file
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
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