forked from platatat/SnapCall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.cs
More file actions
54 lines (49 loc) · 1.02 KB
/
Deck.cs
File metadata and controls
54 lines (49 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnapCall
{
public class Deck
{
private ulong[] cards;
private ulong removedCards;
private int position;
private Random random;
// TODO: this metric doesn't account for removed cards
public int CardsRemaining { get { return 52 - position; } }
public Deck(ulong removedCards = 0)
{
this.removedCards = removedCards;
random = new Random();
cards = new ulong[52];
for (int i = 0; i < 52; i++) cards[i] = 1ul << i;
position = 0;
}
public void Shuffle()
{
int n = cards.Length;
while (n > 1)
{
n--;
int k = random.Next(n + 1);
ulong value = cards[k];
cards[k] = cards[n];
cards[n] = value;
}
position = 0;
}
public ulong Draw(int count)
{
ulong hand = 0;
for (int i = 0; i < count; i++)
{
while ((cards[position] & removedCards) != 0) position++;
hand |= cards[position];
position++;
}
return hand;
}
}
}