Package edu.villanova.studs.poker.transport

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


        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);
View Full Code Here


  public static TableDataIntf buildTableData(ServletRequest req) throws TransportException {
   
            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
      boolean stop = false;
      for (int i = 1; !stop && i <= 5; i++) {
              tmpCard = convertValueToCard(req.getParameter(getCommunityParamName(i)));
              if (tmpCard.getRank() != TransportUtils.UNKNOWN
                              && tmpCard.getSuit() != TransportUtils.UNKNOWN) {
                      communityCards.add(tmpCard);
              }
      }
      table.setCommunity(communityCards);
      tableData.setGameTable(table);
View Full Code Here

            return tableData;
  }

  private static Card convertValueToCard(String value) throws TransportException  {
    System.out.println("TableDataBuilder.convertValueToCard");
    Card card = new Card();

    if (value != null && !"".equals(value)
        && (value.length() == 2 || value.length() == 3)) {
      String suit = value.substring(0, 1);
      String rank = value.substring(1, value.length());

      if (REQ_PARAM_SUIT_DIAMONDS.equals(suit)) {
        card.setSuit(TransportUtils.DIAMONDS);
      } else if (REQ_PARAM_SUIT_CLUBS.equals(suit)) {
        card.setSuit(TransportUtils.CLUBS);
      } else if (REQ_PARAM_SUIT_SPADES.equals(suit)) {
        card.setSuit(TransportUtils.SPADES);
      } else if (REQ_PARAM_SUIT_HEARTS.equals(suit)) {
        card.setSuit(TransportUtils.HEARTS);
      }

      if (REQ_PARAM_RANK_TWO.equals(rank)) {
        card.setRank(TransportUtils.TWO);
      } else if (REQ_PARAM_RANK_THREE.equals(rank)) {
        card.setRank(TransportUtils.THREE);
      } else if (REQ_PARAM_RANK_FOUR.equals(rank)) {
        card.setRank(TransportUtils.FOUR);
      } else if (REQ_PARAM_RANK_FIVE.equals(rank)) {
        card.setRank(TransportUtils.FIVE);
      } else if (REQ_PARAM_RANK_SIX.equals(rank)) {
        card.setRank(TransportUtils.SIX);
      } else if (REQ_PARAM_RANK_SEVEN.equals(rank)) {
        card.setRank(TransportUtils.SEVEN);
      } else if (REQ_PARAM_RANK_EIGHT.equals(rank)) {
        card.setRank(TransportUtils.EIGHT);
      } else if (REQ_PARAM_RANK_NINE.equals(rank)) {
        card.setRank(TransportUtils.NINE);
      } else if (REQ_PARAM_RANK_TEN.equals(rank)) {
        card.setRank(TransportUtils.TEN);
      } else if (REQ_PARAM_RANK_JACK.equals(rank)) {
        card.setRank(TransportUtils.JACK);
      } else if (REQ_PARAM_RANK_QUEEN.equals(rank)) {
        card.setRank(TransportUtils.QUEEN);
      } else if (REQ_PARAM_RANK_KING.equals(rank)) {
        card.setRank(TransportUtils.KING);
      } else if (REQ_PARAM_RANK_ACE.equals(rank)) {
        card.setRank(TransportUtils.ACE);
      }
    }

    return card;
  }
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);
View Full Code Here

    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);
    assertEquals(card.getSuit(), TransportUtils.CLUBS);
  }
View Full Code Here

            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);
View Full Code Here

            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);
View Full Code Here

        //Try and run the engine with an invalid player configuration
        try {
            //Add a player with no cards
            td.addPlayer( p );
            //Add one card after
            td.returnPlayer(0).addCard( new Card( 1, 1 ) );
            //Attempt to setup the engine with the invalid player data
            proph.setGameData( td );
        } catch (TransportException e) {
            fail( "An unexpeced error occured while setting up the SetGameData player Test: " + e.getMessage() );
        } catch (CalcEngineException e ) {
            //Test overriden version of getLocalizedMessage()
            assertTrue("Unexpected Error Message for English Failed card setting", e.getLocalizedMessage().equals( "ERROR: Setting up game data failed while Setting player cards <br>CAUSE: " + e.getCause() ) );
        }
       
        //Now try and run the engine with an invalid community configuration
        try {
            //Add another valid card to the existing player so that part passes
            td.returnPlayer(0).addCard( new Card( 2, 2 ) );
           
            //Create an invalid table by adding 3 cards and removing one
            cards.add( new Card() );
            cards.add( new Card() );
            cards.add( new Card() );
            Table t = new Table();
           
            t.addCard( cards );
            t.removeCard(0);
            td.setGameTable( t );
View Full Code Here

        try {
            //Add a player with no cards
            p.clearCards();
            td.addPlayer( p );
            //Add one card after
            td.returnPlayer(0).addCard( new Card( 1, 1 ) );
            //Attempt to setup the engine with the invalid player data
            proph.setGameData( td );
        } catch (TransportException e) {
            fail( "An unexpeced error occured while setting up the SetGameData player Test: " + e.getMessage() );
        } catch (CalcEngineException e ) {
            //Test overriden version of getLocalizedMessage()
            assertTrue("Unexpected Error Message for German Failed card setting", e.getLocalizedMessage().equals( "FEHLER: Konfiguration des Spiels konnte nicht w�hrend der Zuordnung von Spiel-Karten f�r jeden Spieler <br>URSACHE: " + e.getCause() ) );
        }
       
        //Now try and run the engine with an invalid community configuration
        try {
            //Add another valid card to the existing player so that part passes
            td.returnPlayer(0).addCard( new Card( 2, 2 ) );
           
            //Create an invalid table by adding 3 cards and removing one
            cards.clear();
            cards.add( new Card() );
            cards.add( new Card() );
            cards.add( new Card() );
            Table t = new Table();
           
            t.addCard( cards );
            t.removeCard(0);
            td.setGameTable( t );
View Full Code Here

    this.req = req;
  }
 
  @Override
  public void buildCommunity() throws TransportException  {
    Card card = null;
    Table table = new Table();
    ArrayList<Card> communityCards = new ArrayList<Card>();

    for (int i = 1; i <= 5; i++) {
      card = convertValueToCard(req.getParameter("cc" + i));
      if (card.getRank() != TransportUtils.UNKNOWN
          && card.getSuit() != TransportUtils.UNKNOWN) {       
        communityCards.add(card);
               
        if (communityCards.size() != i) {
                                    throw new TransportException( PokerMessages.COMM_ORDER );
        }       
View Full Code Here

TOP

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

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.