In C++ Language, create a text art-based “Spades” Game for 4 players. The game s
ID: 3911256 • Letter: I
Question
In C++ Language, create a text art-based “Spades” Game for 4 players. The game should allow the users to play the game multiple times until they select not to play again.
Spades is a card game that requires 4 players and is played in pairs. The objective of the game is to reach 500 points by collecting more books also known as tricks than your opponent. You obtain books by trying to reach the amount you bid prior to your hand being played. You receive a bag when you get a book more than you bid. Each book is worth 10 points and each bag is worth 1 point. It must be a standard 52-card deck.4l 1. Each player bids the number of tricks they expect to take. The player to the left of the dealer starts the bidding and bidding continues in a clockwise direction, ending with the dealer. As Spades are always trump, no trump suit is named during bidding as with some other variants. A bid of "zero" is called "nil"; the player must bid at least one if you don't want to bid "nil"* 2. Each hand consists of a number of tricks (the 4-handed game contains 13 tricks using all 52 cards). The player on the dealer's left makes the opening lead by playing a single card of their choice. Players in clockwise fashion then play a card of their choice; they must follow suit, if they can, otherwise they may play any card, including a trump Spadee common rule is that a player may not lead Spades until a Spade has been played to trump another card. A player cannot lead Spades in the first HAND.d 4. A partnership reneges on their contract if they violate the rules of play; most often this happens when a player plays off-suit when they could have, and therefore should have, followed suit. ^ 5. A 100-point penalty when 10 bags are accumulated and the ones place rolls over.Explanation / Answer
Hello there ,
Please find below code and output .
/**
** Java Program to Implement Gaussian Elimination Algorithm
**/
import java.util.Scanner;
/** Class GaussianElimination **/
public class GaussianElimination
{
public void solve(double[][] A, double[] B)
{
int N = B.length;
for (int k = 0; k < N; k++)
{
/** find pivot row **/
int max = k;
for (int i = k + 1; i < N; i++)
if (Math.abs(A[i][k]) > Math.abs(A[max][k]))
max = i;
/** swap row in A matrix **/
double[] temp = A[k];
A[k] = A[max];
A[max] = temp;
/** swap corresponding values in constants matrix **/
double t = B[k];
B[k] = B[max];
B[max] = t;
/** pivot within A and B **/
for (int i = k + 1; i < N; i++)
{
double factor = A[i][k] / A[k][k];
B[i] -= factor * B[k];
for (int j = k; j < N; j++)
A[i][j] -= factor * A[k][j];
}
}
/** Print row echelon form **/
printRowEchelonForm(A, B);
/** back substitution **/
double[] solution = new double[N];
for (int i = N - 1; i >= 0; i--)
{
double sum = 0.0;
for (int j = i + 1; j < N; j++)
sum += A[i][j] * solution[j];
solution[i] = (B[i] - sum) / A[i][i];
}
/** Print solution **/
printSolution(solution);
}
/** function to print in row echleon form **/
public void printRowEchelonForm(double[][] A, double[] B)
{
int N = B.length;
System.out.println(" Row Echelon form : ");
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
System.out.printf("%.3f ", A[i][j]);
System.out.printf("| %.3f ", B[i]);
}
System.out.println();
}
/** function to print solution **/
public void printSolution(double[] sol)
{
int N = sol.length;
System.out.println(" Solution : ");
for (int i = 0; i < N; i++)
System.out.printf("%.3f ", sol[i]);
System.out.println();
}
/** Main function **/
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Gaussian Elimination Algorithm Test ");
/** Make an object of GaussianElimination class **/
GaussianElimination ge = new GaussianElimination();
System.out.println(" Enter number of variables");
int N = scan.nextInt();
double[] B = new double[N];
double[][] A = new double[N][N];
System.out.println(" Enter "+ N +" equations coefficients ");
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
A[i][j] = scan.nextDouble();
System.out.println(" Enter "+ N +" solutions");
for (int i = 0; i < N; i++)
B[i] = scan.nextDouble();
ge.solve(A,B);
}
}
Find output for these equations.
3x + 2y - 4z = 3
2x + 3y + 3z = 15
5x - 3y + z = 14
========O/P=========
run:
Gaussian Elimination Algorithm Test
Enter number of variables
3
Enter 3 equations coefficients
3 2 -4
2 3 3
5 -3 1
Enter 3 solutions
3
15
14
Row Echelon form :
5.000 -3.000 1.000 | 14.000
0.000 4.200 2.600 | 9.400
0.000 0.000 -6.952 | -13.905
Solution :
3.000 1.000 2.000
BUILD SUCCESSFUL (total time: 52 seconds