示例#1
0
        public void GzipSelfReferencedState()
        {
            // Arrange
            var beginningState = StateGenerator.GenerateSelfRefereningState();

            // Act
            var zipped = beginningState.Zippify();

            var unzipped = zipped.Unzippify <SelfReferencingState>();
        }
        public GameOfLife(IInputReader inputReader, IOutputWriter outputWriter)
        {
            StateGenerator = new StateGenerator();
            var inputProcessor = new WorldBuilder(inputReader);

            GridFormatter = new GridFormatter();
            OutputWriter  = outputWriter;

            World = inputProcessor.GetWorld();

            DisplayInitialGameOutput();
        }
示例#3
0
        static void Main(string[] args)
        {
            // todo read from file
            var grammar = new Grammar("S -> a S b S\nS -> a");
            var states  = new StateGenerator(grammar);

            states.PrintStates();

            var table = new ParseTable(grammar, states.States);

            Console.WriteLine();
            table.Print();
        }
示例#4
0
文件: Program.cs 项目: YouJinTou/BNQ
        static GameState GetStartState(bool isDeterministic)
        {
            if (!isDeterministic)
            {
                return(StateGenerator.GenerateState());
            }

            var heroHand    = isDeterministic ? Card.d6 | Card.d5 : BoardGenerator.GenerateHand();
            var villainHand = Card.None;
            var flop        = isDeterministic ?
                              Card.c3 | Card.d4 | Card.c9 : BoardGenerator.GenerateFlop(heroHand | villainHand);
            var hero    = new Player(heroHand, Position.SB, 99.5, true, true);
            var villain = new Player(villainHand, Position.BB, 98.25, false);
            var state   = StateFactory.CreateStartState(
                flop, Street.Flop, hero, villain, 2.25, 0.75d, Action.Bet50);

            return(state);
        }
示例#5
0
 public void Setup()
 {
     TestGrammar   = new Grammar("S -> a S b S\nS -> a");
     TestGenerator = new StateGenerator(TestGrammar);
 }
示例#6
0
 public void addState(string name, StateGenerator <T> generator)
 {
     stateHash.Add(name, generator);
 }
示例#7
0
    public static void WindowOpen()
    {
        Init();

        window = EditorWindow.GetWindow <StateGenerator>("SateGen");
    }
 public FooMerchant_RP(Entity principal) : base(principal)
 {
     stateGenerator = new StateGenerator(principal);
 }
        public void Step()
        {
            World = StateGenerator.GetNextState(World);

            DisplayWorldState();
        }
示例#10
0
        /// <summary>
        /// Given an underlying analysis and generator for a bottom value, this method computes a mapping between a state of
        /// the iterator and fixpoint information computed by the underlying analysis for the slice that corresponds to that
        /// state.
        ///
        /// The analysis runs the underlying analyzer on state 0, the initial state, first. The state from the return point
        /// of this state will be the current value of the invariant candidate.
        /// Then for every continuing state (the state from which a new item is generated for the ienumerable result), we map
        /// the current invariant candidate and map it to the entry of the method, and run the underlying analysis for that
        /// state. Running the underlying analysis for a particular state requires a set of program points, which are the entry
        /// points of other slices. The underlying analysis will mark those program points as unreachable. The exit abstract
        /// state will become the current invariant candidate. This process finishes when a fixedpoint is reached.
        /// </summary>
        /// <typeparam name="MyDomain">The domain of the underlying analysis.</typeparam>
        /// <param name="analysis">The underlying analysis.</param>
        /// <param name="bv">A delegate that generates a bottom value for MyDomain.</param>
        /// <returns></returns>
        public FunctionalMap <int, IMethodAnalysisFixPoint <Variable> > Analyze <MyDomain>(
            IMoveNextOnePassAnalysis <Local, Parameter, Method, Field, Property, Type, Expression, Attribute, Assembly, MyDomain, Variable> analysis,
            StateGenerator <MyDomain> bv)
        {
            // Use a pre-analysis to collect information regarding the state machine.
            MoveNextStateAnalyzer           preAnalyzer = new MoveNextStateAnalyzer();
            StateMachineInformation <Local> stateInfo   = preAnalyzer.AnalyzeMoveNext("MoveNext", driver);

            // If we are not able
            if (stateInfo.OrderedVisibleStates == null || stateInfo.OrderedVisibleStates.Count() == 0)
            {
                throw new ArgumentException("Argument error with MoveNext method: Cannot analyze the state machine.");
            }

            // Fix point computation: fixpoint of the iterator analysis is a mapping: answers.
            bool     fixedpointReached = false;
            MyDomain d = default(MyDomain), oldd = default(MyDomain);
            FunctionalMap <int, IMethodAnalysisFixPoint <Variable> > answers = FunctionalMap <int, IMethodAnalysisFixPoint <Variable> > .Empty;
            MyDomain invariantCandidate   = default(MyDomain);
            Converter <Variable, int> key = driver.KeyNumber;

            int pass = 0;

            while (!fixedpointReached)
            {
                fixedpointReached = true;
                // Going through every state of the state machine, if the final states changes at least once
                // then fixpoint is not reached.
                foreach (int state in stateInfo.OrderedVisibleStates)
                {
                    // The initial state is only analyzed once.
                    if (state < 0)
                    {
                        continue;
                    }
                    if (state == 0 && pass > 0)
                    {
                        continue;
                    }

                    // Initial value for one pass, either TOP, if we analyze it for the first time
                    // or the invariantCandidate.
                    if (invariantCandidate == null || invariantCandidate.Equals(default(MyDomain)))
                    {
                        d = analysis.GetInitialValue(key);
                    }
                    else
                    {
                        d = analysis.MutableVersion(invariantCandidate);
                    }

                    // Call the underlying analysis for one pass
                    Set <APC> cutOffPCs = GetStateEntriesOtherThan(stateInfo, state);
                    driver.CreateForwardForIterator(analysis, bv, cutOffPCs)(d);

                    // Getting the state from the return point of the most recent pass, map it
                    // to the entry point, and join it with the current invariant candidate
                    IFunctionalMap <Variable, FList <Variable> > mapping = GetFieldMapping(driver);
                    var      fakeEdge    = new Pair <APC, APC>(driver.CFG.NormalExit, driver.CFG.Entry);
                    MyDomain returnState = analysis.ReturnState;
                    MyDomain newState    = analysis.ParallelAssign(fakeEdge, mapping, returnState);
                    bool     changed     = false;
                    if (invariantCandidate != null && !invariantCandidate.Equals(default(MyDomain)))
                    {
                        oldd = invariantCandidate;
                        // TODO: use a more sophisticated widenning strategy.
                        bool toWiden = (pass > 2) ? true : false;
                        d = analysis.Join(fakeEdge, newState, oldd, out changed, toWiden);
                        if (changed)
                        {
                            invariantCandidate = d;
                        }
                    }
                    else
                    {
                        changed            = true;
                        invariantCandidate = newState;
                    }
                    if (changed)
                    {
                        fixedpointReached = false;
                    }

                    // Fill the result table with the most recent fixpoint information.
                    answers  = (FunctionalMap <int, IMethodAnalysisFixPoint <Variable> >)answers.Add(state, analysis.ExtractResult());
                    analysis = analysis.Duplicate();
                }
                pass++;
            }
            return(answers);
        }
示例#11
0
文件: Program.cs 项目: YouJinTou/BNQ
        static void MeasureTimes()
        {
            var stopWatch = new Stopwatch();

            Evaluator.Initialize();

            while (true)
            {
                var roots = new List <GameState>();

                System.Console.Clear();

                stopWatch.Reset();

                stopWatch.Start();

                var root = StateGenerator.GenerateState();

                for (int i = 0; i < 3; i++)
                {
                    roots.Add(RunSimulation(GameState.CopyState(root), false));
                }

                System.Console.WriteLine(stopWatch.Elapsed.ToString());

                System.Console.WriteLine(roots.First().Hero);

                System.Console.WriteLine(roots.First());

                var m        = 10000d;
                var averages = new Dictionary <Action, double>();

                foreach (IEnumerable <State> children in roots.Select(r => r.Children))
                {
                    foreach (GameState child in children)
                    {
                        if (averages.ContainsKey(child.LastAction))
                        {
                            averages[child.LastAction] += (child.AverageValue / children.Count());
                        }
                        else
                        {
                            averages.Add(child.LastAction, (child.AverageValue / children.Count()));
                        }
                    }
                }

                foreach (var average in averages)
                {
                    var avg = string.Format("{0:0.00000}", m * average.Value);

                    System.Console.WriteLine($"{average.Key}: {avg}");
                }

                System.Console.ReadLine();

                roots.Last().Print();

                System.Console.ReadLine();
            }
        }