Package com.poker.test

Source Code of com.poker.test.FillPlayWindow

package com.poker.test;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;

import com.poker.analyst.element.Board;
import com.poker.analyst.element.Player;
import com.poker.analyst.element.Rounds;
import com.poker.analyst.elements.state.PlayerState;
import com.poker.analyst.parse.BufferParser;
import com.poker.analyst.parse.ParserResult;
import com.poker.control.PokerControl;
import com.poker.data.PokerData;
import com.poker.ui.windows.PlayWindow;

public class FillPlayWindow {
  public static Board prerareBoard(Board board, int numAP, int numSP, int dealer,float bb){

    board.setDealer(dealer);
    int t_numAP = 1;
    int t_numSP = 1;
    if (numSP == 0 )
      t_numSP = 0;
    int t_curr  = 0;  
    List<Player> players =  board.getPlayers();
    for (int i = 0; i<10; i++){
      if (t_numAP + t_numSP <= numAP + numSP){
        players.get(i).setIsInAction(true);
        players.get(i).setStack(30*bb);
       

        if (t_numAP > numAP)
          t_curr = 1
        if (t_numSP > numSP || t_numSP == 0)
          t_curr = 0;
         
        if (t_numAP > numAP)
          t_curr = 1
        if (t_numSP > numSP)
          t_curr = 0;

       
       
        if (t_curr == 0){       
          players.get(i).setPlayerState(PlayerState.PRS_IN_ACTION);
          t_curr = 1;
          t_numAP++;
        }
        else
          if (t_curr == 1){
            players.get(i).setPlayerState(PlayerState.PRS_SITOUT);
            t_curr = 0;
            t_numSP++;
          }     
      }
      else{
        players.get(i).setPlayerState(PlayerState.PRS_NONE);
      }
    }   



    return board;
  }

  public static PlayWindow fillPlayWindow(PlayWindow playWnd, String strBuffer) throws Exception{

    PokerControl pControl = new PokerControl();
    PokerData pdata = new PokerData();
    final BufferParser bufferParser = pdata.getRoomSettings().getBufferParser("");

    // Opening buffer
    File file = new File(strBuffer);
    FileReader fr = new FileReader(file);
    char[] buffer = new char[10000];   
    fr.read(buffer);   
    strBuffer = new String(buffer);
    strBuffer = strBuffer.trim();
    //System.out.println(strBuffer);


    ParserResult     parserResult = null;
    ParserResult     parserResultPrev = null;

    Board board     = pControl.createBoardShablon(pdata);
    board       = prerareBoard(board, 10, 0, 9, 0.2f);
    board.getPlayers().get(0).setStack(6.0f);
   

    Board boardPrev = null;
    Board boardPrevNew = null;

    try {           
      parserResult = bufferParser.getParserResult(strBuffer,null);

      if (parserResult.getCurrentRound() != Rounds.PREFLOP){
        boardPrevNew = pControl.createBoardShablon(pdata);
        boardPrevNew = prerareBoard(boardPrevNew, 10, 0, 9, 0.2f);
        boardPrevNew.getPlayers().get(0).setStack(4.9f);
        switch (parserResult.getCurrentRound()) {
        case FLOP:
          parserResultPrev = bufferParser.getParserResult(strBuffer,Rounds.PREFLOP);
          break;
        case TURN:
          parserResultPrev = bufferParser.getParserResult(strBuffer,Rounds.FLOP);
          break;
        case RIVER:
          parserResultPrev = bufferParser.getParserResult(strBuffer,Rounds.TURN);
          break;       
        }        
        if (parserResultPrev == null) throw new Exception("prev buffer taking exception");
      }           
    } catch (final Exception e) {
      System.err.println("buffer taking exception");
      e.printStackTrace();
      return null;
    }
    playWnd.setCurrentRound(parserResult.getCurrentRound());
    switch(parserResult.getCurrentRound()){
      case PREFLOP :
        playWnd.setPreflopBoard(null);
        playWnd.setFlopBoard(null);
        playWnd.setTurnBoard(null);
        playWnd.setRiverBoard(null);
        break;
      case FLOP :
        boardPrev = playWnd.getPreflopBoard();
        break;
      case TURN :
        boardPrev = playWnd.getFlopBoard();
        break;
      case RIVER :
        boardPrev = playWnd.getTurnBoard();
        break;
    }

    if (parserResult.getCurrentRound() != Rounds.PREFLOP){
      for (int i = 0; i< boardPrev.getPlayers().size() ; i++)
        boardPrevNew.getPlayers().get(i).setPlayerState(boardPrev.getPlayers().get(i).getPlayerState());
      boardPrevNew.setCurrentRound(boardPrev.getCurrentRound());
    }
    if (boardPrevNew != null){
          boardPrevNew.setDealer(board.getDealer());
          //boardPrevNew = pControl.setNamesToBoard(boardPrevNew,bufferParser.getPlayersName(strBuffer));
          boardPrevNew = pControl.setParserResultsToBoard(pdata, pControl, boardPrevNew, parserResultPrev);
        }

    //board = pControl.setNamesToBoard(board,bufferParser.getPlayersName(strBuffer));                      
    board = pControl.setParserResultsToBoard(pdata, pControl, board, parserResult);




    switch(parserResult.getCurrentRound()){
    case PREFLOP :         
      break;
    case FLOP :
      playWnd.setPreflopBoard(boardPrevNew);
      break;
    case TURN :
      playWnd.setFlopBoard(boardPrevNew);
      break;
    case RIVER :
      playWnd.setTurnBoard(boardPrevNew);
      break;
   
    switch(parserResult.getCurrentRound()){
    case PREFLOP :
      playWnd.setPreflopBoard(board);
      break;
    case FLOP :
      playWnd.setFlopBoard(board);
      break;
    case TURN :
      playWnd.setTurnBoard(boardPrevNew);
      break;
    case RIVER :
      playWnd.setRiverBoard(board);
      break;
    }

    return playWnd;
  }


  public static void main(String[] args) {
    //

  }

}
TOP

Related Classes of com.poker.test.FillPlayWindow

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.