public void Loop() { int numLoops = 3; List <byte> loopCode = new List <byte>(); loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER); loopCode.InsertRange(0, LiteralFactory.CreateIntLiteral(4)); loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER); loopCode.InsertRange(0, LiteralFactory.CreateStringLiteral("Hello world")); loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER); loopCode.InsertRange(0, LiteralFactory.CreateBoolLiteral(true)); bytes.push(InstructionFactory.Make_Loop( LiteralFactory.CreateIntLiteral(numLoops), loopCode )); game.ExecuteNext(); for (int i = 0; i < numLoops; i++) { Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop()); Assert.AreEqual(4, bytes.ReadIntLiteral(game.queryCheck)); Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop()); Assert.AreEqual("Hello world", bytes.ReadStringLiteral(game.queryCheck)); Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop()); Assert.AreEqual(true, bytes.ReadBoolLiteral(game.queryCheck)); } }
public void ForLoop() { game.Players = new PlayerManager(2); GamePlayer P1 = game.Players.GetPlayer(0); GamePlayer P2 = game.Players.GetPlayer(1); List <byte> items = new List <byte> { (byte)Instruction.GET_ALL_PLAYERS }; List <byte> code = InstructionFactory.Make_SetPlayerPoints( LiteralFactory.CreatePlaceholderLiteral(0), LiteralFactory.CreateIntLiteral(50) ); bytes.push(InstructionFactory.Make_ForLoop(items, code, 0)); Assert.AreNotEqual(50, P1.Points); Assert.AreNotEqual(50, P2.Points); game.ExecuteNext(); while (bytes.HasBytes()) { Debug.Log((Instruction)bytes.peek()); game.ExecuteNext(); } Assert.AreEqual(50, P1.Points); Assert.AreEqual(50, P2.Points); }
public void PopInstruction() { bytes.push(LiteralFactory.CreateStringLiteral("Hello world")); bytes.push(LiteralFactory.CreateIntLiteral(5)); bytes.push(LiteralFactory.CreateBoolLiteral(true)); bytes.push((byte)Instruction.EFFECT_DELIMITER); List <byte> instructionArr = bytes.popInstruction(dummyCallback); Assert.AreEqual(1, instructionArr.Count); Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)instructionArr[0]); List <byte> boolArr = bytes.popInstruction(dummyCallback); Assert.AreEqual(2, boolArr.Count); bytes.push(boolArr); Assert.AreEqual(true, bytes.ReadBoolLiteral(dummyCallback)); List <byte> intArr = bytes.popInstruction(dummyCallback); Assert.AreEqual(5, intArr.Count); bytes.push(intArr); Assert.AreEqual(5, bytes.ReadIntLiteral(dummyCallback)); List <byte> stringArr = bytes.popInstruction(dummyCallback); bytes.push(stringArr); Assert.AreEqual("Hello world", bytes.ReadStringLiteral(dummyCallback)); }
public void NestedLoop() { int innerLoops = 3; int outerLoops = 2; List <byte> loopCode = new List <byte>(); loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER); loopCode.InsertRange(0, LiteralFactory.CreateIntLiteral(4)); loopCode.InsertRange(0, LiteralFactory.CreateStringLiteral("Hello world")); List <byte> innerLoop = InstructionFactory.Make_Loop( LiteralFactory.CreateIntLiteral(innerLoops), loopCode ); List <byte> outerLoop = InstructionFactory.Make_Loop( LiteralFactory.CreateIntLiteral(outerLoops), innerLoop ); bytes.push(outerLoop); game.ExecuteNext(); for (int i = 0; i < outerLoops; i++) { game.ExecuteNext(); for (int j = 0; j < innerLoops; j++) { Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop()); Assert.AreEqual(4, bytes.ReadIntLiteral(game.queryCheck)); Assert.AreEqual("Hello world", bytes.ReadStringLiteral(game.queryCheck)); } } }
public void Int() { bytes.push(LiteralFactory.CreateIntLiteral(4)); Assert.AreEqual( bytes.ReportStackContent(), "INT(4) " ); }
public void SetCounter() { bytes.push(InstructionFactory.Make_SetCounter( LiteralFactory.CreateStringLiteral("my-key"), LiteralFactory.CreateIntLiteral(44) )); game.ExecuteNext(); Assert.AreEqual(game.Variables.GetCounter("my-key"), 44); }
public void IntBytecode([NUnit.Framework.Range(0, 100, 25)] int num) { List <byte> arr = LiteralFactory.CreateIntLiteral(num); bytes.push(arr); int n = bytes.ReadIntLiteral(dummyCallback); Assert.AreEqual(num, n); }
public void NegativeIntBytecode() { List <byte> arr = LiteralFactory.CreateIntLiteral(-5); bytes.push(arr); int n = bytes.ReadIntLiteral(dummyCallback); Assert.AreEqual(-5, n); }
public void Multiply() { bytes.push(InstructionFactory.Make_Multiply( LiteralFactory.CreateIntLiteral(4), LiteralFactory.CreateIntLiteral(13) )); game.ExecuteNext(); Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 52); }
public void SetStenchTo10() { List <byte> bytes = InstructionFactory.Make_SetCounter( LiteralFactory.CreateStringLiteral("stench"), LiteralFactory.CreateIntLiteral(10) ); string text = getText(bytes); Assert.AreEqual("Set STENCH to 10.", text); }
public void TargetPlayerDraws() { List <byte> bytes = InstructionFactory.Make_PlayerDrawCards( new List <byte> { (byte)Instruction.TARGET_PLAYER }, LiteralFactory.CreateIntLiteral(1) ); string text = getText(bytes); Assert.AreEqual("A player of your choice draws 1 card.", text); }
public void AddToRegister() { bytes.push(LiteralFactory.CreatePlaceholderLiteral(100)); bytes.push(InstructionFactory.Make_AddToRegister( LiteralFactory.CreateIntLiteral(100), LiteralFactory.CreateIntLiteral(4) )); game.ExecuteNext(); Assert.AreEqual(4, bytes.ReadIntLiteral(game.queryCheck)); Assert.IsFalse(bytes.HasBytes()); }
public void YouSet10Points() { List <byte> bytes = InstructionFactory.Make_SetPlayerPoints( new List <byte> { (byte)Instruction.GET_ACTIVE_PLAYER }, LiteralFactory.CreateIntLiteral(10) ); string text = getText(bytes); Assert.AreEqual("Set your score to 10.", text); }
public void YouGainRandomPoints() { List <byte> bytes = InstructionFactory.Make_IncrementPlayerPoints( new List <byte> { (byte)Instruction.GET_ACTIVE_PLAYER }, InstructionFactory.Make_RandomNumber(LiteralFactory.CreateIntLiteral(10)) ); string text = getText(bytes); Assert.AreEqual("You gain points equal to a random number between 1 and 10.", text); }
public void IncrementPlayerPoints() { game.Players = new PlayerManager(1); GamePlayer target = game.Players.GetPlayer(0); target.Points = 5; bytes.push(InstructionFactory.Make_IncrementPlayerPoints( LiteralFactory.CreatePlayerLiteral(target), LiteralFactory.CreateIntLiteral(20) )); game.ExecuteNext(); Assert.AreEqual(target.Points, 25); }
public void SetPlayerMaxHand() { game.Players = new PlayerManager(1); GamePlayer target = game.Players.GetPlayer(0); target.Hand.SetMax(0); bytes.push(InstructionFactory.Make_SetPlayerMaxHand( LiteralFactory.CreatePlayerLiteral(target), LiteralFactory.CreateIntLiteral(5) )); game.ExecuteNext(); Assert.AreEqual(target.Hand.MaxHandSize, 5); }
public void SetPlayerDraw() { game.Players = new PlayerManager(1); GamePlayer target = game.Players.GetPlayer(0); target.SetDrawPerTurn(0); bytes.push(InstructionFactory.Make_SetPlayerDraw( LiteralFactory.CreatePlayerLiteral(target), LiteralFactory.CreateIntLiteral(5) )); game.ExecuteNext(); Assert.AreEqual(target.DrawPerTurn, 5); }
public void IntQuery() { List <byte> addInstruction = InstructionFactory.Make_Add( LiteralFactory.CreateIntLiteral(4), LiteralFactory.CreateIntLiteral(13) ); bytes.push(InstructionFactory.Make_Add( addInstruction, LiteralFactory.CreateIntLiteral(100) )); game.ExecuteNext(); Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 117); }
public void EachPlayerDrawsACard() { List <byte> items = new List <byte> { (byte)Instruction.GET_ALL_PLAYERS }; List <byte> code = InstructionFactory.Make_SetPlayerPoints( LiteralFactory.CreatePlaceholderLiteral(0), LiteralFactory.CreateIntLiteral(50) ); List <byte> bytes = InstructionFactory.Make_ForLoop(items, code, 0); string text = getText(bytes); Assert.AreEqual("For each of the players: that player has their score set to 50", text); }
public GamePlayer(string name, int index) { Name = name; Hand = new Hand(index); Index = index; Points = 0; DrawPerTurn = 1; Colour = Random.ColorHSV(); // set default win condition List <byte> indexBytes = LiteralFactory.CreateIntLiteral(index); List <byte> getPlayerPoints = InstructionFactory.Make_GetPlayerPoints(indexBytes); List <byte> numberToCompare = LiteralFactory.CreateIntLiteral(100); WinCondition = LiteralFactory.CreateConditionLiteral(getPlayerPoints, numberToCompare, ConditionType.NUM, ConditionOperator.AT_LEAST); }
public List <byte> popInstruction(ReadCallback cb) { // bytes returned in reverse order, so they can be pushed straight back on List <byte> bytes = new List <byte>(); byte b = peek(); switch ((Instruction)b) { case Instruction.INT: for (int i = 0; i < 5; i++) { bytes.Insert(0, pop()); } break; case Instruction.STRING: byte headInstruction = pop(); int size = ReadIntLiteral(cb); List <byte> sizeBytes = LiteralFactory.CreateIntLiteral(size); List <byte> charBytes = pop(size); bytes.Insert(0, headInstruction); for (int i = sizeBytes.Count - 1; i >= 0; i--) { bytes.Insert(0, sizeBytes[i]); } for (int i = 0; i < charBytes.Count; i++) { bytes.Insert(0, charBytes[i]); } break; case Instruction.BOOL: case Instruction.ENUM_CONDITION_OPERATOR: case Instruction.ENUM_CONDITION_TYPE: case Instruction.ENUM_DECK_POSITION: case Instruction.ENUM_LIST_TYPE: bytes.Insert(0, pop()); bytes.Insert(0, pop()); break; default: bytes.Add(pop()); break; } return(bytes); }
public void IfStenchOver50ResetStench() { List <byte> bytes = InstructionFactory.Make_If( InstructionFactory.Make_SetCounter( LiteralFactory.CreateStringLiteral("stench"), LiteralFactory.CreateIntLiteral(0) ), InstructionFactory.Make_NumComparison( InstructionFactory.Make_ReadCounter( LiteralFactory.CreateStringLiteral("stench") ), LiteralFactory.CreateIntLiteral(50), (byte)ConditionOperator.MORE_THAN ) ); string text = getText(bytes); Assert.AreEqual("If STENCH is more than 50, then set STENCH to 0.", text); }
public void SubmitTextInput() { string selection = InputFieldText.text; if (String.IsNullOrEmpty(selection)) { return; } switch (currentFieldData.enterValue) { case EnterValueType.NUMBER: { if (Int32.TryParse(selection, out int numValue)) { List <byte> arr = LiteralFactory.CreateIntLiteral(numValue); currentCompilerNode.Add( new EffectBuilderItem(arr) ); } else { Debug.Log($"Couldn't parse {selection}"); } break; } case EnterValueType.TEXT: { List <byte> arr = LiteralFactory.CreateStringLiteral(selection); currentCompilerNode.Add( new EffectBuilderItem(arr) ); break; } default: Debug.LogWarning("Unsupported text input type: " + currentFieldData.enterValue); break; } Next(); }
public void PlayerDrawCards() { game.Cards = new CardManager(); Card c1 = new TestCard(); Card c2 = new TestCard(); Card c3 = new TestCard(); Card c4 = new TestCard(); game.Cards.Deck.AddCard(c1); game.Cards.Deck.AddCard(c2); game.Cards.Deck.AddCard(c3); game.Cards.Deck.AddCard(c4); game.Players = new PlayerManager(1); GamePlayer target = game.Players.GetPlayer(0); Assert.AreEqual(target.Hand.GetSize(), 0); bytes.push(InstructionFactory.Make_PlayerDrawCards( LiteralFactory.CreatePlayerLiteral(target), LiteralFactory.CreateIntLiteral(2) )); game.ExecuteNext(); Assert.AreEqual(target.Hand.GetSize(), 2); }
public string PrintNext() { Instruction instruction = (Instruction)peek(); try { if (Array.IndexOf(enumInstructions, instruction) != -1) { byte b = ReadEnumLiteral(); return($"enum:{b}"); } switch (instruction) { case Instruction.INT: { int n = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}({n})"); } case Instruction.STRING: { string s = ReadStringLiteral(readAccessorFirst); return($"{instruction.ToString()}({s})"); } case Instruction.BOOL: { bool b = ReadBoolLiteral(readAccessorFirst); return($"{instruction.ToString()}({b})"); } case Instruction.PLAYER: { int player = ReadPlayerLiteral(readAccessorFirst); return($"{instruction.ToString()}({player})"); } case Instruction.CARD: { string card = ReadCardLiteral(readAccessorFirst); return($"{instruction.ToString()}({card})"); } case Instruction.LIST: { // pop head and ENUM_LIST_TYPE head pop(); byte type = ReadEnumLiteral(); int size = ReadIntLiteral(readAccessorFirst); push(LiteralFactory.CreateIntLiteral(size)); push(LiteralFactory.CreateEnumLiteral(type, Instruction.ENUM_LIST_TYPE)); push((byte)Instruction.LIST); ReadList(readAccessorFirst); string typeName = EnumRepesentation.EnumLookup("ENUM_LIST_TYPE").getName((int)type); return($"{instruction.ToString()}(size:{size},type:{typeName})"); } case Instruction.IF: case Instruction.UNLESS: case Instruction.LOOP: case Instruction.FOR_LOOP: case Instruction.ENDIF: case Instruction.ENDLOOP: { pop(); int id = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(id:{id})"); } case Instruction.PLACEHOLDER: { pop(); int id = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(id:{id})"); } case Instruction.ADD_TO_REGISTER: { pop(); int id = ReadIntLiteral(readAccessorFirst); int size = ReadIntLiteral(readAccessorFirst); return($"{instruction.ToString()}(at:{id}, size:{size})"); } default: { pop(); return(instruction.ToString()); } } } catch (UnexpectedByteException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } catch (StackFullException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } catch (StackEmptyException e) { Debug.LogError($"Printer jam! ({instruction}) --- {e}"); return("#" + ((byte)instruction).ToString()); } }
public void executeNext() { Instruction next = this.next(); try { switch (next) { // FUNCTIONS case Instruction.RANDOM_NUMBER: { int upperBound = ReadIntLiteral(skipToNext); push(LiteralFactory.CreateIntLiteral(UnityEngine.Random.Range(1, upperBound))); break; } case Instruction.ADD: { int a = ReadIntLiteral(skipToNext); int b = ReadIntLiteral(skipToNext); push(LiteralFactory.CreateIntLiteral(a + b)); break; } case Instruction.IF: { int controlID = ReadIntLiteral(skipToNext); Condition condition = ReadConditionLiteral(skipToNext); List <byte> blockBytes = new List <byte>(); while (HasBytes()) { byte b = pop(); if (b == (byte)Instruction.ENDIF) { int id = ReadIntLiteral(skipToNext); if (id == controlID) { break; } else { blockBytes.Insert(0, (byte)Instruction.ENDIF); blockBytes.InsertRange(0, LiteralFactory.CreateIntLiteral(id)); } } else { blockBytes.Insert(0, b); } } if (condition.Evaluate()) { push(blockBytes); } break; } case Instruction.UNLESS: { int controlID = ReadIntLiteral(skipToNext); Condition condition = ReadConditionLiteral(skipToNext); List <byte> blockBytes = new List <byte>(); while (HasBytes()) { byte b = pop(); if (b == (byte)Instruction.ENDIF) { int id = ReadIntLiteral(skipToNext); if (id == controlID) { break; } else { blockBytes.Insert(0, (byte)Instruction.ENDIF); blockBytes.InsertRange(0, LiteralFactory.CreateIntLiteral(id)); } } else { blockBytes.Insert(0, b); } } if (!condition.Evaluate()) { push(blockBytes); } break; } case Instruction.LIST_LENGTH: { List <byte[]> list = ReadList(skipToNext); push(LiteralFactory.CreateIntLiteral(list.Count)); break; } case Instruction.CARD_HAS_TAG: { Card card = GM.ReadCardFromStack(); string tagName = ReadStringLiteral(skipToNext); push(LiteralFactory.CreateConditionLiteral( LiteralFactory.CreateBoolLiteral(card.HasTag(tagName)), LiteralFactory.CreateBoolLiteral(true), ConditionType.BOOL, ConditionOperator.EQUAL )); break; } case Instruction.PLAYER_IS_WINNING: { GamePlayer player = GM.ReadPlayerFromStack(); bool winning = true; foreach (GamePlayer otherPlayer in GM.Players.GetPlayers()) { if (otherPlayer.Points > player.Points) { winning = false; break; } } push(LiteralFactory.CreateConditionLiteral( LiteralFactory.CreateBoolLiteral(winning), LiteralFactory.CreateBoolLiteral(true), ConditionType.BOOL, ConditionOperator.EQUAL )); break; } case Instruction.PLAYER_IS_LOSING: { GamePlayer player = GM.ReadPlayerFromStack(); bool losing = true; foreach (GamePlayer otherPlayer in GM.Players.GetPlayers()) { if (otherPlayer.Points < player.Points) { losing = false; break; } } push(LiteralFactory.CreateBoolLiteral(losing)); break; } case Instruction.MULTIPLY: { int a = ReadIntLiteral(skipToNext); int b = ReadIntLiteral(skipToNext); push(LiteralFactory.CreateIntLiteral(a * b)); break; } case Instruction.LOOP: { int id = ReadIntLiteral(skipToNext); int num = ReadIntLiteral(skipToNext); List <List <byte> > instructionArrays = new List <List <byte> >(); while (HasBytes()) { if (peek() == (byte)Instruction.ENDLOOP) { pop(); int endloopID = ReadIntLiteral(skipToNext); if (endloopID == id) { break; } else { List <byte> endloopBytes = new List <byte>(LiteralFactory.CreateIntLiteral(endloopID)); endloopBytes.Add((byte)Instruction.ENDLOOP); instructionArrays.Insert(0, endloopBytes); } } else { List <byte> arr = popInstruction(skipToNext); instructionArrays.Insert(0, arr); } } for (int n = 0; n < num; n++) { for (int m = 0; m < instructionArrays.Count; m++) { push(instructionArrays[m]); } } break; } case Instruction.FOR_LOOP: { int ID = ReadIntLiteral(skipToNext); List <byte[]> items = ReadList(skipToNext); List <List <byte> > instructionArrays = new List <List <byte> >(); while (HasBytes()) { if (peek() == (byte)Instruction.ENDLOOP) { pop(); int endloopID = ReadIntLiteral(skipToNext); if (endloopID == ID) { break; } else { List <byte> endloopBytes = new List <byte>(LiteralFactory.CreateIntLiteral(endloopID)); endloopBytes.Add((byte)Instruction.ENDLOOP); instructionArrays.Insert(0, endloopBytes); } } List <byte> arr = popInstruction(skipToNext); instructionArrays.Insert(0, arr); } List <byte> idBytes = LiteralFactory.CreateIntLiteral(ID); for (int i = 0; i < items.Count; i++) { List <byte> currentItem = new List <byte>(items[i]); currentItem.Reverse(); List <byte> addToRegister = InstructionFactory.Make_AddToRegister(idBytes, currentItem); for (int m = 0; m < instructionArrays.Count; m++) { push(instructionArrays[m]); } push(addToRegister); } break; } case Instruction.ADD_TO_REGISTER: { int ID = ReadIntLiteral(skipToNext); int size = ReadIntLiteral(skipToNext); List <byte> bytes = pop(size); register[ID] = bytes; break; } case Instruction.PLACEHOLDER: { int ID = ReadIntLiteral(skipToNext); List <byte> fetch = new List <byte>(register[ID]); fetch.Reverse(); push(fetch); break; } // QUERIES case Instruction.GET_ACTIVE_PLAYER: { push(LiteralFactory.CreatePlayerLiteral(GM.Players.GetActivePlayer())); break; } case Instruction.GET_ALL_OPPONENTS: { push(LiteralFactory.CreateListLiteral( new List <GamePlayer>(GM.Players.GetOpponents()) )); break; } case Instruction.GET_ALL_PLAYERS: { push(LiteralFactory.CreateListLiteral( new List <GamePlayer>(GM.Players.GetPlayers()) )); break; } case Instruction.GET_CARDS_IN_DECK: { push(LiteralFactory.CreateListLiteral( new List <Card>(GM.Cards.Deck.GetCards()) )); break; } case Instruction.GET_CARDS_IN_DISCARD: { push(LiteralFactory.CreateListLiteral( new List <Card>(GM.Cards.Discard.GetCards()) )); break; } case Instruction.GET_CARDS_IN_HAND: { GamePlayer player = GM.ReadPlayerFromStack(); push(LiteralFactory.CreateListLiteral( new List <Card>(player.Hand.GetCards()) )); break; } case Instruction.GET_PLAYER_POINTS: { GamePlayer player = GM.ReadPlayerFromStack(); int points = player.Points; push(LiteralFactory.CreateIntLiteral(points)); break; } case Instruction.READ_COUNTER: { string key = ReadStringLiteral(skipToNext); int count = GM.Variables.GetCounter(key); push(LiteralFactory.CreateIntLiteral(count)); break; } case Instruction.BOOL_COMPARISON: { bool operandA = ReadBoolLiteral(skipToNext); byte operatorEnum = ReadEnumLiteral(); bool operandB = ReadBoolLiteral(skipToNext); push(LiteralFactory.CreateConditionLiteral( new CompareBool(operandA, operandB, (ConditionOperator)operatorEnum) )); break; } case Instruction.NUM_COMPARISON: { int operandA = ReadIntLiteral(skipToNext); int operandB = ReadIntLiteral(skipToNext); byte operatorEnum = ReadEnumLiteral(); push(LiteralFactory.CreateConditionLiteral( new CompareNum(operandA, operandB, (ConditionOperator)operatorEnum) )); break; } case Instruction.TARGET_PLAYER: { GM.UI.PresentChoiceOfPlayers(new List <GamePlayer>(GM.Players.GetPlayers()), this); break; } case Instruction.TARGET_OPPONENT: { GM.UI.PresentChoiceOfPlayers(new List <GamePlayer>(GM.Players.GetOpponents()), this); break; } case Instruction.TARGET_CARD_IN_DECK: { GM.UI.PresentChoiceOfCards(new List <Card>(GM.Cards.Deck.GetCards()), this); break; } case Instruction.TARGET_CARD_IN_DISCARD: { GM.UI.PresentChoiceOfCards(new List <Card>(GM.Cards.Discard.GetCards()), this); break; } case Instruction.TARGET_CARD_IN_HAND: { GamePlayer player = GM.ReadPlayerFromStack(); GM.UI.PresentChoiceOfCards(new List <Card>(player.Hand.GetCards()), this); break; } case Instruction.RANDOM_PLAYER: { GamePlayer[] players = GM.Players.GetPlayers(); GamePlayer randomPlayer = players[UnityEngine.Random.Range(0, players.Length)]; push(LiteralFactory.CreatePlayerLiteral(randomPlayer)); break; } case Instruction.RANDOM_OPPONENT: { GamePlayer[] opponents = GM.Players.GetOpponents(); GamePlayer randomOpponent = opponents[UnityEngine.Random.Range(0, opponents.Length)]; push(LiteralFactory.CreatePlayerLiteral(randomOpponent)); break; } case Instruction.RANDOM_CARD_IN_DECK: { Card[] deckCards = GM.Cards.Deck.GetCards(); Card randomCard = deckCards[UnityEngine.Random.Range(0, deckCards.Length)]; push(LiteralFactory.CreateCardLiteral(randomCard)); break; } case Instruction.RANDOM_CARD_IN_DISCARD: { Card[] discardCards = GM.Cards.Discard.GetCards(); Card randomCard = discardCards[UnityEngine.Random.Range(0, discardCards.Length)]; push(LiteralFactory.CreateCardLiteral(randomCard)); break; } case Instruction.RANDOM_CARD_IN_HAND: { GamePlayer player = GM.ReadPlayerFromStack(); Card[] handCards = player.Hand.GetCards(); Card randomCard = handCards[UnityEngine.Random.Range(0, handCards.Length)]; push(LiteralFactory.CreateCardLiteral(randomCard)); break; } // EFFECTS case Instruction.INCREMENT_PLAYER_POINTS: { GamePlayer player = GM.ReadPlayerFromStack(); int pointsNum = ReadIntLiteral(skipToNext); GM.SetPlayerPoints(player, player.Points + pointsNum); break; } case Instruction.PLAYER_DRAW_CARD: { GamePlayer player = GM.ReadPlayerFromStack(); int numCards = ReadIntLiteral(skipToNext); for (int n = 0; n < numCards; n++) { GM.PlayerDrawCard(player); } break; } case Instruction.SET_COUNTER: { string key = ReadStringLiteral(skipToNext); int count = ReadIntLiteral(skipToNext); GM.Variables.SetCounter(key, count); break; } case Instruction.SET_PLAYER_DRAW: { GamePlayer player = GM.ReadPlayerFromStack(); int num = ReadIntLiteral(skipToNext); player.SetDrawPerTurn(num); break; } case Instruction.SET_PLAYER_MAX_HAND: { GamePlayer player = GM.ReadPlayerFromStack(); int num = ReadIntLiteral(skipToNext); player.Hand.SetMax(num); break; } case Instruction.SET_PLAYER_POINTS: { GamePlayer player = GM.ReadPlayerFromStack(); int pointsNum = ReadIntLiteral(skipToNext); GM.SetPlayerPoints(player, pointsNum); break; } case Instruction.MOVE_TO_DECK: { Card card = GM.ReadCardFromStack(); DeckLocation posEnum = (DeckLocation)ReadEnumLiteral(); card.Zone.MoveCard(GM.Cards.Deck, card.GetID()); GM.Cards.Deck.MoveLastAddedCard(posEnum); break; } case Instruction.MOVE_TO_DISCARD: { Card card = GM.ReadCardFromStack(); card.Zone.MoveCard(GM.Cards.Discard, card.GetID()); break; } } } catch (UnexpectedByteException e) { Debug.LogError(e); } catch (StackFullException e) { Debug.LogError(e); } catch (StackEmptyException e) { Debug.LogError(e); } }