Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 3: Программирование на Visual C# искусственного интеллекта (продолжение 2) - страница 33

Шрифт
Интервал


new string [] {«club», «diamond», «heart», «spade»};
///
/// Names of individual cards, in the order of the cards
/// in a suit
///
static private string [] valueNames =
new string [] {«Ace», «Deuce», «Three», «Four», «Five», «Six»,
«Seven», «Eight», «Nine», «Ten», «Jack», «Queen», «King»};
///
/// Returns the value in points of a given card,
/// according to BlackJack rules
///
public int BlackJackScore
{
get
{
return scores [(CardNo – 1) % 13];
}
}
///
/// Returns true if the card is a picture
/// (i.e. jack, queen or king)
///
public bool IsPicture
{
get
{
return isPicture [(CardNo – 1) % 13];
}
}
///
/// Returns text of the suit of this card
///
public string Suit
{
get
{
return suitNames [(CardNo – 1) / 13];
}
}
///
/// Returns the text of the value of this card
///
public string ValueName
{
get
{
return valueNames [(CardNo – 1) % 13];
}
}
///
/// Returns true if this is a red card
///
public bool Red
{
get
{
int suit = (CardNo – 1) / 13;
return ((suit == 1) || (suit == 2));
}
}
///
/// Returns true if this is a black card
///
public bool Black
{
get
{
return! Red;
}
}
///
/// Returns an image which can be used to draw this card
///
public Image CardImage
{
get
{
int dispNo = CardNo;
if (!FaceUp)
{
dispNo = 0;
}
if (cardImages [dispNo] == null)
{
cardImages [dispNo] = new Bitmap (
execAssem.GetManifestResourceStream (
@"PocketJack.images.» + dispNo + @".gif»));
}
return cardImages [dispNo];
}
}
///
/// Constructs a card with a partiuclar number
///
/// number of the card
/// in the range 1 to 52 
/// true if the card
/// is to be drawn face up
public Card (byte cardNo, bool faceUp)
{
CardNo = cardNo;
FaceUp = faceUp;
}
///
/// Constructs a face up card with that number
///
///
public Card (byte cardNo)
: this (cardNo, true)
{
}
///
/// String description of the card
///
/// the name and suit of the card
public override string ToString ()
{
return ValueName + " of " + Suit;
}
}
///
/// Provides a container for a number of cards.
/// May be used to draw the cards and compute their score.