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 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 NestedIfStatement() { CompareNum isFalse = new CompareNum(1, 2, ConditionOperator.EQUAL); List <byte> inner_if_false = InstructionFactory.Make_If( new List <byte> { (byte)Instruction.ERROR }, LiteralFactory.CreateConditionLiteral(isFalse) ); List <byte> innerCode = new List <byte>(inner_if_false); innerCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER); CompareNum isTrue = new CompareNum(1, 2, ConditionOperator.NOT_EQUAL); List <byte> outer_if_true = InstructionFactory.Make_If( innerCode, LiteralFactory.CreateConditionLiteral(isTrue) ); bytes.push(outer_if_true); game.ExecuteNext(); Assert.IsTrue(bytes.HasBytes()); game.ExecuteNext(); Assert.IsTrue(bytes.HasBytes()); bytes.pop(); Assert.IsFalse(bytes.HasBytes()); }
public void IfStatement() { CompareNum compare = new CompareNum(1, 2, ConditionOperator.EQUAL); List <byte> if_false = InstructionFactory.Make_If( new List <byte> { (byte)Instruction.EFFECT_DELIMITER }, LiteralFactory.CreateConditionLiteral(compare) ); bytes.push(if_false); game.ExecuteNext(); Assert.IsFalse(bytes.HasBytes()); compare = new CompareNum(1, 2, ConditionOperator.NOT_EQUAL); List <byte> if_true = InstructionFactory.Make_If( new List <byte> { (byte)Instruction.EFFECT_DELIMITER }, LiteralFactory.CreateConditionLiteral(compare) ); bytes.push(if_true); game.ExecuteNext(); Assert.IsTrue(bytes.HasBytes()); Assert.AreEqual((byte)Instruction.EFFECT_DELIMITER, bytes.pop()); Assert.IsFalse(bytes.HasBytes()); }
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 ConditionBytecode() { CompareBool compbool1 = new CompareBool(true, true, ConditionOperator.EQUAL); bytes.push(LiteralFactory.CreateConditionLiteral(compbool1)); Condition boolCondition1 = bytes.ReadConditionLiteral(dummyCallback); Assert.IsTrue(boolCondition1.Evaluate()); CompareBool compbool2 = new CompareBool(true, true, ConditionOperator.NOT_EQUAL); bytes.push(LiteralFactory.CreateConditionLiteral(compbool2)); Condition boolCondition2 = bytes.ReadConditionLiteral(dummyCallback); Assert.IsFalse(boolCondition2.Evaluate()); CompareNum compnum1 = new CompareNum(2, 4, ConditionOperator.LESS_THAN); bytes.push(LiteralFactory.CreateConditionLiteral(compnum1)); Condition numCondition1 = bytes.ReadConditionLiteral(dummyCallback); Assert.IsTrue(numCondition1.Evaluate()); CompareNum compnum2 = new CompareNum(2, -2, ConditionOperator.LESS_THAN); bytes.push(LiteralFactory.CreateConditionLiteral(compnum2)); Condition numCondition2 = bytes.ReadConditionLiteral(dummyCallback); Assert.IsFalse(numCondition2.Evaluate()); }
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 Player() { bytes.push(LiteralFactory.CreatePlayerLiteral(1)); Assert.AreEqual( bytes.ReportStackContent(), "PLAYER(1) " ); }
public void String() { bytes.push(LiteralFactory.CreateStringLiteral("hello world")); Assert.AreEqual( bytes.ReportStackContent(), "STRING(hello world) " ); }
public void BoolBytecode() { bytes.push(LiteralFactory.CreateBoolLiteral(true)); bytes.push(LiteralFactory.CreateBoolLiteral(false)); Assert.IsFalse(bytes.ReadBoolLiteral(dummyCallback)); Assert.IsTrue(bytes.ReadBoolLiteral(dummyCallback)); }
public void Card() { bytes.push(LiteralFactory.CreateCardLiteral("my-card-guid")); Assert.AreEqual( bytes.ReportStackContent(), "CARD(my-card-guid) " ); }
public void Bool() { bytes.push(LiteralFactory.CreateBoolLiteral(true)); Assert.AreEqual( bytes.ReportStackContent(), "BOOL(True) " ); }
public void Int() { bytes.push(LiteralFactory.CreateIntLiteral(4)); Assert.AreEqual( bytes.ReportStackContent(), "INT(4) " ); }
public void Enum() { bytes.push(LiteralFactory.CreateEnumLiteral(200, Instruction.ENUM_DECK_POSITION)); Assert.AreEqual( bytes.ReportStackContent(), "enum:200 " ); }
public void Placeholder() { bytes.push(LiteralFactory.CreatePlaceholderLiteral(99)); Assert.AreEqual( bytes.ReportStackContent(), "PLACEHOLDER(id:99) " ); }
public void PlayerChoiceCallback(GamePlayer chosenPlayer) { if (chosenPlayer != null) { List <byte> player = LiteralFactory.CreatePlayerLiteral(chosenPlayer); GM.AddToStack(player); } next(); }
public void CardChoiceCallback(Card chosenCard) { if (chosenCard != null) { List <byte> card = LiteralFactory.CreateCardLiteral(chosenCard.GetID()); GM.AddToStack(card); } next(); }
public void NegativeIntBytecode() { List <byte> arr = LiteralFactory.CreateIntLiteral(-5); bytes.push(arr); int n = bytes.ReadIntLiteral(dummyCallback); Assert.AreEqual(-5, n); }
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 Multiply() { bytes.push(InstructionFactory.Make_Multiply( LiteralFactory.CreateIntLiteral(4), LiteralFactory.CreateIntLiteral(13) )); game.ExecuteNext(); Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 52); }
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 ReadCounter() { game.Variables.SetCounter("my-key", 11); bytes.push(InstructionFactory.Make_ReadCounter( LiteralFactory.CreateStringLiteral("my-key") )); game.ExecuteNext(); Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 11); }
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 GetPlayerPoints() { game.Players = new PlayerManager(4); GamePlayer target = game.Players.GetPlayer(1); target.Points = 22; bytes.push(InstructionFactory.Make_GetPlayerPoints( LiteralFactory.CreatePlayerLiteral(target) )); game.ExecuteNext(); Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 22); }
public void StringBytecode() { bytes.push(LiteralFactory.CreateStringLiteral("Hello World 👋")); bytes.push(LiteralFactory.CreateStringLiteral("The quick brown fox jumped over the lazy dog.")); bytes.push(LiteralFactory.CreateStringLiteral("Hello World!")); bytes.push(LiteralFactory.CreateStringLiteral("A")); Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "A"); Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "Hello World!"); Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "The quick brown fox jumped over the lazy dog."); Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "Hello World 👋"); }
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 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 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 PlayerBytecode() { game.Players = new PlayerManager(3); GamePlayer[] players = game.Players.GetPlayers(); bytes.push(LiteralFactory.CreatePlayerLiteral(players[0])); bytes.push(LiteralFactory.CreatePlayerLiteral(players[1])); bytes.push(LiteralFactory.CreatePlayerLiteral(players[2])); Assert.AreSame(game.ReadPlayerFromStack(), players[2]); Assert.AreSame(game.ReadPlayerFromStack(), players[1]); Assert.AreSame(game.ReadPlayerFromStack(), players[0]); }