Esempio n. 1
0
        public void Add(TimeSpan?time, BoardInfo scan)
        {
            int?   parent;
            double changeCost;

            FindParent(scan, out parent, out changeCost);
            if (changeCost == 0 && parent == Game.Replay.Actions.Count - 1)
            {
                return;
            }
            if (time != null)
            {
                Replay.SetEndTime((TimeSpan)time);
            }
            if (parent == null)
            {
                Replay.AddAction(new CreateBoardAction(scan.Width, scan.Height));
                parent = Replay.Actions.Count - 1;
            }
            else
            {
                Replay.AddAction(new SelectStateAction((int)parent));
            }
            FillImages();
            BoardInfo old = Images[(int)parent];

            Debug.Assert(old.Width == scan.Width && old.Height == scan.Height);
            foreach (GameAction action in StateDelta.Delta(BoardToGameState(old), BoardToGameState(scan)))
            {
                Replay.AddAction(action);
            }
        }
Esempio n. 2
0
        public static void ApplyDelta(State state, StateDelta delta)
        {
            var deltaState = delta.State;

            state.ApplyMutableFrom(deltaState, deltaState.Flags);

            state.ResetControllerData();
            if (deltaState.HasControllerData)
            {
                state.ApplyControllerFrom(deltaState);
            }

            state.HasControllerData = deltaState.HasControllerData;

            state.HasImmutableData = deltaState.HasImmutableData || state.HasImmutableData;
            if (deltaState.HasImmutableData)
            {
                state.ApplyImmutableFrom(deltaState);
            }
        }
Esempio n. 3
0
    public bool SetState(string jsonState)
    {
        if (!startUIControl.gameStarted)
        {
            return(false);
        }
        else
        {
            // Parse the JSON
            StateDelta stateDelta = JsonUtility.FromJson <StateDelta>(jsonState);

            SetSeed(seed.ToString());
            SetCharacter("Human");
            setGame.reset = true;
            SetNumCards(stateDelta.cards.Length);
            propPlacement.PlaceCardsWithState(stateDelta.cards, stateDelta.lead, stateDelta.follow);
            propPlacement.PlacePlayersWithState(stateDelta.lead, stateDelta.follow);
            return(true);
        }
    }
Esempio n. 4
0
        public static string Export(Replay replay)
        {
            Game              game     = new Game(replay);
            GameState         oldState = null;
            List <GameAction> actions  = new List <GameAction>();

            for (int i = 0; i < replay.Actions.Count; i++)
            {
                if (replay.Actions[i] is ReplayTimeAction)
                {
                    actions.Add(replay.Actions[i]);
                }
                game.Seek(i);
                List <GameAction> newActions = StateDelta.Delta(oldState, game.State);
                actions.AddRange(newActions);
                if (game.State != null)
                {
                    oldState = game.State.Clone();
                }
            }
            List <JObject> jActions = new List <JObject>();
            TimeSpan       time     = TimeSpan.Zero;

            foreach (var action in actions)
            {
                if (action is ReplayTimeAction)
                {
                    time = ((ReplayTimeAction)action).Time;
                }
                else
                {
                    jActions.Add(SerializeAction(action, time));
                }
            }
            JObject json = new JObject(new JProperty("changes", new JArray(jActions)));

            return(json.ToString(Newtonsoft.Json.Formatting.None));
        }