Example #1
0
  public static void main(String[] args) {
    // Use the Game's template method play() to demonstrate a defined way of playing game.
    Game game = new Football();
    game.play();

    game = new Cricket();
    game.play();
  }
 private void playGameWrapException(Game game) {
   try {
     game.play();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Example #3
0
 @Test
 public void testPlay() {
   assert game.isNew();
   assertTrue("server in game", game.players().has(server));
   assertTrue("receiver in game", game.players().has(receiver));
   game.play();
   assert game.isOver();
 }
  public static void main(String[] args) {
    BoardTests.runTests();

    // beginner vs human
    Game.play(new Advanced(), new HumanPlayer());

    // beginner vs master for 50 games
    Game.Tournament(new Beginner(), new Master(), 50);

    //         Game.Tournament(new Advanced(), new Beginner(), 50);
    //        Game.Tournament(new Master(), new Advanced(), 10);
    //        Game.Tournament(new Advanced(), new Master(), 10);
  }
  @Test
  public void doPost_shouldPopulateResponseWithCorrectData_whenServletPathIsPlayHumanVsRobot()
      throws ServletException, IOException, JSONException {
    // Setup
    Gesture expectedHumanGesture = Gesture.PAPER;
    Gesture expectedRobot3Gesture = Gesture.ROCK;
    int expectedHumanScore = 5;
    int expectedRobot3Score = 10;
    Result expectedResult = Result.PLAYER1;
    when(request.getServletPath()).thenReturn(PATH_HUMAN_VS_ROBOT);
    when(session.getAttribute(KEY_HUMAN_PLAYER)).thenReturn(humanPlayer);
    when(session.getAttribute(KEY_ROBOT3)).thenReturn(robot3);
    when(humanPlayer.getGesture()).thenReturn(expectedHumanGesture);
    when(robot3.getGesture()).thenReturn(expectedRobot3Gesture);
    when(humanPlayer.getScore()).thenReturn(expectedHumanScore);
    when(robot3.getScore()).thenReturn(expectedRobot3Score);
    when(game.play(humanPlayer, robot3)).thenReturn(expectedResult);

    // Test
    gameServlet.doPost(request, response);

    // Verify
    verify(writer).print(captorJson.capture());
    assertEquals(
        "Response is not as expected",
        expectedHumanGesture,
        captorJson.getValue().get(KEY_PLAYER1_GESTURE));
    assertEquals(
        "Response is not as expected",
        expectedRobot3Gesture,
        captorJson.getValue().get(KEY_PLAYER2_GESTURE));
    assertEquals(
        "Response is not as expected",
        expectedHumanScore,
        captorJson.getValue().get(KEY_PLAYER1_SCORE));
    assertEquals(
        "Response is not as expected",
        expectedRobot3Score,
        captorJson.getValue().get(KEY_PLAYER2_SCORE));
    assertEquals(
        "Response is not as expected", expectedResult, captorJson.getValue().get(KEY_RESULT));
  }
Example #6
0
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    //		myPrintStream asd = new myPrintStream(System.out);
    //		System.setOut(asd);

    Presenter presenter = new ConsolePresenter(System.out);
    Board board = new Board();
    Player xPlayer = new ConsolePlayer(scanner, System.out);
    Player oPlayer = new ConsolePlayer(scanner, System.out);
    Referee referee = new PrimeReferee();

    Game game = new Game(board, xPlayer, oPlayer, referee, presenter);
    game.play();
    try {
      board.getLog();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    scanner.close();
  }
  @Test
  public void testHandCompare() {
    Hand royalFlushHand1 = new Hand("1 TenHearts JackHearts QueenHearts KingHearts AceHearts");
    Hand royalFlushHand2 = new Hand("1 TenSpades JackSpades QueenSpades KingSpades AceSpades");

    Hand straightFlushHand1 = new Hand("1 ThreeClubs FourClubs FiveClubs SixClubs SevenClubs");
    Hand straightFlushHand2 =
        new Hand("1 ThreeDiamonds FourDiamonds FiveDiamonds SixDiamonds SevenDiamonds");

    Hand fourOfAKindHand1 = new Hand("3 TwoClubs TwoHearts TwoSpades TwoDiamonds FiveClubs");
    Hand fourOfAKindHand2 = new Hand("3 TwoClubs JackDiamonds TwoSpades TwoDiamonds TwoHearts");

    Hand fullHouseHand1 = new Hand("2 AceHearts AceClubs AceSpades KingDiamonds KingHearts");
    Hand fullHouseHand2 = new Hand("2 AceHearts AceClubs KingSpades KingDiamonds KingHearts");

    Hand flushHand1 = new Hand("1 AceClubs TenClubs FiveClubs ThreeClubs NineClubs");
    Hand flushHand2 = new Hand("1 AceClubs TenClubs FourClubs ThreeClubs NineClubs");

    Hand straightHand1 = new Hand("1 TwoClubs ThreeClubs FourSpades FiveClubs SixDiamonds");
    Hand straightHand2 = new Hand("1 SevenClubs ThreeClubs FourSpades FiveHearts SixDiamonds");

    Hand threeOfAKindHand1 = new Hand("4 TwoSpades TwoClubs KingHearts TwoHearts QueenDiamonds");
    Hand threeOfAKindHand2 = new Hand("4 TwoSpades TwoClubs AceHearts TwoHearts QueenDiamonds");

    Hand twoPairHand1 = new Hand("2 AceClubs KingDiamonds AceHearts KingSpades ThreeDiamonds");
    Hand twoPairHand2 = new Hand("2 AceClubs KingDiamonds AceHearts KingSpades AceDiamonds");

    Hand onePairHand1 = new Hand("3 AceHearts AceDiamonds KingSpades FourClubs SixHearts");
    Hand onePairHand2 = new Hand("3 KingHearts AceClubs KingSpades FourClubs SixHearts");

    Hand highCardHand1 = new Hand("1 AceHearts KingClubs QueenDiamonds JackClubs NineClubs");
    Hand highCardHand2 = new Hand("1 AceClubs KingDiamonds QueenSpades JackClubs NineClubs");

    assertEquals(0, royalFlushHand2.compareTo(royalFlushHand1));
    assertEquals(0, straightFlushHand1.compareTo(straightFlushHand2));
    assertEquals(-1, fourOfAKindHand1.compareTo(fourOfAKindHand2));
    assertEquals(1, fullHouseHand1.compareTo(fullHouseHand2));
    assertEquals(1, flushHand1.compareTo(flushHand2));
    assertEquals(-1, straightHand1.compareTo(straightHand2));
    assertEquals(-1, threeOfAKindHand1.compareTo(threeOfAKindHand2));
    assertEquals(-1, twoPairHand1.compareTo(twoPairHand2));
    assertEquals(1, onePairHand1.compareTo(onePairHand2));
    assertEquals(0, highCardHand1.compareTo(highCardHand2));

    assertEquals(-1, highCardHand1.compareTo(onePairHand1));
    assertEquals(-1, onePairHand1.compareTo(twoPairHand1));
    assertEquals(-1, threeOfAKindHand1.compareTo(straightHand1));
    assertEquals(-1, straightHand1.compareTo(flushHand1));
    assertEquals(-1, flushHand1.compareTo(fullHouseHand1));
    assertEquals(-1, fullHouseHand1.compareTo(fourOfAKindHand1));
    assertEquals(-1, fourOfAKindHand1.compareTo(straightFlushHand1));
    assertEquals(-1, straightFlushHand1.compareTo(royalFlushHand1));

    assertEquals(1, royalFlushHand1.compareTo(flushHand1));
    assertEquals(1, threeOfAKindHand1.compareTo(onePairHand1));

    List<Card> deck = makeDeck();
    int n = 2;

    String input = n + "\n";

    List<Hand> hands = new ArrayList<Hand>();
    String handString = "";
    String tmp = "";
    for (int i = 1; i <= n; i++) {
      input += i;
      handString = "";
      handString += i;
      for (int j = 0; j < 5; j++) {
        tmp = deck.remove(0).toString();
        input += " " + tmp;
        handString += " " + tmp;
      }
      input += "\n";
      hands.add(new Hand(handString));
    }

    // get sorted order

    List<Card> sortedCards;
    Card tmpCard;

    for (int g = 0; g < n; g++) {
      sortedCards = new ArrayList<Card>();

      for (Card c : hands.get(g).getCards()) sortedCards.add(c);

      for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
          if (sortedCards.get(i).getRank().rank > sortedCards.get(j).getRank().rank) {
            tmpCard = sortedCards.get(i);
            sortedCards.set(i, sortedCards.get(j));
            sortedCards.set(j, tmpCard);
          }
        }
      }
      hands.get(g).setCards(sortedCards);
    }

    InputStream stream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));

    System.out.println(n);
    for (int i = 0; i < n; i++) {
      System.out.println(
          hands.get(i).toString() + ", rank: " + hands.get(i).getHandRanking().name());
    }

    Game game = new Game(stream);
    game.play();
  }
Example #8
0
 /** Kills the player. Displays a death message and starts a new game. */
 public void die() {
   System.out.println(
       "I'm afraid you are\ndead.\n\n   **** You have died ****\n\nNow let's take a look here... Well, you probably deserve another chance.\nI can't quite fix you up completely, but you can't have everything.");
   Game game = new Game();
   game.play();
 }
Example #9
0
 /** @param args */
 public static void main(String[] args) {
   CommandWords.initialize(null);
   Game theGame = new Game();
   theGame.play();
 }
Example #10
0
 public static void main(String[] args) {
   Game game = new Game();
   game.play();
 }