Exemple #1
0
        public static ButtonCondition ReadButtonCondition(this ISwfStreamReader reader)
        {
            var res = new ButtonCondition {
                IdleToOverDown    = reader.ReadBit(),
                OutDownToIdle     = reader.ReadBit(),
                OutDownToOverDown = reader.ReadBit(),
                OverDownToOutDown = reader.ReadBit(),
                OverDownToOverUp  = reader.ReadBit(),
                OverUpToOverDown  = reader.ReadBit(),
                OverUpToIdle      = reader.ReadBit(),
                IdleToOverUp      = reader.ReadBit(),
                KeyPress          = (byte)reader.ReadUnsignedBits(7),
                OverDownToIdle    = reader.ReadBit()
            };

            var        ar = new ActionReader(reader);
            ActionBase action;

            do
            {
                action = ar.ReadAction();
                res.Actions.Add(action);
            } while (!(action is ActionEnd));
            return(res);
        }
        public void Sanity()
        {
            Mock <MovementDisplayNamesResolver> movementDisplayNamesResolver = new Mock <MovementDisplayNamesResolver>(MockBehavior.Strict, new object[] { null });
            Mock <LegalMovesCalculator>         legalMovesCalculator         = new Mock <LegalMovesCalculator>();
            Mock <IO.IO> io               = new Mock <IO.IO>();
            string       endGameSymbol    = RandomString(100);
            string       newGameSymbol    = RandomString(100);
            string       movements        = RandomString(100);
            string       expectedResponse = RandomString(100);
            ActionReader actionReader     = new ActionReader(newGameSymbol, endGameSymbol, movementDisplayNamesResolver.Object,
                                                             legalMovesCalculator.Object, io.Object);

            legalMovesCalculator.Setup(lmc => lmc.GetLegalMoves(It.IsAny <Board>())).Returns(new List <Movement>());
            movementDisplayNamesResolver.Setup(mdnr => mdnr.Render(It.IsAny <List <Movement> >())).Returns(movements);
            io.Setup(o =>
                     o.Read(Match.Create <string>(msg =>
                                                  msg.Contains(endGameSymbol) &&
                                                  msg.Contains(newGameSymbol) &&
                                                  msg.Contains(movements))))
            .Returns(expectedResponse);

            string response = actionReader.ReadAction(new Board());

            Assert.Equal(expectedResponse, response);
        }
Exemple #3
0
        public static ClipActionRecord ReadClipActionRecord(this ISwfStreamReader reader, byte swfVersion)
        {
            var record = new ClipActionRecord();

            record.Flags = reader.ReadClipEventFlags(swfVersion);
            if (record.Flags.IsEmpty)
            {
                return(record);
            }

            var offset = reader.ReadUInt32();

            if (record.Flags.ClipEventKeyPress)
            {
                record.KeyCode = reader.ReadByte();
            }

            ActionBase action;
            var        ar = new ActionReader(reader);

            do
            {
                action = ar.ReadAction();
                record.Actions.Add(action);
            } while (!(action is ActionEnd));

            return(record);
        }
Exemple #4
0
        SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DoActionTag tag, ISwfStreamReader reader)
        {
            var        actionReader = new ActionReader(reader);
            ActionBase action;

            do
            {
                action = actionReader.ReadAction();
                tag.ActionRecords.Add(action);
            } while (!(action is ActionEnd));
            return(tag);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var readInput = new ActionReader();
            var player1   = new Player(PlayerType.Human, "test_player_1");
            var player2   = new Player(PlayerType.Human, "test_player_2");

            var players = new[] { player1, player2 };

            var game = new Game(players, Round.Two);

            game.StartGame();
        }
Exemple #6
0
        protected T ReadAction <T>(byte[] source) where T : ActionBase
        {
            var mem = new MemoryStream();

            mem.Write(source, 0, source.Length);
            mem.Seek(0, SeekOrigin.Begin);
            var reader       = new SwfStreamReader(mem);
            var actionReader = new ActionReader(reader);
            var action       = actionReader.ReadAction();

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of stream");
            return((T)action);
        }
Exemple #7
0
        public Player(PlayerType playerType, string name, ActionReader actionReader)
        {
            PlayerType         = playerType;
            Name               = name;
            Random             = new Random();
            RolledDice         = new int[6];
            FixedDice          = Enumerable.Repeat(false, 6).ToArray();
            TotalNumberOfRolls = 0;
            Board              = new Board();
            CombinationList    = new CombinationList();
            ActionReader       = actionReader;
            CombinationToPlay  = CombinationType.Unknown;
            FirstAction        = false;
            Round              = Round.One;

            // PatternProbabilities - Load list of all possible pattern probabilities
            PatternProbabilities = GameUtility.CreatePatternProbabilitiesDictionary();
        }
Exemple #8
0
 public void ReadOneByteActionsTest()
 {
     var vals = Enum.GetValues(typeof(ActionCode));
     foreach (ActionCode type in vals) {
         if ((byte)type < 0x80) {
             var mem = new MemoryStream();
             mem.WriteByte((byte)type);
             mem.Seek(0, SeekOrigin.Begin);
             var reader = new SwfStreamReader(mem);
             var actionReader = new ActionReader(reader);
             var action = actionReader.ReadAction();
             Assert.IsNotNull(action);
             var actualType = action.ActionCode;
             Assert.AreEqual(type, actualType);
             Assert.AreEqual(1, mem.Position);
         }
     }
 }
        public static ClipActionRecord ReadClipActionRecord(this ISwfStreamReader reader, byte swfVersion)
        {
            var record = new ClipActionRecord();
            record.Flags = reader.ReadClipEventFlags(swfVersion);
            if (record.Flags.IsEmpty) return record;

            var offset = reader.ReadUInt32();
            if (record.Flags.ClipEventKeyPress) {
                record.KeyCode = reader.ReadByte();
            }

            ActionBase action;
            var ar = new ActionReader(reader);
            do {
                action = ar.ReadAction();
                record.Actions.Add(action);
            } while (!(action is ActionEnd));

            return record;
        }
Exemple #10
0
        public void ReadOneByteActionsTest()
        {
            var vals = Enum.GetValues(typeof(ActionCode));

            foreach (ActionCode type in vals)
            {
                if ((byte)type < 0x80)
                {
                    var mem = new MemoryStream();
                    mem.WriteByte((byte)type);
                    mem.Seek(0, SeekOrigin.Begin);
                    var reader       = new SwfStreamReader(mem);
                    var actionReader = new ActionReader(reader);
                    var action       = actionReader.ReadAction();
                    Assert.IsNotNull(action);
                    var actualType = action.ActionCode;
                    Assert.AreEqual(type, actualType);
                    Assert.AreEqual(1, mem.Position);
                }
            }
        }
Exemple #11
0
        public static ButtonCondition ReadButtonCondition(this ISwfStreamReader reader)
        {
            var res = new ButtonCondition {
                IdleToOverDown = reader.ReadBit(),
                OutDownToIdle = reader.ReadBit(),
                OutDownToOverDown = reader.ReadBit(),
                OverDownToOutDown = reader.ReadBit(),
                OverDownToOverUp = reader.ReadBit(),
                OverUpToOverDown = reader.ReadBit(),
                OverUpToIdle = reader.ReadBit(),
                IdleToOverUp = reader.ReadBit(),
                KeyPress = (byte)reader.ReadUnsignedBits(7),
                OverDownToIdle = reader.ReadBit()
            };

            var ar = new ActionReader(reader);
            ActionBase action;
            do {
                action = ar.ReadAction();
                res.Actions.Add(action);
            } while (!(action is ActionEnd));
            return res;
        }
 public DefaultRelationshipAnalyzer(String actionfilepath)
 {
     this.map = ActionReader.ReadFile(actionfilepath);
 }
Exemple #13
0
 void OnDestroy()
 {
     _instance = null;
 }
Exemple #14
0
 void Awake()
 {
     _instance = this;
 }
Exemple #15
0
        public PlayerAction NextAction()
        {
            // Round ends either by a player ending their turn voluntarily, assigning a combination or running out of rolls
            DisplayActionList(Round, FirstAction);

            var(action, param) = ActionReader.GetNextAction(Round, FirstAction);

            switch (action)
            {
            case PlayerAction.RollDice:
                RollDice(true);
                return(action);

            case PlayerAction.FixDice:
                FixDice(param);
                return(action);

            case PlayerAction.AssignCombination:
                if (TryAssignCombination(param[0]))
                {
                    return(action);
                }
                else
                {
                    return(PlayerAction.InvalidAction);
                };

            case PlayerAction.PickCombinationToPlay:
                if (TryToSetCombinationToPlay(param[0]))
                {
                    return(action);
                }
                else
                {
                    return(PlayerAction.InvalidAction);
                };

            case PlayerAction.ShowBoard:
                ShowBoard();
                return(action);

            case PlayerAction.EndTurn:
                if (CombinationToPlay != CombinationType.Unknown)
                {
                    Board.CurrentBoard[CombinationToPlay].Score     = 0;
                    Board.CurrentBoard[CombinationToPlay].Completed = true;
                }
                return(action);

            case PlayerAction.InvalidAction:
                Console.WriteLine("Invalid action!");
                return(action);

            case PlayerAction.EndGame:
                return(action);

            case PlayerAction.EvaluateAllCombinations:
                EvaluateAllCombinations();
                return(action);


            // Action for testing purposes
            case PlayerAction.AssignDice:
                RolledDice = param;
                EvaluateDice();
                DisplayDice();
                DisplayPossibleCombinations(CurrentPossibleCombinations);
                return(action);

            default:
                throw new Exception();
            }
        }