Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-20-2010, 06:03 AM   PM User | #1
CoarseCoffee
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
CoarseCoffee is an unknown quantity at this point
Java Class and Array trouble mixup.

Excuse me beforehand but I'm french so I hope this still makes sense.

I've been writting a poker program using some pre-made classes (Suits, Values, Card and CardPack), and my own main class that the whole of my own code is going to be.

So far it's all basic stiff, make 4 pools of points for the 3 npc's and the player, make an array of :

Carte[] mainO1 = {PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger()}; (which is basically Card[] handcomputer1 = {CardPack.draw()...

And it's all so far so good, the trouble arises when I try to compare the hand with itself to see if the hand as any possible poker combination is present.

So at first I had many ideas. mainly fiddling around with the Values place, but now I check my java book and every resources I have, and none get in deep enough to have examples or information on how to get an object (or class?) from an array of classes/objects (and so on).

The hand is also put in order from weakest to best card (When I place the hand in the pre-made show hand method, it shows 2 Hearts, 4 Spades, A Clubs, etc.

My big problem, in the end, is getting the values (or leaving them there and comparing them) of each of the 5 cell's and comparing them to each other to see what's what. Anyone as any imput, I hope I made myself clear enough.
CoarseCoffee is offline   Reply With Quote
Old 11-21-2010, 08:24 PM   PM User | #2
CoarseCoffee
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
CoarseCoffee is an unknown quantity at this point
Oh well nevermind, I figured one of my problem out, but now I'm faced with another (albeit smaller) one.

Code:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class TP2 {
    public static boolean paire(Carte[] main){
        boolean combo = false;
        int cpt_paire = 0;
        
        for (int i = 0; i < main.length; i++){
            for (int j = 0; j < main.length; j++){
                 if (main[i].compareTo(main[j]) == 0){
                     
                     cpt_paire++;
                     
                    }
            }
        }

        if (cpt_paire == 4){
            combo = true;
        }
        
        return combo;
    }
    public static boolean dpaire(Carte[] main){
        boolean combo = false;
        int cpt_dpaire = 0;
        
        for (int i = 0; i < main.length; i++){
            for (int j = 0; j < main.length; j++){
                 if (main[i].compareTo(main[j]) == 0){
                     
                     cpt_dpaire++;
                     
                    }
            }
        }

        if (cpt_dpaire == 8){
            combo = true;
        }
        
        return combo;
    }
    public static boolean triple(Carte[] main){
        boolean combo = false;
        int cpt_triple = 0;
        
        for (int i = 0; i < main.length; i++){
            for (int j = 0; j < main.length; j++){
                 if (main[i].compareTo(main[j]) == 0){
                     
                     cpt_triple++;
                     
                    }
            }
        }

        if (cpt_triple == 9){
            combo = true;
        }
        
        return combo;
    }
    public static boolean straight(Carte[] main){
        boolean combo = false;
        int cpt_straight = 0;
        
        if (main[0].obtenirValeur() == Valeur.AS){
            if (main[1].obtenirValeur() == Valeur.DEUX){
                cpt_straight++;
            }
            if (main[2].obtenirValeur() == Valeur.TROIS){
                cpt_straight++;
            }
            if (main[3].obtenirValeur() == Valeur.QUATRE){
                cpt_straight++;
            }
            if (main[4].obtenirValeur() == Valeur.CINQ){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                combo = true;
            }
        }else if (main[0].obtenirValeur() != Valeur.AS){
            if (main[0].obtenirValeur().valeurPlusForte() == main[1].obtenirValeur()){
                cpt_straight++;
            }
            if (main[1].obtenirValeur().valeurPlusForte() == main[2].obtenirValeur()){
                cpt_straight++;
            }
            if (main[2].obtenirValeur().valeurPlusForte() == main[3].obtenirValeur()){
                cpt_straight++;
            }
            if (main[3].obtenirValeur().valeurPlusForte() == main[4].obtenirValeur()){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                combo = true;
            }
        }
        return combo;
    }
    public static boolean flush(Carte[] main){
        boolean combo = false;
        int cpt_flush = 0;
        
        if (main[0].obtenirSuite() == main[1].obtenirSuite()){
            cpt_flush++;
        }
        if (main[1].obtenirSuite() == main[2].obtenirSuite()){
            cpt_flush++;
        }
        if (main[2].obtenirSuite() == main[3].obtenirSuite()){
            cpt_flush++;
        }
        if (main[3].obtenirSuite() == main[4].obtenirSuite()){
            cpt_flush++;
        }
        if (cpt_flush == 4){
            combo = true;
        }
        
        return combo;
    }
    public static boolean fullhouse(Carte[] main){
        boolean combo = false;
        int cpt_fullhouse = 0;
        
        for (int i = 0; i < main.length; i++){
            for (int j = 0; j < main.length; j++){
                 if (main[i].compareTo(main[j]) == 0){
                     
                     cpt_fullhouse++;
                     
                    }
            }
        }

        if (cpt_fullhouse == 13){
            combo = true;
        }
        
        return combo;
    }
     public static boolean square(Carte[] main){
        boolean combo = false;
        int cpt_square = 0;
        
        for (int i = 0; i < main.length; i++){
            for (int j = 0; j < main.length; j++){
                 if (main[i].compareTo(main[j]) == 0){
                     
                     cpt_square++;
                     
                    }
            }
        }

        if (cpt_square == 16){
            combo = true;
        }
        
        return combo;
    }
     public static boolean straightflush(Carte[] main){
        boolean combo = false;
        boolean flush = false;
        boolean straight = false;
        int cpt_flush = 0;
        int cpt_straight = 0;
        
        if (main[0].obtenirSuite() == main[1].obtenirSuite()){
            cpt_flush++;
        }
        if (main[1].obtenirSuite() == main[2].obtenirSuite()){
            cpt_flush++;
        }
        if (main[2].obtenirSuite() == main[3].obtenirSuite()){
            cpt_flush++;
        }
        if (main[3].obtenirSuite() == main[4].obtenirSuite()){
            cpt_flush++;
        }
        if (cpt_flush == 4){
            flush = true;
        }
        
        if (main[0].obtenirValeur() == Valeur.AS){
            if (main[1].obtenirValeur() == Valeur.DEUX){
                cpt_straight++;
            }
            if (main[2].obtenirValeur() == Valeur.TROIS){
                cpt_straight++;
            }
            if (main[3].obtenirValeur() == Valeur.QUATRE){
                cpt_straight++;
            }
            if (main[4].obtenirValeur() == Valeur.CINQ){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                combo = true;
            }
        }else if (main[0].obtenirValeur() != Valeur.AS){
            if (main[0].obtenirValeur().valeurPlusForte() == main[1].obtenirValeur()){
                cpt_straight++;
            }
            if (main[1].obtenirValeur().valeurPlusForte() == main[2].obtenirValeur()){
                cpt_straight++;
            }
            if (main[2].obtenirValeur().valeurPlusForte() == main[3].obtenirValeur()){
                cpt_straight++;
            }
            if (main[3].obtenirValeur().valeurPlusForte() == main[4].obtenirValeur()){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                straight = true;
            }
        }
        if ((straight == true) && (flush == true)){
            combo = true;
        }
        
        return combo;
    }
    public static boolean royalflush(Carte[] main){
        boolean combo = false;
        boolean flush = false;
        boolean straight = false;
        int cpt_as = 0;
        int cpt_flush = 0;
        int cpt_straight = 0;
        
        if (main[0].obtenirSuite() == main[1].obtenirSuite()){
            cpt_flush++;
        }
        if (main[1].obtenirSuite() == main[2].obtenirSuite()){
            cpt_flush++;
        }
        if (main[2].obtenirSuite() == main[3].obtenirSuite()){
            cpt_flush++;
        }
        if (main[3].obtenirSuite() == main[4].obtenirSuite()){
            cpt_flush++;
        }
        if (cpt_flush == 4){
            flush = true;
        }
        
        if (main[0].obtenirValeur() == Valeur.AS){
            if (main[1].obtenirValeur() == Valeur.DEUX){
                cpt_straight++;
            }
            if (main[2].obtenirValeur() == Valeur.TROIS){
                cpt_straight++;
            }
            if (main[3].obtenirValeur() == Valeur.QUATRE){
                cpt_straight++;
            }
            if (main[4].obtenirValeur() == Valeur.CINQ){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                combo = true;
            }
        }else if (main[0].obtenirValeur() != Valeur.AS){
            if (main[0].obtenirValeur().valeurPlusForte() == main[1].obtenirValeur()){
                cpt_straight++;
            }
            if (main[1].obtenirValeur().valeurPlusForte() == main[2].obtenirValeur()){
                cpt_straight++;
            }
            if (main[2].obtenirValeur().valeurPlusForte() == main[3].obtenirValeur()){
                cpt_straight++;
            }
            if (main[3].obtenirValeur().valeurPlusForte() == main[4].obtenirValeur()){
                cpt_straight++;
            }
            if (cpt_straight == 4){
                straight = true;
            }
        }
        
        if (main[4].obtenirValeur() == Valeur.AS){
            cpt_as++;
        }
        if ((straight == true) && (flush == true) && (cpt_as == 1)){
            combo = true;
        }
        
        return combo;
    }
    public static int verifiercombo(Carte[] main){
        int puissancemain = 0;
        
        if (royalflush(main[]) == true){
            
        }
        
        
        return puissancemain;
    }
    public static void main (String[] params) {
        final int MISE = 5;
        int argent_ordi1 = 100;
        int argent_ordi2 = 100;
        int argent_ordi3 = 100;
        int argent_joueur = 100;
        int cpt_pair = 0;
        int cpt_dpair = 0;
        int cpt_triple = 0;
        int cpt_straight = 0;
        int cpt_flush = 0;
        int cpt_fullhouse = 0;
        int cpt_carre = 0;
        int cpt_straightflush = 0;
        int cpt_royalflush = 0;
        int cagnotte = 0;
        boolean fin = false;
        boolean fin_deux = false;
                
        PaquetCartes.brasser();
        
        do {
            argent_ordi1 = argent_ordi1 - MISE;
            argent_ordi2 = argent_ordi2 - MISE;
            argent_ordi3 = argent_ordi3 - MISE;
            argent_joueur = argent_joueur - MISE;
            cagnotte = (MISE * 4);
            
            if (argent_ordi1 <= 0 || argent_ordi2 <= 0 || argent_ordi3 <= 0 || argent_joueur <=0 ){
                fin = true;
            }
            
            Carte[] mainO1 = {PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger()};
            Carte[] mainO2 = {PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger()};
            Carte[] mainO3 = {PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger()};
            Carte[] mainJ = {PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger(), PaquetCartes.piger()};
            
            PaquetCartes.trierMain(mainO1);
            PaquetCartes.trierMain(mainO2);
            PaquetCartes.trierMain(mainO3);
            PaquetCartes.trierMain(mainJ);
            
            
            
        }while (fin == false);
        
        
    } // main
    
} // TP2
While it's not complete yet, I'm having trouble compiling at the

if (royalflush(main[]) == true)

segment. It keeps telling me .class expected, but I don't know why. Knowing would also help me shorten my straight and royalflush methods by alot.

Anyone as a clue about that?
CoarseCoffee is offline   Reply With Quote
Old 11-21-2010, 09:42 PM   PM User | #3
CoarseCoffee
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
CoarseCoffee is an unknown quantity at this point
800 something views and no replies :/ Anyhow I got that part working too, simple silly mistake.
CoarseCoffee is offline   Reply With Quote
Reply

Bookmarks

Tags
poker. java. beginner.

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:01 AM.


Advertisement
Log in to turn off these ads.