Пример #1
0
        public static IPage <T> List <T>(this GridCommand command, int pageSize)
            where T : class, IEntity <T>
        {
            var def = GridParser.Parse <T>(command, pageSize);

            return(Entity <T> .Linq(def.Map, def.Reduce));
        }
Пример #2
0
        public static int BurstsCausingInfection(IList <string> input)
        {
            Grid infectionGridMap = GridParser.Parse(input);

            HashSet <Point> originallyInfected = new HashSet <Point>(infectionGridMap.Where(x => x.value).Select(x => x.point));
            HashSet <Point> currentlyInfected  = new HashSet <Point>(originallyInfected);

            var currentX = infectionGridMap.Width / 2;
            var currentY = infectionGridMap.Height / 2;

            Point     currentPosition  = new Point(currentX, currentY);
            Direction currentDirection = Direction.North;
            int       infectedCount    = 0;

            for (int i = 0; i < 10000; i++)
            {
                var currentDisplay = PrintCurrent(currentPosition, currentlyInfected, new HashSet <Point>(), new HashSet <Point>());

                if (currentlyInfected.Contains(currentPosition))
                {
                    currentDirection = currentDirection.Turn(Turn.Right);
                    currentlyInfected.Remove(currentPosition);
                }
                else
                {
                    currentDirection = currentDirection.Turn(Turn.Left);
                    currentlyInfected.Add(currentPosition);
                    infectedCount++;
                }
                currentPosition = currentPosition.Move(currentDirection);
            }

            return(infectedCount);
        }
        public static void Run(int size, int iterations, string simDesc, string boardPath, bool dbInsert)
        {
            Statistics stats = new Statistics(new Simulation() { SimulationId = Guid.NewGuid(), Description = simDesc, SimulationDate = DateTime.Now, AIType = (int)AIType.Random });

            try
            {
                Random random = new Random();
                for (int i = 0; i < iterations; i++)
                {
                    Game game = new Game();
                    game.GameId = Guid.NewGuid();
                    game.SimulationId = stats.Simulation.SimulationId;
                    game.GameNumber = i + 1;
                    
                    string s = Files.Read(boardPath);
                    Board board = GridParser.Parse(s, size);
                    HuntTargetAI RandAI = new HuntTargetAI(board, game.GameId, random);
                    stats.Shots.AddRange(RandAI.Play());
                    stats.Games.Add(game);
                }

                if(dbInsert)
                    DbInsert.Insert(stats);
                Console.WriteLine("Done");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Пример #4
0
        public static async Task <IGridData <string> > GetGridDataAsync(string expression, GridRange?gridRange, IRSession rSession = null)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            if (rSession == null)
            {
                rSession = VsAppShell.Current.ExportProvider.GetExportedValue <IRSessionProvider>().GetInteractiveWindowRSession();
                if (rSession == null)
                {
                    throw new InvalidOperationException(Invariant($"{nameof(IRSessionProvider)} failed to return RSession for {nameof(EvaluationWrapper)}"));
                }
            }

            string rows    = gridRange?.Rows.ToRString();
            string columns = gridRange?.Columns.ToRString();

            REvaluationResult?result = null;

            using (var evaluator = await rSession.BeginEvaluationAsync()) {
                result = await evaluator.EvaluateAsync($"rtvs:::grid.dput(rtvs:::grid.data({expression}, {rows}, {columns}))", REvaluationKind.Normal);

                if (result.Value.ParseStatus != RParseStatus.OK || result.Value.Error != null)
                {
                    throw new InvalidOperationException($"Grid data evaluation failed{Environment.NewLine} {result}");
                }
            }

            GridData data = null;

            if (result.HasValue)
            {
                data = GridParser.Parse(result.Value.StringResult.ToUnicodeQuotes());
                if (gridRange.HasValue)
                {
                    data.Range = gridRange.Value;
                }

                if ((data.ValidHeaderNames.HasFlag(GridData.HeaderNames.Row) && data.RowNames.Count != data.Range.Rows.Count) ||
                    (data.ValidHeaderNames.HasFlag(GridData.HeaderNames.Column) && data.ColumnNames.Count != data.Range.Columns.Count))
                {
                    throw new InvalidOperationException("Header names lengths are different from data's length");
                }
            }

            return(data);
        }