Package com.poker.analyst.strategy

Source Code of com.poker.analyst.strategy.Strategy

package com.poker.analyst.strategy;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

import com.poker.analyst.AnalystResult;
import com.poker.analyst.element.Board;
import com.poker.analyst.element.Hand;
import com.poker.analyst.element.Rounds;
import com.poker.analyst.elements.state.HeroActionOnTurn;
import com.poker.analyst.strategy.temp.ActionBeforePlay;
import com.poker.ui.robot.reaction.UIReaction;
import com.poker.utils.FloatEx;
import com.poker.utils.StringEx;

public abstract class Strategy {
  protected Map<Integer,List<Hand>> handSets = new HashMap<Integer,List<Hand>>()
 
  public abstract void initHandSets()
 
 
  String heroName;
 
  public Strategy(String heroName) {
    this.heroName = heroName;
    initHandSets();
  }

  public abstract boolean maySitToTable(DataForStrategy dfs);


  public AnalystResult getReaction(DataForStrategy dfs){   
   
    if (dfs.getCurrentRound() == Rounds.PREFLOP){
      ActionBeforePlay abp = getPreparedAction(dfs);
      if (abp == ActionBeforePlay.ABP_CLOSEWINDOW){
        return new AnalystResult(UIReaction.UIR_CLOSE_WINDOW, "");
      }
    }
     
   
    switch (dfs.getCurrentRound()) {
    case PREFLOP:     
      return adaptResult(getPreFlopReaction(dfs),dfs);
    case FLOP:     
      return adaptResult(getFlopReaction(dfs),dfs);
    case TURN:     
      return adaptResult(getTurnReaction(dfs),dfs);
    case RIVER:     
      return adaptResult(getRiverReaction(dfs),dfs);
    default:
      return null;
    }           
  }
  public AnalystResult adaptResult(AnalystResult analystResult,DataForStrategy dfs) {
    AnalystResult result = analystResult;
   
 
    if (analystResult == null){
      System.err.println("ZERO ANSWER!!!!");
      return null;
    }
    String surrogate = analystResult.getSurrogate();
   
    Board board       = dfs.getCurrentBoard();
    float playerBet   = board.getPlayers().get(board.getHero()).getBet();
   
    
    if (analystResult.getReaction() == UIReaction.UIR_ACTION_CHECK){
      // TODO check
      board.setHeroActionOnTurn(HeroActionOnTurn.HAOT_CHECK);     
    }else
    if (analystResult.getReaction() == UIReaction.UIR_ACTION_FOLD){
      // TODO fold
      if (!surrogate.equals("ONLYFOLD") && FloatEx.equals(board.needAmountToCall(), 0, 0.001f)){
        board.setHeroActionOnTurn(HeroActionOnTurn.HAOT_CHECK);
        result = new AnalystResult(UIReaction.UIR_ACTION_CHECK, "");
      }     
      if (surrogate.equals("ONLYFOLD"))
        System.out.println("ONLYFOLD");
    }
    else
    if (analystResult.getReaction() == UIReaction.UIR_ACTION_RAISE){
      Float ft = Float.parseFloat(surrogate);
      //board.setHeroActionOnTurn(HeroActionOnTurn.HAOT_RAISE);
     
      if (FloatEx.gt4(board.needAmountToCall(), ft) ||
          FloatEx.equals4(board.needAmountToCall(), ft)){
        board.setHeroActionOnTurn(HeroActionOnTurn.HAOT_CALL);
        result = new AnalystResult(UIReaction.UIR_ACTION_CALL, "");
      }else
      if (FloatEx.equals4(ft, board.getPlayers().get(board.getHero()).getStack())){
        //result = new AnalystResult(UIReaction.UIR_ACTION_RAISE, StringEx.float2str2(ft + board.needAmountToCall()));               
        result = new AnalystResult(UIReaction.UIR_ACTION_ALLIN, StringEx.float2str2(ft + board.needAmountToCall()));
      }     
    }
    else
    if (analystResult.getReaction() == UIReaction.UIR_ACTION_CALL){     
      board.setHeroActionOnTurn(HeroActionOnTurn.HAOT_CALL);
    }   
   
    return result;
  }
 
  public abstract AnalystResult getPreFlopReaction(DataForStrategy dfs);
  public abstract AnalystResult getFlopReaction(DataForStrategy dfs);
  public abstract AnalystResult getTurnReaction(DataForStrategy dfs);
  public abstract AnalystResult getRiverReaction(DataForStrategy dfs)
 
  public abstract AnalystResult isNeedRebuy(DataForStrategy dfs);

  public Map<Integer, List<Hand>> getHandSets() {
    return handSets;
  }

  public void setHandSets(Map<Integer, List<Hand>> handSets) {
    this.handSets = handSets;
  }

  public boolean checkHandForHSet(Hand hand, int set){
    if (set == 0) return false;
   
    List<Hand> list = getHandSets().get(new Integer(set));
    for (Hand thand : list)
      if (hand.equals(thand)) return true;
     
    return false;   
   
  }
  public abstract ActionBeforePlay getPreparedAction(DataForStrategy dfs);
 
 

}
TOP

Related Classes of com.poker.analyst.strategy.Strategy

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.