Package com.poker.main

Source Code of com.poker.main.PokerMain

package com.poker.main;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import com.poker.analyst.AnalystResult;
import com.poker.analyst.element.Board;
import com.poker.control.PokerControl;
import com.poker.data.PokerData;
import com.poker.thread.OpenWindowThread;
import com.poker.thread.PrepareWindowThread;
import com.poker.ui.robot.reaction.UIReaction;
import com.poker.ui.settings.rooms.events.EventType;
import com.poker.ui.windows.PlayWindow;

public class PokerMain {

    PokerData           pData;
    PokerControl        pControl;
    OpenWindowThread    owThread;
    PrepareWindowThread pwThread;
    long gbTimeCounter        = 0;
    long gbTimeCounterDelay   = 10*1000;
   

    public PokerMain() {
        this.pData = new PokerData();
        this.pControl = new PokerControl();
      //  this.owThread = new OpenWindowThread(this.pData, this.pControl);
      //  this.pwThread = new PrepareWindowThread(this.pData, this.pControl);
        this.pData.getProgramSettings().setDelayMainThreadMs(300);
        this.pData.getProgramSettings().setDelayOpenThreadMs(5000);
        this.pData.getProgramSettings().setDelayPrepareThreadMs(500);
    }

    public void testOutput(final Object[] obj) {

        if (obj == null) {
            System.out.println("null");
            return;
        }
        for (final Object h : obj) {
            System.out.print(h + " ");
        }
        System.out.println();

    }

    public void Run() throws InterruptedException , IOException{

        //      owThread.start();
        //      pwThread.start();

        PlayWindow currentplayWnd;
        Board board;
        AnalystResult analystResult;
        Boolean result;
        int temp;
 
        Logger logger = Logger.getLogger("General");
        FileHandler fh = new FileHandler("c:\\temp\\poker\\general.log", true);
        logger.addHandler(fh);
        logger.setLevel(Level.ALL);
        SimpleFormatter formatter = new SimpleFormatter();
        fh.setFormatter(formatter);

        Integer[] handles;
        /*int MainHandle = 7080878;
       
        temp = pControl.getProcID(pData.getRoomSettings().getProcessName());
        if (temp !=0) 
                pData.setProcID(temp);
       
        pData.setMainWnd(MainHandle,pControl.getWindowPosByHandle(MainHandle));
        */
        //              System.out.println("1: Fold, 2: Check, 3: Call, 4: Raise, 5: BuyIn, 6: SetBB, 7: WaitForBB   0: CLOSE");
        gbTimeCounter = System.currentTimeMillis();
       
        int counterForCloseEmptyWidows = 0;
        while (true) {
                if (System.currentTimeMillis() - gbTimeCounter >=gbTimeCounterDelay){
                        gbTimeCounter = System.currentTimeMillis();
                        System.gc();
                }
                counterForCloseEmptyWidows++;          
            int selector = 0;

            Thread.sleep(this.pData.getProgramSettings().getDelayMainThreadMs());
            if (this.pData.getMainWnd() == null) {
                if (this.pData.getProcID() == null) {
                    temp = this.pControl.getProcID(this.pData.getRoomSettings().getProcessName());
                    if (temp != 0) {
                        this.pData.setProcID(temp);
                    }
                }
                if (this.pData.getProcID() != null) {
                    handles = this.pControl.getOpenWindowsHandles(this.pData.getProcID());
                    this.pControl.RegMainWindow(this.pData, handles);
                }
            } else {
                handles = this.pControl.getOpenWindowsHandles(this.pData.getProcID());

                this.pControl.killDeadTablesFromPosition(this.pData, handles);
                this.pControl.updateWindowsFromWaitingList(this.pData);

                currentplayWnd = this.pControl.getPlayWindowReadyForAction(this.pData,true);
                if (currentplayWnd == null)
                        currentplayWnd = this.pControl.getPlayWindowReadyForAction(this.pData,false);
               
               
                if(counterForCloseEmptyWidows > 20){
                        counterForCloseEmptyWidows = 0;
                        try {
                                                this.pControl.getCloseEmptyWindows(this.pData);
                                        } catch (Exception e) {
                                                e.printStackTrace();
                                                continue;
                                        }
                }
               
                if (currentplayWnd != null) {
                        logger.log(Level.WARNING,currentplayWnd.getCurrentEvent().toString());
                        if (currentplayWnd.getCurrentEvent() == EventType.ET_NEED_WAIT_BB ){
                                analystResult = pControl.getReaction(pData, currentplayWnd);
                        }
                        else
                        if (currentplayWnd.getCurrentEvent() == EventType.ET_SYSTEM_MESSAGE ||
                                currentplayWnd.getCurrentEvent() == EventType.ET_SYSTEM_MESSAGE_2){
                               
                                        try {
                                                                analystResult = pControl.getReaction(pData, currentplayWnd);
                                                        } catch (Exception e) {
                                                                e.printStackTrace();
                                                                continue;
                                                        }
                        }
                        else
                        if (currentplayWnd.getCurrentEvent() == EventType.ET_SET_BB ){
                                try{
                                        currentplayWnd = pControl.fillNotFullBoardForBB(pData, currentplayWnd);
                                       
                                }catch (Exception e) {
                                        e.printStackTrace();
                                        continue;
                                                }
                               
                                analystResult = pControl.getReaction(pData, currentplayWnd);                           
                               
                        }else{                                                  
                                                                               
                       //       System.out.println(currentplayWnd.getCurrentEvent());
                            //Thread.sleep(1000);                                      
                                long time = System.currentTimeMillis();
                               
                                try{
                                        currentplayWnd = this.pControl.fillPlayWnd(this.pData, currentplayWnd);
                                }catch (Exception e) {
                                        e.printStackTrace();
                                        continue;
                                                }
                                time = System.currentTimeMillis() - time;                               
                            analystResult = pControl.getReaction(pData, currentplayWnd);
                            //logger.log(Level.WARNING,analystResult.toString());
                        }                      
                       
                    if (analystResult != null){
                        logger.log(Level.WARNING,analystResult.toString());
                        pControl.react(pData,currentplayWnd,analystResult);                    
                    }
               
                    currentplayWnd.setCurrentEvent(EventType.ET_IN_GAME);
                    continue;
                }
               
               
                if (this.pControl.isNewTableNeeds(this.pData) ) {
                    // openWindows     
                    if (this.pData.getWaitingWindowList().size() == 0 ) {
                        this.pControl.activateWindow(this.pData.getMainWnd());
                        EventType ev = this.pControl.getMainWindowEvent(this.pData, this.pControl);
                        if (ev != null) {
                        //    System.out.println(ev);
                            this.pControl.activateWindow(this.pData.getMainWnd());
                            this.pControl.react(this.pData, this.pData.getMainWnd(),
                                    new AnalystResult(UIReaction.UIR_MN_CLOSE_SYSTEM_WINDOW, null));
                        }
                        this.pControl.activateWindow(this.pData.getMainWnd());
                        this.pControl.react(this.pData, this.pData.getMainWnd(), new AnalystResult(
                                UIReaction.UIR_OPEN_WINDOW, null));
                        selector = 0;
                        while (selector < this.pData.getProgramSettings().getDelayOpenThreadMs()) {
                            selector += 500;
                            Thread.sleep(500);
                            if (handles.length < this.pControl.getOpenWindowsHandles(this.pData
                                    .getProcID()).length) {
                                break;
                            }
                            ev = this.pControl.getMainWindowEvent(this.pData, this.pControl);
                            if (ev != null) {
                              //  System.out.println(ev);
                                this.pControl.activateWindow(this.pData.getMainWnd());
                                this.pControl.react(this.pData, this.pData.getMainWnd(),
                                        new AnalystResult(UIReaction.UIR_MN_CLOSE_SYSTEM_WINDOW,
                                                null));
                              //  System.out.println("No due tables");
                                break;
                            }

                        }
                    }

                    // prepareWindows
                    handles = this.pControl.getOpenWindowsHandles(this.pData.getProcID());
                    Thread.sleep(this.pData.getProgramSettings().getDelayPrepareThreadMs());

                    result = this.pControl.updateWaitingListFromHandles(this.pData, handles);
                    result = this.pControl.isNewTableNeeds(this.pData);

                    //System.out.println("WL.size: " + pData.getWaitingWindowList().size());
                    if (result) {
                        this.pControl.analyzeOneTableFromWaitingList(this.pData, this.pControl);
                    } else {
                        this.pControl.killAllTablesFromWaitingList(this.pData, this.pControl);
                    }
                }
            }
        }
               
    }

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

        final PokerMain pMain = new PokerMain();
        /*
        Winwrk wrk = new Winwrk();     
        System.out.println(wrk.getCoords(1377570));*/

        try {
            pMain.Run();
            /*  List<EventType> qqq = new ArrayList<EventType>();
                qqq.add(EventType.ET_ACTION);
                qqq.add(EventType.ET_IN_GAME);
                qqq.add(EventType.ET_NOTHING);
                qqq.add(EventType.ET_CONFIGM_ENTERING_GAME);
                */

        } catch (final Exception e) {
            e.printStackTrace();
        }

        /*      UIRobot robot = new UIRobot();
                try {
                        robot.initRobot();
                } catch (AWTException e) {
                        //
                        e.printStackTrace();
                }
                int i = 95;
                while(i++<100000){
                System.out.println(robot.analyzePixel(10,10, new Color(0,0,0), new Color(0,0,0)));
                }*/
        /*
        OCR ocr = new OCR();
        System.out.println(ocr.showString("c:\\temp\\poker\\tmp.bmp"));
        */
    }
}
TOP

Related Classes of com.poker.main.PokerMain

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.