Package edu.villanova.studs.poker.transport

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


     *        have cards or not as well as have folded or not
     */
    private void setPlayerCards( ArrayList<Player> pls ) {
        //Variables to store data in types used by the calc engine
        HoleCards cards;
        Player player;
       
        //Set the total players in the hand (folder or not)
        totalPlayers = pls.size();
       
        //Create the HoleCards array used by the engine
        playerCards = new HoleCards[ totalPlayers ];
       
        //Loop through each player in the ArrayList, create a HoleCards object
        //for them, set their cards & state then add to the prcessing array
        //used by the calc engine
        for ( int ii = 0; ii < totalPlayers; ii++ ) {
            //Get the next player from the list
            player = pls.get(ii);
           
            //Check if the player is active (cards in their hand)
            if ( player.isActive() ) {
                //The player is active, create a HoleCards class for them and
                //assign their cards using the data from the input
                cards = new HoleCards( new Card( player.getCard(0).getRank(),
                                                 player.getCard(0).getSuit() ),
                                       new Card( player.getCard(1).getRank(),
                                                 player.getCard(1).getSuit() ) );
               
                //Check if the player has folded
                if ( player.getFolded() )
                    //This defaults to false, so only set if they have folded
                    cards.setFolded( true );
                else
                    //Haven't folded, inc the # of active players
                    activePlayers++;
View Full Code Here


       
        TableDataIntf td = new TableDataCommunity();
        Hashtable<String, Object> opts = new Hashtable<String, Object>();
        Locale.setDefault( Locale.GERMAN );
        try {
            Player p = new Player();
            p.addCard( new Card(1,1) );
            p.addCard( new Card(1,2) );
            td.addPlayer( p );
            td.addPlayer( new Player() );
        } catch (TransportException e) {
          e.printStackTrace(System.out);
            CalcEngineException ex = new CalcEngineException( "My message" , e);
            System.out.println(ex.getLocalizedMessage( Locale.GERMAN) );
            return;
View Full Code Here

   
            TableDataCommunity tableData = new TableDataCommunity();
            Table table = new Table();
            ArrayList<Card> communityCards = new ArrayList<Card>();
            Card tmpCard = null;
            Player tmpPlayer = null;
            String playerFold = null;

      int numOfPlayers = Integer.parseInt(req.getParameter(REQ_PARAM_NUM_PLAYERS));
      // loop through all the players
      for (int i = 1; i <= numOfPlayers; i++) {
              tmpPlayer = new Player();
              tmpCard = convertValueToCard(req.getParameter(getPlayerParamName(i, 1)));
              if (tmpCard.getRank() != TransportUtils.UNKNOWN
                              && tmpCard.getSuit() != TransportUtils.UNKNOWN) {
                      tmpPlayer.addCard(tmpCard);
              }

              tmpCard = convertValueToCard(req.getParameter(getPlayerParamName(i, 2)));
              if (tmpCard.getRank() != TransportUtils.UNKNOWN
                              && tmpCard.getSuit() != TransportUtils.UNKNOWN) {
                      tmpPlayer.addCard(tmpCard);
              }
             
              playerFold = req.getParameter(getPlayerFoldParamName(i));
              tmpPlayer.setFolded(REQ_VALUE_FOLD.equals(playerFold));

              tableData.addPlayer(tmpPlayer);
      }

      // loop through the community cards
View Full Code Here

    ((TableDataCommunity) pokerTable).setGameTable(table);
  }

  @Override
  public void buildSeats() throws TransportException {
    Player player = null;
    int num;
    try {
                    num = Integer.parseInt(req.getParameter(PARAM_NUM_PLAYERS));
    } catch( Exception e ) {
                    num = 1;
    }
   
    for (int i = 0; i < num; i++) {
      player = new Player();
      pokerTable.addPlayer(player);
    }
  }
View Full Code Here

  }

  @Override
  public void buildDealtHands() throws TransportException {
    List<Player> players = pokerTable.getPlayers();
    Player player = null;
    Card card = null;
    String playerFold = null;
    int numActive = 0;
    for (int i = 1; i <= players.size(); i++) {
      player = players.get(i - 1);
      card = convertValueToCard(req.getParameter("p" + i + "c1"));
      if (card.getRank() != TransportUtils.UNKNOWN
          && card.getSuit() != TransportUtils.UNKNOWN) {
        player.addCard(card);
      }

      card = convertValueToCard(req.getParameter("p" + i + "c2"));
      if (card.getRank() != TransportUtils.UNKNOWN
          && card.getSuit() != TransportUtils.UNKNOWN) {
        player.addCard(card);
      }

     
      if (player.getCards().size() == 1) {
          //Player has invalid number of cards in hand
          throw new TransportException( PokerMessages.PLAYER_CARDS,
                                        new Object[] { i, 1, 2} );
      }
     
      playerFold = req.getParameter("p" + i + "fold");
      player.setFolded(REQ_VALUE_FOLD.equals(playerFold));
     
      if(player.isActive() && !player.getFolded()) {
        numActive++;
      }
    }
               
                if ( numActive == 0 )
View Full Code Here

  @Test
  public void calculate() throws Exception {
    CalculatorIntf calculator = new CalculatorLocalImpl();
    TableDataIntf tableData = new TableDataCommunity();
    Player p1 = new Player(), p2 = new Player();
    Card p1c1 = new Card(TransportUtils.ACE, TransportUtils.SPADES),
      p1c2 = new Card(TransportUtils.TWO, TransportUtils.SPADES),
      p2c1 = new Card(TransportUtils.ACE, TransportUtils.HEARTS),
      p2c2 = new Card(TransportUtils.TWO, TransportUtils.HEARTS);
   
    p1.addCard(p1c1);
    p1.addCard(p1c2);
   
    p2.addCard(p2c1);
    p2.addCard(p2c2);
   
    tableData.addPlayer(p1);
    tableData.addPlayer(p2);
   
    Hashtable <String, Object> opts = new Hashtable <String, Object> ();
View Full Code Here

    //test the number of players
    List <Player> players = tableData.getPlayers();
    assertEquals(players.size(), 2);
   
    //test the number of cards for player 1
    Player p = players.get(0);
    List <Card> cards = p.getCards();
    assertEquals(cards.size(), 2);

    //test the rank and suit of player 1's first card
    Card card = cards.get(0);
    assertEquals(card.getRank(), TransportUtils.EIGHT);
View Full Code Here

        super(sTestName);

        td = new TableDataCommunity();
        proph = new CalcEngineProphesier();
        cards = new ArrayList<Card>();
        p = new Player();
    }
View Full Code Here

            opts.put( CalcEngineFactory.ENGINE_PROPH_SIMS, 0 );
            td.setOptions(opts);
           
            //add 2 players to the game
            td.clearPlayers();
            p = new Player();
            p.addCard( new Card(3,3) );
            p.addCard( new Card(4,4) );
            td.addPlayer( p );
            p = new Player();
            p.addCard( new Card(1,2) );
            p.addCard( new Card(4,3) );
            td.addPlayer( p );
           
            //setup the table data so configuration will pass (execution will fail with dup card on the table)           
            Table t = new Table();
           
            td.setGameTable( t );
           
            proph.setOtherOptions( opts );
            proph.setGameData(td);
           
            proph.getCalculationResults();
           
        } catch (TransportException e) {
            fail( "An unexpeced error occured while setting up the GetCalculationResults multi-player Test: " + e.getMessage() );
        } catch (CalcEngineException e ) {
            //Test overriden version of getLocalizedMessage()
            assertTrue("Unexpected Error Message for English multi-player failure", e.getLocalizedMessage().equals( "ERROR: Calculating hand results failed while Running multi-player simulations<br>CAUSE: " + e.getCause() ) );
        }
       
        //Single-player simulation failure
        try {
            //Create a valid # of simulations in the options
            opts.put( CalcEngineFactory.ENGINE_PROPH_SIMS, 10000 );
            td.setOptions(opts);
           
            //add only 1 player to the game - will cause single player failure
            td.clearPlayers();
            p = new Player();
            p.addCard( new Card(3,3) );
            p.addCard( new Card(4,4) );
            td.addPlayer( p );
            p = new Player();
            proph = new CalcEngineProphesier();
            proph.setOtherOptions( opts );
            proph.setGameData(td);
           
            proph.getCalculationResults();
View Full Code Here

            opts.put( CalcEngineFactory.ENGINE_PROPH_SIMS, 0 );
            td.setOptions(opts);
           
            //add 2 players to the game
            td.clearPlayers();
            p = new Player();
            p.addCard( new Card(3,3) );
            p.addCard( new Card(4,4) );
            td.addPlayer( p );
            p = new Player();
            p.addCard( new Card(1,2) );
            p.addCard( new Card(4,3) );
            td.addPlayer( p );
           
            //setup the table data so configuration will pass (execution will fail with dup card on the table)           
            Table t = new Table();
           
            td.setGameTable( t );
           
            proph.setOtherOptions( opts );
            proph.setGameData(td);
           
            proph.getCalculationResults();
           
        } catch (TransportException e) {
            fail( "An unexpeced error occured while setting up the German GetCalculationResults multi-player Test: " + e.getMessage() );
        } catch (CalcEngineException e ) {
            //Test overriden version of getLocalizedMessage()
            assertTrue("Unexpected Error Message for German multi-player failure", e.getLocalizedMessage().equals( "FEHLER: Berechnung der Ergebnisse konnte nicht w�hrend Ausf�hren von Multi-Player-Simulationen<br>URSACHE: " + e.getCause() ) );
        }
       
        //Single-player simulation failure
        try {
            //Create a valid # of simulations in the options
            opts.put( CalcEngineFactory.ENGINE_PROPH_SIMS, 10000 );
            td.setOptions(opts);
           
            //add only 1 player to the game - will cause single player failure
            td.clearPlayers();
            p = new Player();
            p.addCard( new Card(3,3) );
            p.addCard( new Card(4,4) );
            td.addPlayer( p );
            p = new Player();
            proph = new CalcEngineProphesier();
            proph.setOtherOptions( opts );
            proph.setGameData(td);
           
            proph.getCalculationResults();
View Full Code Here

TOP

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

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.