Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Cards
- {
- class Heap
- {
- public static void Initialize(int[] cards)
- {
- for (int i = 0; i < cards.Length; i++)
- cards[i] = 0;
- }
- public static void InputInitialize(int[] cards, int n)
- {
- for (int i = 0; i <n; i++)
- cards[i] = int.Parse(Console.ReadLine());
- }
- public static void RandomInitializer(int[] cards, int n)
- {
- Random rnd = new Random();
- for (int i = 0; i < n; i++)
- cards[i] = rnd.Next(1, 14);
- }
- public static void AddCard(int[] cards, int card)
- {
- int n = 0;
- while (cards[n] != 0)
- n++;
- cards[n] = card;
- }
- public static int DrawCard(int[] cards)
- {
- int tmp = cards[0];
- for (int i = 0; i < cards.Length - 1; i++)
- cards[i] = cards[i + 1];
- cards[cards.Length - 1] = 0;
- return tmp;
- }
- public static bool Empty(int[] cards)
- {
- for (int i = 0; i < cards.Length; i++)
- {
- if (cards[i] != 0)
- return false;
- }
- return true;
- }
- }
- }
- ***************
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Cards
- {
- class Program
- {
- static void Main(string[] args)
- {
- int playerOneCard, playerTwoCard;
- int[] heapOne, heapTwo;
- heapOne = new int[52];
- heapTwo = new int[52];
- Heap.Initialize(heapOne);
- Heap.RandomInitializer(heapOne, 26);
- Heap.Initialize(heapTwo);
- Heap.RandomInitializer(heapTwo, 26);
- while(!Heap.Empty(heapOne) && !Heap.Empty(heapTwo))
- {
- playerOneCard = Heap.DrawCard(heapOne);
- playerTwoCard = Heap.DrawCard(heapTwo);
- if(playerOneCard > playerTwoCard)
- {
- Heap.AddCard(heapOne, playerOneCard);
- Heap.AddCard(heapOne, playerTwoCard);
- }
- else
- {
- Heap.AddCard(heapTwo, playerTwoCard);
- Heap.AddCard(heapTwo, playerOneCard);
- }
- }
- if(Heap.Empty(heapOne))
- Console.WriteLine("Winner is player two!");
- else
- Console.WriteLine("Winner is player one!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement