Advertisement
electricmaster

UNO AI

Jan 22nd, 2017
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. IEnumerator TakeTurn() { // AI programming for a given turn
  2.         takingTurn = true;
  3.         while(GameManager.gm.Turn == Order) {
  4.             switch (GameManager.gm.CurrentState) {
  5.                 case GameManager.States.Wait:
  6.                     if (!MovesAvailable()) { // No moves! Draw a card
  7.                         AddCard(GameManager.GameDeck.Draw());
  8.                         if (!MovesAvailable()) // Still no moves! End turn
  9.                             GameManager.gm.IncrementTurn();
  10.                     }
  11.                     else { // grab the first selectable card and play it. Might improve on this in later versions.
  12.                         foreach(Card c in Hand)
  13.                             if (c.Model.GetComponent<CardBehavior>().isSelectable) {
  14.                                 RemoveCard(c);
  15.                                 // Playing a card will re-parent the card and increment the turn counter accordingly.
  16.                                 GameManager.gm.PlayCard(c, Order);
  17.                             }
  18.                     }
  19.                     break;
  20.                 case GameManager.States.Draw:
  21.                     while(GameManager.gm.DrawCount > 0) {
  22.                         AddCard(GameManager.GameDeck.Draw());
  23.                         GameManager.gm.DrawCount--;
  24.                     }
  25.                     GameManager.gm.IncrementTurn();
  26.                     break;
  27.                 /*case GameManager.States.ChooseColor:
  28.                     break;*/ // Currently, color selection is initiated by the game manager.
  29.             }
  30.             yield return new WaitForSeconds(2.5f); // make sure everything doesn't happen instantaneously
  31.         }
  32.         takingTurn = false;
  33.         yield break;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement