コード例 #1
0
ファイル: Program.cs プロジェクト: DenisStolyarov/OOP-2
        private static void MoveHero()
        {
            IComponent hero = null;

            while (hero is null)
            {
                hero = GetComponent();
            }

            var stayState     = new SingleState(new StayCommand());
            var runState      = new SingleState(new RunCommand());
            var jumpState     = new ComplexState(new JumpCommand(), stayState);
            var attackState   = new ComplexState(new AttackCommand(), stayState);
            var heroContext   = new Context(stayState, hero.Title);
            var stateRestorer = new Restorer(heroContext);

            Console.WriteLine("Game start!");
            do
            {
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.UpArrow:
                    heroContext.Update(jumpState);
                    stateRestorer.BackUp();
                    break;

                case ConsoleKey.LeftArrow:
                    heroContext.Update(runState);
                    stateRestorer.BackUp();
                    break;

                case ConsoleKey.RightArrow:
                    heroContext.Update(runState);
                    stateRestorer.BackUp();
                    break;

                case ConsoleKey.DownArrow:
                    heroContext.Update(attackState);
                    stateRestorer.BackUp();
                    break;

                case ConsoleKey.Escape:
                    return;

                default:
                    stateRestorer.Undo();
                    break;
                }

                heroContext.Request();
            } while (true);
        }
コード例 #2
0
        private IEnumerable <string> reportDfa(IEnumerable <string> nfaStateIndices = null)
        {
            if (dfa != null)
            {
                string rep = dfa.ToString(nfaStateIndices);
                if (rep != "")
                {
                    return new string[] { "# " + SingleState <SYMBOL_ENUM, TREE_NODE> .ToStringFormat(), Environment.NewLine, rep }
                }
                ;
            }

            return(Enumerable.Empty <string>());
        }
    // accessed when the state mod should be change - looks for new/next mode
    // and saves it to currentState variable
    void ReadData(string transferToState)
    {
        string             iterateStateID;
        List <SingleState> singleStateList = outputStates.singleStates;

        foreach (SingleState n in singleStateList)
        {
            iterateStateID = n.stateID;
            if (iterateStateID.Equals(transferToState))
            {
                currentState = n;
                Log("Mode changed to " + currentState.stateID);
                break;
            }
        }
        if (currentState == null)
        {
            Debug.Log("No <" + transferToState + "> state found in given Json.");
        }
    }
コード例 #4
0
        static void Main(string[] args)
        {
            Graph graph;

            {
                Console.WriteLine("Loading Graph...");
                StreamReader reader = new StreamReader("sample-graph.txt");
                string       line   = reader.ReadLine();
                graph = new Graph(int.Parse(line));

                string[] names = reader.ReadLine().Split(' ');
                int      i     = 0;
                foreach (string name in names)
                {
                    if (name != "")
                    {
                        graph.NameVertex(i, name);
                    }
                    i++;
                }

                while (!reader.EndOfStream)
                {
                    string[] row    = reader.ReadLine().Split(' ');
                    string   v1     = row[0];
                    string   v2     = row[1];
                    int      weight = int.Parse(row[2]);
                    graph.AddEdge(v1, v2, weight);
                }

                Console.WriteLine(graph);
            }

            SingleState.Run(graph);

            Console.WriteLine("==========");

            BasicDiscretePopulation.Run(graph);

            Console.Read();
        }
 // read file and determine current state
 void InitialReadData()
 {
     // path is set here
     path = Application.persistentDataPath + "/" + filename;
     Debug.Log(path);
     try
     {
         if (System.IO.File.Exists(path))
         {
             string jsonData = System.IO.File.ReadAllText(path);
             outputStates = JsonUtility.FromJson <JsonStates>(jsonData);
             // Debug.Log(inputStates.singleStates);
             List <SingleState> singleStateList = outputStates.singleStates;
             string             currentStateID;
             foreach (SingleState n in singleStateList)
             {
                 currentStateID = n.stateID;
                 if (currentStateID.Equals("default"))
                 {
                     currentState = n;
                     Debug.Log("State found successfull.");
                     break;
                 }
             }
             if (currentState == null)
             {
                 Debug.Log("No <default> state found in given Json.");
             }
         }
         else
         {
             Debug.Log("File does not exist.");
         }
     }
     catch (System.Exception e)
     {
         Debug.Log("Unknown exception: " + e.Message);
     }
 }
コード例 #6
0
        private bool disambiguateShiftReduceConflictOnHorizon(SingleState <SYMBOL_ENUM, TREE_NODE> shiftItem,
                                                              ReductionAction <SYMBOL_ENUM, TREE_NODE> reduceAction)
        {
            foreach (SYMBOL_ENUM incoming in shiftItem.RhsUnseenSymbols)
            {
                if (!coverSets[incoming].Overlaps(coverSets[reduceAction.Cell.LhsSymbol]) &&
                    !coverSets[incoming].Overlaps(reduceAction.AcceptHorizon))
                {
                    // we have to use cover set, and not the incoming symbol, because
                    // it could be non-terminal, and those do NOT exist by definition in the input stream, only on stack
                    reduceAction.RejectHorizon.Add(coverSets[incoming]);
                    return(true);
                }
            }

            if (!shiftItem.AfterLookaheads.Overlaps(coverSets[reduceAction.Cell.LhsSymbol]) &&
                !shiftItem.AfterLookaheads.Overlaps(reduceAction.AcceptHorizon))
            {
                reduceAction.RejectHorizon.Add(shiftItem.AfterLookaheads);
                return(true);
            }

            return(false);
        }
コード例 #7
0
 public void AddReduce(int sourceNodeId, SymbolChunk <SYMBOL_ENUM> inputChunk, SingleState <SYMBOL_ENUM, TREE_NODE> reductionItem)
 {
     setSingle(sourceNodeId, inputChunk, new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, ReductionAction.Create(reductionItem.CreateCell())));
 }
コード例 #8
0
        internal static ReductionAction <SYMBOL_ENUM, TREE_NODE> Create <SYMBOL_ENUM, TREE_NODE>(SingleState <SYMBOL_ENUM, TREE_NODE> state,
                                                                                                 CoverSets <SYMBOL_ENUM> coverSets,
                                                                                                 HorizonSets <SYMBOL_ENUM> horizonSets)
            where SYMBOL_ENUM : struct
            where TREE_NODE : class
        {
            SymbolChunkSet <SYMBOL_ENUM> cover   = coverSets[state.LhsSymbol];
            SymbolChunkSet <SYMBOL_ENUM> horizon = horizonSets[state.LhsSymbol];
            // if we have internal conflict between symbols, we cannot use horizon data (because we couldn't tell if we reached horizon)
            bool use_horizon = !horizon.IsEmpty && !cover.Overlaps(horizon);
            var  action      = new ReductionAction <SYMBOL_ENUM, TREE_NODE>(state.CreateCell(), use_horizon ? horizon : null,
                                                                            use_horizon ? new SymbolChunkSet <SYMBOL_ENUM>() : null);

            return(action);
        }