Package edu.villanova.studs.poker.transport

Examples of edu.villanova.studs.poker.transport.CalculateResults


        TableDataFactory tdFactory = new TableDataFactory();
        CalcEngineFactory calcFactory = new CalcEngineFactory();       
       
        //Create the objects used to store the results...
        //This is the class the holds all results (or errors) for serialization
        CalculateResults results = new CalculateResults();
        //Holds the results for each individual player if there are no errors
        PlayerResults[] playerResults;
       
        //The table data factory is responsible for deserializing the input
        //array and returning the appropriate concrete Table Data implementation
        TableDataIntf td = tdFactory.createTableData( in, flag );
       
        //The calc engine factory uses the table data instance to determine the
        //appropriate calc engine implementation to use
        calcEngine = calcFactory.createCalcEngine( td );
       
        //Set the calc engine options - do this 1st because the options may
        //affect how game data is set and processed
        calcEngine.setOtherOptions( td.getOptions() );
       
        //Use a try..catch here in case generating the results throws an error
        try {
            //Set the game data - this is the player & cards
            calcEngine.setGameData( td );
       
            //Get the calculation results and return the PlayerResults array
            playerResults = calcEngine.getCalculationResults();
           
            //Add the player results to the return object
            results.setPlayerResults( playerResults );
           
            //Serialize the results as a byte array
            return TransportUtils.getSerializedResult( results );
        } catch ( CalcEngineException e ) {
          e.printStackTrace(System.out);
            //There was an error thrown by a lower process.  Format the message
            //and assign it to the results class.  Use getLocalizedMessage() in
            //case so other engines require an extension of CalcEngineException
            results.setError( true );
            results.setErrorMessage( e.getLocalizedMessage() );
            return TransportUtils.getSerializedResult( results );
       }
    }
View Full Code Here


            return;
        }
        opts.put( CalcEngineFactory.ENGINE_PROPH_SIMS, -1 );
        td.setOptions( opts );
       
        CalculateResults results = new CalculateResults();
               
        //Object o = TransportUtils.getDeserializedResult(new CalcHandResults().getResults( td ), res.getClass() );
        results = (CalculateResults)TransportUtils.getDeserializedResult(new CalcHandResults().getResults( TransportUtils.getSerializedResult( td ), 1 ), results.getClass() );
        //Object o = TransportUtils.getDeserializedResult(new CalcHandResults().getResults( 3 ), td.getClass() );
        
        if ( results.getError() )
            System.out.println( results.getErrorMessage() );
        else
            printResults( results.getPlayerResults() );   
       

    }
View Full Code Here

    }
   
    private static void printResults( byte[] result ) {
       
        //Decode the result as an object
        CalculateResults results = new CalculateResults();
                
        results = (CalculateResults)TransportUtils.getDeserializedResult( result, results.getClass() );
        
        //Check the data type for an error (a string)
        if ( results.getError() )
            System.out.println( results.getErrorMessage() );
        else {
            PlayerResults[] res = results.getPlayerResults();
           
            for( int ii = 0; ii < res.length; ii++ ) {
                System.out.println( res[ii].toString() +
                "\n--------------------------------\n" );   
            }
View Full Code Here

   
    Hashtable <String, Object> opts = new Hashtable <String, Object> ();
    opts.put(CalcEngineFactory.ENGINE_PROPH_SIMS, 50);
    tableData.setOptions(opts);
   
    CalculateResults results = calculator.calculate(tableData);
   
    //check that results were actually returned
    assertNotNull(results);
   
    PlayerResults [] playerResults = results.getPlayerResults();
    float p1WinPct = playerResults [0].getPerfectWinPct() * 100;
    float p2WinPct = playerResults [1].getPerfectWinPct() * 100;
   
    //considering the players cards both should have about
    //a 50% chance of winning give or take 2%
View Full Code Here

   
    //call the process method
    calculateActionServlet.process(req, resp);
   
    //retrieve the results from the request
    CalculateResults results = (CalculateResults)req.getAttribute(CalculateActionServlet.REQUEST_VAR_RESULTS);
   
    //check that the results var in the request
    //was actually populated via the process method
    assertNotNull(results);
  }
View Full Code Here

   * @throws IOException
   */
  public void process(ServletRequest req, ServletResponse resp)
      throws ServletException, IOException {
   
            CalculateResults results = null;
           
            try {
                //create a calculator instance 1st because this is what sets the Locale
                CalculatorIntf calculator = CalculatorFactory.createDefaultCalculator();

                //construct the Table from the http request
    Dealer dealer = new Dealer();
    dealer.setPokerTableBuilder(new TexasHoldemTableBuilder(req));
    dealer.constructPokerTable();
     
    //calculate the results
    results = calculator.calculate(dealer.getPokerTable());
            } catch ( TransportException e ) {
          results = new CalculateResults();
    results.setError(true);
    results.setErrorMessage( e.getMessage() );
            }
       
            //store the results in the request
            req.setAttribute(REQUEST_VAR_RESULTS, results);
  }
View Full Code Here

            endPointURI = endPoint;
        }
       
  public CalculateResults calculate(TableDataIntf tableData) {
   
    CalculateResults res = new CalculateResults();

    try {
      // Use a remote proecdure call to connect to the web service
      RPCServiceClient serviceClient = new RPCServiceClient();

      // Get a reference to the service endpoint
      EndpointReference targetEPR = new EndpointReference( endPointURI );

      // Get the client options and set the target to the endpoint
      Options options = serviceClient.getOptions();
      options.setTo(targetEPR);

      // Create a qualified reference to the getResulst method of the
      // calcengine service
      QName opGetResults = new QName(QUALIFIED_CLASS_NAME, METHOD_NAME );

      // Create a serialzied byte array to pass as a service parameter
      byte[] serializedResult = TransportUtils
          .getSerializedResult(tableData);

      // Setup an array of input arguments - include the flag indicating
      // the table data contains community cards
      Object[] obInputArgs = new Object[] { serializedResult,
          TableDataFactory.TABLE_DATA_COMMUNITY };

      // Setup an array of only one return object a byte array
      Class[] returnTypes = new Class[] { byte[].class };

      // Invoke a blocking call to the service and store the results
      Object[] response = serviceClient.invokeBlocking(opGetResults,
          obInputArgs, returnTypes);

      res = (CalculateResults) TransportUtils.getDeserializedResult(
          (byte[]) response[0], res.getClass());

     
      return res;

    } catch (AxisFault af) {
      res.setError(true);
      res.setErrorMessage("REMOTE CALL ERROR: " + af.getMessage());
      return res;
    }
  }
View Full Code Here

* This class implements the hand calculation logic locally.
*/
public class CalculatorLocalImpl implements CalculatorIntf {
  public CalculateResults calculate(TableDataIntf tableData) {
   
    CalculateResults res = new CalculateResults();

    byte[] serializedResult = TransportUtils.getSerializedResult(tableData);
    CalcHandResults calcHandResults = new CalcHandResults();
    byte[] results = calcHandResults.getResults(serializedResult,
        TableDataFactory.TABLE_DATA_COMMUNITY);
    res = (CalculateResults) TransportUtils.getDeserializedResult(results, res.getClass());

 
    return res;
  }
View Full Code Here

TOP

Related Classes of edu.villanova.studs.poker.transport.CalculateResults

Copyright © 2018 www.massapicom. 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.