From 7dcf18ae927974d7315bb2f52b8a8baf12a32609 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 25 Oct 2021 15:38:14 -0300 Subject: [PATCH] fixed poker probability --- Poker.java | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Poker.java b/Poker.java index 0aeca05..7c6cfae 100644 --- a/Poker.java +++ b/Poker.java @@ -67,56 +67,62 @@ public class Poker{ } public static boolean esTrio(Carta[] mano) { - int conta = 0; + int conta = 0,max=0; int i; for (i = 0; i < mano.length-1; i++) { if(mano[i].getValor() == mano[i+1].getValor()){ conta++; } else{ - break; + conta = 0; } + if(conta>max)max=conta; } - return (conta)==2; + return (max)==2; } public static boolean esDoblePareja(Carta[] mano) { - int conta = 0; - int contb = 0; + int conta = 0,maxa=0; + int contb = 0, maxb=0; int i; for (i = 0; i < mano.length-1; i++) { if(mano[i].getValor() == mano[i+1].getValor()){ conta++; } else{ - break; + conta = 0; } + if(conta>maxa)maxa=conta; + if(maxa==1) break; } for (i=i+1 ;i < mano.length-1; i++) { if(mano[i].getValor() == mano[i+1].getValor()){ contb++; } else{ - break; + contb = 0; } + if(contb>maxb)maxb=contb; + } - return conta==contb&&conta==1; + return maxa==maxb&&maxb==1; } public static boolean esDoble(Carta[] mano) { - int conta = 0; + int conta = 0,max=0; int i; for (i = 0; i < mano.length-1; i++) { if(mano[i].getValor() == mano[i+1].getValor()){ conta++; } else{ - break; + conta = 0; } + if(conta>max)max=conta; } - return (conta)==1; + return (max)==1; } public static boolean esColor(Carta[] mano) { -- libgit2 0.26.0