How to I change this code to print the highest value(s) in the array? The wanted output (you just need to make it print the winner, ignore what comes before) is included below:
--------------------------------------------------------------------------------------------
public static void playGame(int players, int cards) {
if (players * cards > 52) {
System.out.println("Not enough cards for that many players.");
return;
}
boolean[] deck = new boolean[52];
int[] playerScore = new int[players];
for (int i = 0; i < players; i++) {
System.out.println("Player " + (i + 1));
int[] hand = Cards.dealHandFromDeck(cards, deck);
Cards.printHand(hand);
System.out.println("Score = " + Cards.pointValue(hand));
System.out.println();
playerScore[i] = Cards.pointValue(hand);
}
//go through playerScore array twice, first to find the highest score, then print which player(s) have that score
Screenshot of code:
Textual Code :
public static void playGame(int players, int cards) {
if (players * cards > 52) {
System.out.println("Not enough cards for that many players.");
return;
}
boolean[] deck = new boolean[52];
int[] playerScore = new int[players];
// this will store the highest score
int highest_score = -1;
for (int i = 0; i < players; i++) {
System.out.println("Player " + (i + 1));
int[] hand = Cards.dealHandFromDeck(cards, deck);
Cards.printHand(hand);
System.out.println("Score = " + Cards.pointValue(hand));
System.out.println();
playerScore[i] = Cards.pointValue(hand);
// finding the highest score
if(Cards.pointValue(hand) > highest_score) {
highest_score = Cards.pointValue(hand);
}
}
// now the variable highest_score has the maximum score value
// now just iterate over all the players and those players having the same
// score as highest_score print that player
for (int i = 0; i < players; i++) {
int[] hand = Cards.dealHandFromDeck(cards, deck);
if(Cards.pointValue(hand) == highest_score) {
System.out.println("Player " + (i+1) + " is a winner");
}
}
}
How to I change this code to print the highest value(s) in the array? The wanted...
C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...
Please try to not use array lists Main topics: Random number generators Arrays Programmer defined methods Program Specification: You are to develop a program to play a variation on a game of chance called single player Poker. Game Description: • There is a Player who starts with 100 chips, each worth $1.00. • There is a deck of 36 cards: – Each card has a number in the range of [1, 9] printed on it - 9 possible values /...
Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...
Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler { /** * The number of consecutive shuffle steps to be performed in each call * to each sorting...
This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...
I wrote a card shuffle program and I am trying to see how I can add a sorting function to the program to sort the players hands before printing them. How would I do this? #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; void printHand(int []); void deal(vector<int> &, int[], int[], int[], int[]); void unwrapDeck(vector<int> &deck) { for(int i=0; i<=51; i++) deck.push_back(i); } void shuffleDeck(vector<int> &deck) { //Status of cards before shuffling cout << "Before shuffling: "...
C++ program This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...
In java---- The DeckTester.java file, provides a basic set of Deck tests. Add additional code at the bottom of the main method to create a standard deck of 52 cards and test the shuffle method ONLY in the Deck class. After testing the shuffle method, use the Deck toString method to “see” the cards after every shuffle. Deck: import java.util.List; import java.util.ArrayList; /** * The Deck class represents a shuffled deck of cards. * It provides several operations including *...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...