Example #1
0
        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);
        }
Example #2
0
 public void Placeholder()
 {
     bytes.push(LiteralFactory.CreatePlaceholderLiteral(99));
     Assert.AreEqual(
         bytes.ReportStackContent(),
         "PLACEHOLDER(id:99) "
         );
 }
Example #3
0
        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());
        }
Example #4
0
        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);
        }
Example #5
0
        public void NestedForLoop()
        {
            game.Players = new PlayerManager(2);
            GamePlayer P1 = game.Players.GetPlayer(0);
            GamePlayer P2 = game.Players.GetPlayer(1);

            for (int i = 0; i < 2; i++)
            {
                P1.Hand.AddCard(new TestCard());
                P2.Hand.AddCard(new TestCard());
                P2.Hand.AddCard(new TestCard());
            }

            Assert.AreEqual(2, P1.Hand.GetSize());
            Assert.AreEqual(4, P2.Hand.GetSize());

            List <byte> innerCode = InstructionFactory.Make_MoveToDiscard(
                LiteralFactory.CreatePlaceholderLiteral(2)
                );
            List <byte> innerList = new List <byte>();

            innerList.AddRange(LiteralFactory.CreatePlaceholderLiteral(1));
            innerList.Add((byte)Instruction.GET_CARDS_IN_HAND);

            List <byte> innerLoop = InstructionFactory.Make_ForLoop(innerList, innerCode, 2);

            List <byte> outerList = new List <byte> {
                (byte)Instruction.GET_ALL_PLAYERS
            };
            List <byte> outerLoop = InstructionFactory.Make_ForLoop(outerList, innerLoop, 1);

            bytes.push(outerLoop);

            game.ExecuteNext();
            game.ExecuteNext();

            while (bytes.HasBytes())
            {
                game.ExecuteNext();
            }

            Assert.AreEqual(0, P1.Hand.GetSize());
            Assert.AreEqual(0, P2.Hand.GetSize());
        }