Валерий Алексеевич Жарков

Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 8: Программирование на Visual C# искусственного интеллекта. Издание 2. Продолжение 1


Скачать книгу

= rand.Next(decks.Length);

      swap = decks[p1];

      decks[p1] = decks[p2];

      decks[p2] = swap;

      }

      }

      nextCard = 0;

      }

      /// <summary>

      /// Gets the next card number from the deck

      /// </summary>

      /// <returns>The number of the next card</returns>

      public byte NextCardNo()

      {

      if (nextCard == decks.Length)

      {

      shuffleShoe();

      }

      return decks[nextCard++];

      }

      /// <summary>

      /// Gets the next card from the deck.

      /// </summary>

      /// <returns>A new instance of the card</returns>

      public Card DealCard()

      {

      return new Card(NextCardNo());

      }

      /// <summary>

      /// Constructs a shoe containing a number of decks

      /// </summary>

      /// <param name="noOfDecks"></param>

      public CardShoe(int noOfDecks)

      {

      this.noOfDecks = noOfDecks;

      makeShoe();

      shuffleShoe();

      testShoe = false;

      }

      /// <summary>

      /// Constructs a shoe containing a single deck

      /// </summary>

      public CardShoe()

      : this(1)

      {

      }

      /// <summary>

      /// Creates a stacked deck for test purposes.

      /// </summary>

      /// <param name="stackedDeck">array of bytes</param>

      public CardShoe(byte[] stackedDeck)

      {

      decks = stackedDeck;

      testShoe = true;

      }

      }

      }

      В панели Solution Explorer выполняем правый щелчок по имени проекта и в контекстном меню выбираем Add, New Item. В панели Add New Item выделяем шаблон Code File, в окне Name записываем имя нового файла с расширением *.cs и щёлкаем кнопку Add. В проект (и в панель Solution Explorer) добавляется этот файл, открывается пустое окно редактирования кода, в которое записываем следующий код.

      Листинг 1.12. Новый файл Pot.cs .

      using System;

      namespace PocketJack

      {

      /// <summary>

      /// Summary description for Betting.

      /// </summary>

      public class Pot

      {

      private int betValueChangeValue;

      private int betValue;

      private int potValue;

      private const int INITIAL_POT_VALUE = 500;

      private const int INITIAL_BET_CHANGE_VALUE = 5;

      public int BetValue

      {

      get

      {

      return betValue;

      }

      }

      public int PotValue

      {

      get

      {

      return potValue;

      }

      }

      public void ResetPot()

      {

      betValueChangeValue = INITIAL_BET_CHANGE_VALUE;

      betValue = INITIAL_BET_CHANGE_VALUE;

      potValue = INITIAL_POT_VALUE;

      }

      public void CheckPot()

      {

      if (betValue > potValue)

      {

      if (System.Windows.Forms.MessageBox.Show(

      "Insufficient funds for the bet." +

      "Do you want to reload the pot?",

      "Bank",

      System.Windows.Forms.MessageBoxButtons.YesNo,

      System.Windows.Forms.MessageBoxIcon.Question,

      System.Windows.Forms.

      MessageBoxDefaultButton.Button1) ==

      System.Windows.Forms.DialogResult.Yes)

      {

      ResetPot();

      }

      else

      {

      betValue = potValue;

      }

      }

      }

      public void DoIncreaseBet()

      {

      betValue = betValue + betValueChangeValue;

      CheckPot();

      }

      public void DoDecreaseBet()

      {

      if (betValue >= betValueChangeValue)

      {

      betValue = betValue – betValueChangeValue;

      }

      }

      public void PlayerWins()

      {

      // win back 2 * our stake

      potValue = potValue + betValue;

      //potValue = potValue + betValue; //We commented out.

      }

      public void HouseWins()

      {

      CheckPot();

      }

      public void DoPushBet()

      {

      // put the betValue back in the potValue

      potValue = potValue + betValue;

      }

      public void DoPlaceBet()

      {

      potValue = potValue – betValue;

      }

      public Pot()

      {

      ResetPot();

      }

      }

      }

      После