-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
48 lines (42 loc) · 1.13 KB
/
Player.cs
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
using System.Collections.Generic;
using System.Linq;
namespace blackjack {
public class Player {
public string Name;
public int Chips;
public int Bet;
public List<Card> Cards;
public Player() {}
public Player(string name, int chips)
{
Name = name;
Chips = chips;
}
public int Total()
{
return Cards.Count > 0 ? Cards.Aggregate(0, (sum, card) => sum + card.Value) : 0;
}
public bool HasAce()
{
return Cards.Any(card => card.Value == 11);
}
public bool HasBlackjack()
{
return Cards.Count == 2 && Total() == 21;
}
public void ReduceAce()
{
var Ace = Cards.Where(card => card.Value == 11).ToArray();
Ace[0].Value = 1;
}
public List<string> ValidMoves()
{
var validMoves = new List<string> {"stick", "hit", "surrender"};
if (Chips >= Bet)
{
validMoves.Add("double down");
}
return validMoves;
}
}
}