Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class Cards
- {
- static void Main(string[] args)
- {
- int N = int.Parse(Console.ReadLine());
- long handStrength1 = 0;
- long handStrength2 = 0;
- BigInteger playerScore1 = 0;
- BigInteger playerScore2 = 0;
- byte wins1 = 0;
- byte wins2 = 0;
- bool winner1 = false, winner2 = false;
- for (int turn = 0; turn < N; turn++)
- {
- handStrength1 = 0; //Set point of current hand to 0, for every new turn
- handStrength2 = 0; //Same here, for the other player
- string[] firstPlayerCard = new string[3];
- string[] secondPlayerCard = new string[3];
- for (int card1 = 0; card1 < 3; card1++)
- {
- firstPlayerCard[card1] = Console.ReadLine();
- switch (firstPlayerCard[card1]) //check the value of the current card
- {
- case "2":
- handStrength1 += 10;
- break;
- case "3":
- handStrength1 += 9;
- break;
- case "4":
- handStrength1 += 8;
- break;
- case "5":
- handStrength1 += 7;
- break;
- case "6":
- handStrength1 += 6;
- break;
- case "7":
- handStrength1 += 5;
- break;
- case "8":
- handStrength1 += 4;
- break;
- case "9":
- handStrength1 += 3;
- break;
- case "10":
- handStrength1 += 2;
- break;
- case "A":
- handStrength1 += 1;
- break;
- case "J":
- handStrength1 += 11;
- break;
- case "Q":
- handStrength1 += 12;
- break;
- case "K":
- handStrength1 += 13;
- break;
- case "Z":
- playerScore1 *= 2;
- break;
- case "Y":
- playerScore1 -= 200;
- break;
- case "X":
- winner1 = true;
- break;
- default:
- break;
- }
- }
- for (int card2 = 0; card2 < 3; card2++)
- {
- secondPlayerCard[card2] = Console.ReadLine();
- switch (secondPlayerCard[card2]) //check value of card
- {
- case "2":
- handStrength2 += 10;
- break;
- case "3":
- handStrength2 += 9;
- break;
- case "4":
- handStrength2 += 8;
- break;
- case "5":
- handStrength2 += 7;
- break;
- case "6":
- handStrength2 += 6;
- break;
- case "7":
- handStrength2 += 5;
- break;
- case "8":
- handStrength2 += 4;
- break;
- case "9":
- handStrength2 += 3;
- break;
- case "10":
- handStrength2 += 2;
- break;
- case "A":
- handStrength2 += 1;
- break;
- case "J":
- handStrength2 += 11;
- break;
- case "Q":
- handStrength2 += 12;
- break;
- case "K":
- handStrength2 += 13;
- break;
- case "Z":
- playerScore2 *= 2;
- break;
- case "Y":
- playerScore2 -= 200;
- break;
- case "X":
- winner2 = true;
- break;
- default:
- break;
- }
- }
- if (winner1 && winner2) //if both drew X card
- {
- playerScore1 += 50;
- playerScore2 += 50;
- }
- else if (winner1 && !winner2) //if only one of them => game over => break loop
- {
- break;
- }
- else if (winner2 && !winner1) //same as above for the other player
- {
- break;
- }
- //check which player has a stronger hand and the one with the better wins and adds the points up to the playerScore
- if (handStrength1 > handStrength2)
- {
- playerScore1 += handStrength1;
- wins1++;
- }
- else if (handStrength2 > handStrength1)
- {
- playerScore2 += handStrength2;
- wins2++;
- }
- }
- if (winner1 && !winner2) //X card check
- {
- Console.WriteLine("X card drawn! Player one wins the match!");
- }
- else if (winner2 && !winner1) //X card check
- {
- Console.WriteLine("X card drawn! Player two wins the match!");
- }
- else
- { //check which player has won it
- if (playerScore1 > playerScore2)
- {
- Console.WriteLine("First player wins!");
- Console.WriteLine("Score: {0}", playerScore1);
- Console.WriteLine("Games won: {0}", wins1);
- }
- else if (playerScore2 > playerScore1)
- {
- Console.WriteLine("Second player wins!");
- Console.WriteLine("Score: {0}", playerScore2);
- Console.WriteLine("Games won: {0}", wins2);
- }
- else if ((playerScore1 == playerScore2))
- {
- Console.WriteLine("It's a tie!");
- Console.WriteLine("Score: {0}", playerScore1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement