Package com.poker.analyst.analyser.combanalyzer

Source Code of com.poker.analyst.analyser.combanalyzer.FlushAnalyzer

package com.poker.analyst.analyser.combanalyzer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;


import com.poker.analyst.analyser.CardComparator;
import com.poker.analyst.combination.FourOfKind;
import com.poker.analyst.combination.ThreeOfKind;
import com.poker.analyst.combination.Flush;
import com.poker.analyst.element.Card;
import com.poker.analyst.element.CardFace;
import com.poker.analyst.element.CardPositionType;
import com.poker.analyst.element.PlayingCards;
import com.poker.analyst.element.Suit;



public class FlushAnalyzer {
  public static List<Flush> analyseFlush(PlayingCards plCards){
    Set<Card> allCards = new TreeSet<Card>(new CardComparator());
    for (Card card: plCards.getPlayerCards())
      if (card != null) allCards.add(card);
    for (Card card: plCards.getTableCards())
      if (card != null) allCards.add(card);
   
    return analyseFlush(allCards, plCards);
  }
  public static List<Flush> analyseFlushDraw(PlayingCards plCards){
    Set<Card> allCards = new TreeSet<Card>(new CardComparator());
    for (Card card: plCards.getPlayerCards())
      if (card != null) allCards.add(card);
    for (Card card: plCards.getTableCards())
      if (card != null) allCards.add(card);
   
    return analyseFlushDraw(allCards, plCards);
  }
  public static List<Flush> analyseFlush(Set<Card> allCards, PlayingCards plCards){   
    Flush        comb       = null;
    List<Flush>     combinations = null;         
    List<Card>       combinationList;     
    Set<Card> allFlushCards       = null;
   
    int diamonds = 0;
    int clubs    = 0;
    int spades   = 0;
    int hearts   = 0;
   
    int count   = 0;
    Suit flushSuit = null;
   
    for (Card card: allCards){
      switch (card.getSuit()) {
        case clubs:    clubs++;  break;
        case diamonds:  diamonds++;  break;
        case spades:  spades++;  break;
        case hearts:  hearts++;   break;
        default:          break;   
      }
    }
    count = Math.max(Math.max(clubs, diamonds),Math.max(spades, hearts));   
    if (clubs    >= 5) flushSuit = Suit.clubs;
    else
    if (diamonds >= 5) flushSuit = Suit.diamonds;
    else
    if (spades    >= 5) flushSuit = Suit.spades;
    else
    if (hearts    >= 5) flushSuit = Suit.hearts;   
   
   
    int i = 0;
    Card firstCard = null;
    if (count >= 5){
      combinations = new ArrayList<Flush>();
     
      allFlushCards = new TreeSet<Card>(new CardComparator());
      for (Card card: allCards){
        if (card.getSuit().equals(flushSuit))
          allFlushCards.add(card);
      }     
     
      do{
        comb = new Flush();
        combinationList = new ArrayList<Card>();
        i = 0;
        firstCard = null;
        for (Card card: allFlushCards){
          if (i++ >4) break;
          if (firstCard == null)
            firstCard = card;
         
          combinationList.add(card);
         
        }         
        comb.setCombinationList(combinationList);   
        combinations.add(comb);
       
       
        allFlushCards.remove(firstCard);
      }while(allFlushCards.size() >=5 );
    }
   
    return combinations;
  }
  public static List<Flush> analyseFlushDraw(Set<Card> allCards, PlayingCards plCards){   
    Flush        comb       = null;
    List<Flush>     combinations = null;         
    List<Card>       combinationList;     
    Set<Card> allFlushCards       = null;
   
    int diamonds = 0;
    int clubs    = 0;
    int spades   = 0;
    int hearts   = 0;
   
    int count   = 0;
    Suit flushSuit = null;
   
    for (Card card: allCards){
      switch (card.getSuit()) {
        case clubs:    clubs++;  break;
        case diamonds:  diamonds++;  break;
        case spades:  spades++;  break;
        case hearts:  hearts++;   break;
        default:          break;   
      }
    }
    count = Math.max(Math.max(clubs, diamonds),Math.max(spades, hearts));   
    if (clubs    == 4) flushSuit = Suit.clubs;
    else
    if (diamonds == 4) flushSuit = Suit.diamonds;
    else
    if (spades    == 4) flushSuit = Suit.spades;
    else
    if (hearts    == 4) flushSuit = Suit.hearts;   
   
   
    int i = 0;
    Card firstCard = null;
    if (count == 4){
      combinations = new ArrayList<Flush>();
     
      allFlushCards = new TreeSet<Card>(new CardComparator());
      for (Card card: allCards){
        if (card.getSuit().equals(flushSuit))
          allFlushCards.add(card);
      }     
     
      do{
        comb = new Flush();
        combinationList = new ArrayList<Card>();
        i = 0;
        firstCard = null;
        for (Card card: allFlushCards){
          if (i++ >3) break;
          if (firstCard == null) firstCard = card;
          combinationList.add(card);
         
        }         
        comb.setCombinationList(combinationList);   
        combinations.add(comb);
       
        allFlushCards.remove(firstCard);
      }while(allFlushCards.size() >=4 );
    }   
    return combinations;
  }
}
TOP

Related Classes of com.poker.analyst.analyser.combanalyzer.FlushAnalyzer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.