示例#1
0
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public Move(Int16 componentId, FieldLocation toSquare, Tick tick)
     : base(PossibleTypes.Move)
 {
     ComponentId = componentId;
     ToSquare = toSquare;
     EnablingTick = tick;
 }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public GetResource(Int16 gameId, PossibleResourceType type, Tick tick)
     : base(PossibleTypes.GetResource)
 {
     GameId = gameId;
     GetResourceType = type;
     EnablingTick = tick;
 }
示例#3
0
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public Eat(Int16 zombieId, Int16 targetId, Tick tick)
     : base(PossibleTypes.Move)
 {
     ZombieId = zombieId;
     TargetId = targetId;
     EnablingTick = tick;
 }
示例#4
0
 public Bomb(Int16 creatorId, List<Excuse> excuses, List<WhiningTwine> twine, Tick builtOnTick)
 {
     CreatorId = creatorId;
     Excuses = excuses;
     Twine = twine;
     BuiltOnTick = builtOnTick;
 }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public ThrowBomb(Int16 bsId, Bomb bomb, FieldLocation towardsSquare, Tick tick)
     : base(PossibleTypes.Move)
 {
     ThrowingBrilliantStudentId = bsId;
     Bomb = bomb;
     TowardsSquare = towardsSquare;
     EnablingTick = tick;
 }
        public void WhiningSpinner_CheckEncodeAndDecode()
        {
            Tick t1 = new Tick();
            Tick t2 = new Tick();
            Tick t3 = new Tick();
            Tick t4 = new Tick();
            List<Tick> ticks = new List<Tick> { t1, t2, t3 };
            WhiningTwine e1 = new WhiningTwine(10, ticks, t4);
            Assert.AreEqual(10, e1.CreatorId);
            Assert.IsNotNull(e1.Ticks);
            Assert.AreEqual(3, e1.Ticks.Count);
            Assert.AreSame(t1, e1.Ticks[0]);
            Assert.AreSame(t2, e1.Ticks[1]);
            Assert.AreSame(t3, e1.Ticks[2]);
            Assert.AreSame(t4, e1.RequestTick);

            ByteList bytes = new ByteList();
            e1.Encode(bytes);
            WhiningTwine e2 = WhiningTwine.Create(bytes);
            Assert.AreEqual(e1.CreatorId, e2.CreatorId);
            Assert.AreEqual(e1.Ticks.Count, e2.Ticks.Count);
            Assert.AreEqual(e1.Ticks[0].LogicalClock, e2.Ticks[0].LogicalClock);
            Assert.AreEqual(e1.Ticks[0].HashCode, e2.Ticks[0].HashCode);
            Assert.AreEqual(e1.Ticks[1].LogicalClock, e2.Ticks[1].LogicalClock);
            Assert.AreEqual(e1.Ticks[1].HashCode, e2.Ticks[1].HashCode);
            Assert.AreEqual(e1.Ticks[2].LogicalClock, e2.Ticks[2].LogicalClock);
            Assert.AreEqual(e1.Ticks[2].HashCode, e2.Ticks[2].HashCode);
            Assert.AreEqual(e1.RequestTick.LogicalClock, e2.RequestTick.LogicalClock);
            Assert.AreEqual(e1.RequestTick.HashCode, e2.RequestTick.HashCode);

            bytes.Clear();
            e1.Encode(bytes);
            bytes.GetByte();            // Read one byte, which will throw the length off
            try
            {
                e2 = WhiningTwine.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }

            bytes.Clear();
            e1.Encode(bytes);
            bytes.Add((byte)100);       // Add a byte
            bytes.GetByte();            // Read one byte, which will make the ID wrong
            try
            {
                e2 = WhiningTwine.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }
        }
        public void AckNak_CheckConstructorsAndFactories()
        {
            Tick t1 = new Tick();
            AckNak m = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note");
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Success, m.Status);
            Assert.AreEqual(10, m.IntResult);
            Assert.AreSame(t1, m.ObjResult);
            Assert.AreEqual("Test Message", m.Message);
            Assert.AreEqual("Test Note", m.Note);

            m = new AckNak(Reply.PossibleStatus.Failure, 20);
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status);
            Assert.AreEqual(20, m.IntResult);
            Assert.IsNull(m.ObjResult);
            Assert.AreEqual("", m.Message);
            Assert.AreEqual("", m.Note);

            m = new AckNak(Reply.PossibleStatus.Failure, 20, "Test Message");
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status);
            Assert.AreEqual(20, m.IntResult);
            Assert.IsNull(m.ObjResult);
            Assert.AreEqual("Test Message", m.Message);
            Assert.AreEqual("", m.Note);

            m = new AckNak(Reply.PossibleStatus.Failure, t1);
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status);
            Assert.AreEqual(0, m.IntResult);
            Assert.AreSame(t1, m.ObjResult);
            Assert.AreEqual("", m.Message);
            Assert.AreEqual("", m.Note);

            m = new AckNak(Reply.PossibleStatus.Failure, t1, "Test Message");
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status);
            Assert.AreEqual(0, m.IntResult);
            Assert.AreSame(t1, m.ObjResult);
            Assert.AreEqual("Test Message", m.Message);
            Assert.AreEqual("", m.Note);

            ByteList bytes = new ByteList();
            m.Encode(bytes);
            Message msg = Message.Create(bytes);
            Assert.IsNotNull(msg);
            Assert.IsTrue(msg is AckNak);
            AckNak m2 = msg as AckNak;
            Assert.AreEqual(m.Status, m2.Status);
            Assert.AreEqual(m.Note, m2.Note);
        }
        public void TickTester_CheckOtherMethods()
        {
            Tick tick1 = new Tick(10, 20, 30);
            Assert.AreEqual(10, tick1.ForAgentId);
            Assert.AreEqual(20, tick1.LogicalClock);
            Assert.AreEqual(30, tick1.HashCode);
            Assert.IsFalse(tick1.IsValid);

            for (int i = 0; i < 100; i++)
            {
                tick1 = new Tick(10);
                Assert.IsTrue(tick1.IsValid);
                Assert.AreEqual(10, tick1.ForAgentId);
            }
        }
        public void TickTester_CheckEncodeDecode()
        {
            Tick tick1 = new Tick(10);
            tick1.LogicalClock = 100;
            ByteList bytes = new ByteList();
            tick1.Encode(bytes);
            Tick tick2 = Tick.Create(bytes);
            Assert.AreEqual(10, tick1.ForAgentId);
            Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock);

            tick1.LogicalClock = 0;
            bytes = new ByteList();
            tick1.Encode(bytes);
            tick2 = Tick.Create(bytes);
            Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock);

            tick1.LogicalClock = Int32.MaxValue;
            bytes = new ByteList();
            tick1.Encode(bytes);
            tick2 = Tick.Create(bytes);
            Assert.AreEqual(tick1.ForAgentId, tick1.ForAgentId);
            Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock);

            bytes.Clear();
            tick1.Encode(bytes);
            bytes.GetByte();            // Read one byte, which will throw the length off
            try
            {
                tick2 = Tick.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }

            bytes.Clear();
            tick1.Encode(bytes);
            bytes.Add((byte)100);       // Add a byte
            bytes.GetByte();            // Read one byte, which will make the ID wrong
            try
            {
                tick2 = Tick.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }
        }
        public void Bomb_CheckEncodeAndDecode()
        {
            Tick t1 = new Tick();
            List<Excuse> eList = new List<Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) };
            List<WhiningTwine> wtList = new List<WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) };
            Bomb b1 = new Bomb(1, eList, wtList, t1);
            Assert.AreEqual(1, b1.CreatorId);
            Assert.AreSame(eList, b1.Excuses);
            Assert.AreSame(wtList, b1.Twine);
            Assert.AreSame(t1, b1.BuiltOnTick);

            ByteList bytes = new ByteList();
            b1.Encode(bytes);
            Bomb b2 = Bomb.Create(bytes);
            Assert.AreEqual(b1.CreatorId, b2.CreatorId);
            Assert.AreEqual(b1.Excuses.Count, b2.Excuses.Count);
            Assert.AreEqual(b1.Twine.Count, b2.Twine.Count);

            Assert.AreEqual(b1.BuiltOnTick.LogicalClock, b2.BuiltOnTick.LogicalClock);
            Assert.AreEqual(b1.BuiltOnTick.HashCode, b2.BuiltOnTick.HashCode);

            bytes.Clear();
            b1.Encode(bytes);
            bytes.GetByte();            // Read one byte, which will throw the length off
            try
            {
                b2 = Bomb.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }

            bytes.Clear();
            b1.Encode(bytes);
            bytes.Add((byte)100);       // Add a byte
            bytes.GetByte();            // Read one byte, which will make the ID wrong
            try
            {
                b2 = Bomb.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }
        }
        public void TickTester_CheckConstructors()
        {
            Tick tick1 = new Tick(1, 10, 20);
            Assert.AreEqual(1, tick1.ForAgentId);
            Assert.AreEqual(10, tick1.LogicalClock);
            Assert.AreEqual(20, tick1.HashCode);

            tick1 = new Tick(10);
            Assert.AreEqual(10, tick1.ForAgentId);
            Assert.AreEqual(0, tick1.LogicalClock);
            Assert.AreEqual(0, tick1.HashCode);

            tick1 = new Tick();
            Assert.AreEqual(0, tick1.ForAgentId);
            Assert.AreEqual(0, tick1.LogicalClock);
            Assert.AreEqual(0, tick1.HashCode);
        }
        public void AckNak_CheckEncodeDecode()
        {
            Tick t1 = new Tick();
            AckNak m1 = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note");
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m1.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Success, m1.Status);
            Assert.AreEqual(10, m1.IntResult);
            Assert.AreSame(t1, m1.ObjResult);
            Assert.AreEqual("Test Message", m1.Message);
            Assert.AreEqual("Test Note", m1.Note);

            ByteList bytes = new ByteList();
            m1.Encode(bytes);
            AckNak m2 = AckNak.Create(bytes);
            Assert.AreEqual(m1.Status, m2.Status);
            Assert.AreEqual(m1.IntResult, m2.IntResult);
            Assert.AreEqual(((Tick)m1.ObjResult).LogicalClock, ((Tick)m2.ObjResult).LogicalClock);
            Assert.AreEqual(m1.Message, m2.Message);
            Assert.AreEqual(m1.Note, m2.Note);

            bytes.Clear();
            m1.Encode(bytes);
            bytes.GetByte();            // Read one byte, which will throw the length off
            try
            {
                m2 = AckNak.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }

            bytes.Clear();
            m1.Encode(bytes);
            bytes.Add((byte)100);       // Add a byte
            bytes.GetByte();            // Read one byte, which will make the ID wrong
            try
            {
                m2 = AckNak.Create(bytes);
                Assert.Fail("Expected an exception to be thrown");
            }
            catch (ApplicationException)
            {
            }
        }
        public void Bomb_CheckConstructors()
        {
            Bomb b = new Bomb();
            Assert.AreEqual(0, b.CreatorId);
            Assert.IsNotNull(b.Excuses);
            Assert.IsNotNull(b.Twine);
            Assert.AreEqual(0, b.Excuses.Count);
            Assert.AreEqual(0, b.Twine.Count);
            Assert.IsNull(b.BuiltOnTick);

            Tick t1 = new Tick();
            List<Excuse> eList = new List<Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) };
            List<WhiningTwine> wtList = new List<WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) };
            b = new Bomb(1, eList, wtList, t1);
            Assert.AreEqual(1, b.CreatorId);
            Assert.AreSame(eList, b.Excuses);
            Assert.AreSame(wtList, b.Twine);
            Assert.AreSame(t1, b.BuiltOnTick);
        }
        public void WhiningSpinner_CheckConstructors()
        {
            WhiningTwine e = new WhiningTwine();
            Assert.AreEqual(0, e.CreatorId);
            Assert.IsNotNull(e.Ticks);
            Assert.AreEqual(0, e.Ticks.Count);
            Assert.IsNull(e.RequestTick);

            Tick t1 = new Tick();
            Tick t2 = new Tick();
            Tick t3 = new Tick();
            Tick t4 = new Tick();
            List<Tick> ticks = new List<Tick> { t1, t2, t3 };
            e = new WhiningTwine(10, ticks, t4);
            Assert.AreEqual(10, e.CreatorId);
            Assert.IsNotNull(e.Ticks);
            Assert.AreEqual(3, e.Ticks.Count);
            Assert.AreSame(t1, e.Ticks[0]);
            Assert.AreSame(t2, e.Ticks[1]);
            Assert.AreSame(t3, e.Ticks[2]);
            Assert.AreSame(t4, e.RequestTick);
        }
示例#15
0
 void Td_Tick(Tick tick)
 {
     AddTick(tick.Time, tick.Price, tick.Lots);
 }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public Collaborate(Tick tick)
     : base(PossibleTypes.Collaborate)
 {
     EnablingTick = tick;
 }
 public WhiningTwine(Int16 creatorId, List<Tick> ticks, Tick requestTick)
 {
     CreatorId = creatorId;
     Ticks = ticks;
     RequestTick = requestTick;
 }
示例#18
0
 public Excuse(Int16 creatorId, List <Tick> ticks, Tick requestTick)
 {
     CreatorId   = creatorId;
     Ticks       = ticks;
     RequestTick = requestTick;
 }
示例#19
0
 /// <summary>
 /// Factor method to create a FieldLocation from a byte list
 /// </summary>
 /// <param name="bytes">A byte list from which the distributable object will be decoded</param>
 /// <returns>A new object of this class</returns>
 public static new Tick Create(ByteList bytes)
 {
     Tick result = new Tick();
     result.Decode(bytes);
     return result;
 }
        public void TickTester_CheckProperties()
        {
            Tick tick1 = new Tick(1);
            tick1.LogicalClock = 100;
            Assert.AreEqual(1, tick1.ForAgentId);
            Assert.AreEqual(100, tick1.LogicalClock);
            Assert.AreEqual(0, tick1.HashCode);

            tick1.ForAgentId = 200;
            Assert.AreEqual(200, tick1.ForAgentId);
        }
示例#21
0
 public Excuse(Int16 creatorId, List<Tick> ticks, Tick requestTick)
 {
     CreatorId = creatorId;
     Ticks = ticks;
     RequestTick = requestTick;
 }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public TickDelivery(Tick tick)
     : base(PossibleTypes.TickDelivery)
 {
     CurrentTick = tick;
 }
        public void Bomb_CheckProperties()
        {
            Tick t1 = new Tick();
            List<Excuse> eList = new List<Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) };
            List<WhiningTwine> wtList = new List<WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) };
            Bomb b = new Bomb(1, eList, wtList, t1);
            Assert.AreEqual(1, b.CreatorId);
            Assert.AreSame(eList, b.Excuses);
            Assert.AreSame(wtList, b.Twine);
            Assert.AreSame(t1, b.BuiltOnTick);

            b.CreatorId = 135;
            Assert.AreEqual(135, b.CreatorId);
            b.CreatorId = 0;
            Assert.AreEqual(0, b.CreatorId);
            b.CreatorId = Int16.MaxValue;
            Assert.AreEqual(Int16.MaxValue, b.CreatorId);

            b.Excuses = new List<Excuse>();
            Assert.IsNotNull(b.Excuses);
            Assert.AreNotSame(eList, b.Excuses);
            b.Excuses = eList;
            Assert.AreSame(eList, b.Excuses);

            b.Twine = new List<WhiningTwine>();
            Assert.IsNotNull(b.Twine);
            Assert.AreNotSame(wtList, b.Twine);
            b.Twine = wtList;
            Assert.AreSame(wtList, b.Twine);
        }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public ValidateTick(Int16 componentId, Tick tick)
     : base(PossibleTypes.ValidateTick)
 {
     ComponentId = componentId;
     TickToValidate = tick;
 }
        public void WhiningSpinner_CheckProperties()
        {
            Tick t1 = new Tick();
            Tick t2 = new Tick();
            Tick t3 = new Tick();
            Tick t4 = new Tick();
            List<Tick> ticks = new List<Tick> { t1, t2, t3 };
            WhiningTwine e = new WhiningTwine(10, ticks, t4);
            Assert.AreEqual(10, e.CreatorId);
            Assert.IsNotNull(e.Ticks);
            Assert.AreEqual(3, e.Ticks.Count);
            Assert.AreSame(t1, e.Ticks[0]);
            Assert.AreSame(t2, e.Ticks[1]);
            Assert.AreSame(t3, e.Ticks[2]);
            Assert.AreSame(t4, e.RequestTick);

            e.CreatorId = 135;
            Assert.AreEqual(135, e.CreatorId);
            e.CreatorId = 0;
            Assert.AreEqual(0, e.CreatorId);
            e.CreatorId = Int16.MaxValue;
            Assert.AreEqual(Int16.MaxValue, e.CreatorId);

            e.Ticks = null;
            Assert.IsNull(e.Ticks);
            e.Ticks = ticks;
            Assert.AreSame(ticks, e.Ticks);

            e.RequestTick = null;
            Assert.IsNull(e.RequestTick);
            e.RequestTick = t4;
            Assert.AreSame(t4, e.RequestTick);
        }
        public void AckNak_CheckProperties()
        {
            Tick t1 = new Tick();
            AckNak m = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note");
            Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType);
            Assert.AreEqual(Reply.PossibleStatus.Success, m.Status);
            Assert.AreEqual(10, m.IntResult);
            Assert.AreSame(t1, m.ObjResult);
            Assert.AreEqual("Test Message", m.Message);
            Assert.AreEqual("Test Note", m.Note);

            m.IntResult = 200;
            Assert.AreEqual(200, m.IntResult);

            m.ObjResult = null;
            Assert.IsNull(m.ObjResult);
            m.ObjResult = t1;
            Assert.AreSame(t1, m.ObjResult);

            m.Message = "Testing";
            Assert.AreEqual("Testing", m.Message);

            m.Note = "Test Note";
            Assert.AreEqual("Test Note", m.Note);

            Assert.AreEqual( Message.MESSAGE_CLASS_IDS.AckNak, m.MessageTypeId());
        }
示例#27
0
 public Bomb(Int16 creatorId, List <Excuse> excuses, List <WhiningTwine> twine, Tick builtOnTick)
 {
     CreatorId   = creatorId;
     Excuses     = excuses;
     Twine       = twine;
     BuiltOnTick = builtOnTick;
 }