Beispiel #1
0
    public static int DistanceClosestToCentralPort(DirectionPath wireA, DirectionPath wireB)
    {
        var bounds = GetBounds(wireA, wireB);
        var grid   = new GridValue[bounds.size.x, bounds.size.y];
        var centralPortPosition = new Vector2Int(Mathf.Abs(bounds.min.x), Mathf.Abs(bounds.min.y));

        grid[centralPortPosition.x, centralPortPosition.y] = GridValue.CentralPort;

        grid = FillGrid(grid, wireA, GridValue.A, GridValue.B, centralPortPosition);
        grid = FillGrid(grid, wireB, GridValue.B, GridValue.A, centralPortPosition);

        //var str = "";
        var minDistance = Int32.MaxValue;

        for (int y = grid.GetLength(1) - 1; y >= 0; y--)
        {
            for (int x = 0; x < grid.GetLength(0); x++)
            {
                //str += GridValueToChar(grid[x, y]);
                if (grid[x, y] == GridValue.AB)
                {
                    minDistance = Mathf.Min(minDistance, Mathf.Abs(x - centralPortPosition.x) + Mathf.Abs(y - centralPortPosition.y));
                }
            }
            //str += "\n";
        }

        //Debug.Log(str);

        return(minDistance);
    }
Beispiel #2
0
    public static int DistanceClosestToCentralPortByLength(DirectionPath wireA, DirectionPath wireB)
    {
        var bounds              = GetBounds(wireA, wireB);
        var grid                = new GridValue[bounds.size.x, bounds.size.y];
        var gridDistanceA       = new int[bounds.size.x, bounds.size.y];
        var gridDistanceB       = new int[bounds.size.x, bounds.size.y];
        var centralPortPosition = new Vector2Int(Mathf.Abs(bounds.min.x), Mathf.Abs(bounds.min.y));

        grid[centralPortPosition.x, centralPortPosition.y] = GridValue.CentralPort;

        grid = FillGrid(grid, wireA, GridValue.A, GridValue.B, centralPortPosition, gridDistanceA);
        grid = FillGrid(grid, wireB, GridValue.B, GridValue.A, centralPortPosition, gridDistanceB);

        var minDistance = Int32.MaxValue;

        for (int y = grid.GetLength(1) - 1; y >= 0; y--)
        {
            for (int x = 0; x < grid.GetLength(0); x++)
            {
                if (grid[x, y] == GridValue.AB)
                {
                    minDistance = Mathf.Min(minDistance, gridDistanceA[x, y] + gridDistanceB[x, y]);
                }
            }
        }


        return(minDistance);
    }
Beispiel #3
0
        }                                    //是否是组合图形
        #endregion
        public PlateModel Copy()
        {
            PlateModel pm = new Model.PlateModel();

            pm.plateName      = plateNum;
            pm.plateNum       = plateNum;
            pm.plateCode      = plateCode;
            pm.inheritanceID  = inheritanceID;
            pm.plateCount     = plateCount;
            pm.plateUseCount  = plateUseCount;
            pm.standard       = standard;
            pm.specifications = specifications;
            pm.material       = material;
            pm.text           = text;
            pm.plateClass     = plateClass;
            pm.outModel       = outModel;
            pm.innerModel     = innerModel.ToList();
            pm.area           = area;
            pm.bound          = bound;
            pm.isArc          = isArc;
            pm.rotateCenter   = rotateCenter;
            pm.powCenter      = powCenter;
            pm.hadUsedGene    = hadUsedGene;
            pm.heightPower    = heightPower;
            pm.areaPower      = areaPower;
            pm.widthPower     = widthPower;
            pm.GridValue      = GridValue == null ? null : GridValue.ToList();
            pm.id             = id;
            pm.GridLen        = GridLen;
            pm.GridWid        = GridWid;
            pm.Rect           = Rect;
            pm.Combine        = Combine;
            return(pm);
        }
Beispiel #4
0
 private bool HaveSameValue(GridValue? first, GridValue? second, GridValue? third)
 {
     if (first == null)
     {
         return false;
     }
     return first == second && second == third;
 }
Beispiel #5
0
        public MiniMaxPlayer(string playerName, GridValue playerSide, GameRules rules)
        {
            PlayerName = playerName;
            PlayerSide = playerSide;

            var problem = new TicTacToeAdversarialSearchProblem();
            var stateEvaluator = new TicTacToeStateEvaluator(PlayerSide, rules);
            _search = new AdversarialSearch<TicTacToeState, Move>(problem, stateEvaluator);
        }
 //Code d'initialisation
 public SudokuSolver(int x, int y)
 {
     // only initialize in the constructor, no calls
     SudokuGrid = new GridValue[x, y];     // the array exists now in mem, but each entry is pointing to null
     for (int i = 0; i < x; i++)
     {
         for (int j = 0; j < y; j++)
         {
             SudokuGrid[i, j] = new GridValue();
         }
     }
 }
Beispiel #7
0
 private string GetGridValue(GridValue? value)
 {
     switch (value)
     {
         case GridValue.O:
             return "O";
         case GridValue.X:
             return "X";
         default:
             return " ";
     }
 }
        private GridValue[,] SudokuGridCreator(out GridValue[,] SudokuGrid)
        {
            SudokuGrid = new GridValue[9, 9];
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    SudokuGrid[i, j] = new GridValue();
                }
            }

            return SudokuGrid;
        }
 //Initialisation code
 public SudokuSolver()
 {
     GridValue[,] SudokuGrid = new GridValue[9, 9];
     //###################
     for (int r = 0; r < 9; r++)
     {
         for (int c = 0; c < 9; c++)
         {
             SudokuGrid[r, c] = new GridValue();
         }
     }
     //###################
     SudokuDisplay(SudokuGrid);
     Console.ReadKey();
 }
Beispiel #10
0
 private static GridValue ValueToPutOnGrid(GridValue valueOnGrid, int x, int y, GridValue a, GridValue b)
 {
     if (valueOnGrid == GridValue.Empty)
     {
         return(a);
     }
     else if (valueOnGrid == b)
     {
         return(GridValue.AB);
     }
     else
     {
         return(valueOnGrid);
     }
 }
Beispiel #11
0
    private static char GridValueToChar(GridValue value)
    {
        switch (value)
        {
        case GridValue.A: return('a');

        case GridValue.B: return('b');

        case GridValue.AB: return('X');

        case GridValue.CentralPort: return('O');

        default: return('.');
        }
    }
Beispiel #12
0
    public static Grid Spawn(GridValue gridValue, Node node)
    {
        GameObject model = Resources.Load <GameObject>(gridValue == GridValue.grid_zero ? "Prefabs/Game/Rock" : "Prefabs/Game/Grid");
        GameObject grid  = GameObject.Instantiate <GameObject>(model);

        grid.transform.SetParent(PushBoxGame.Instance.gridContainer.transform);
        grid.transform.localScale = Vector3.one;
        Vector2 pos = GridContainer.NodeToPosition(node);

        grid.transform.localPosition = new Vector3(pos.x, pos.y, 0);
        Grid gridCom = grid.GetComponent <Grid>();

        gridCom.Value = gridValue;
        gridCom.Node  = node;
        //grid.GetComponent<RectTransform>().sizeDelta = new Vector2(GridContainer.GRID_WIDTH,GridContainer.GRID_HEIGHT);
        return(gridCom);
    }
Beispiel #13
0
        private void FillGridValues()
        {
            foreach (var hr in HealthRecords)
            {
                foreach (var hio in Icds.Union <IHrItemObject>(Words))
                {
                    var values = ItemsWith(hio, hr)
                                 .Select(item => ValueOf(item))
                                 .Where(x => x != null)
                                 .ToList();

                    // обычно в записи только один элемент с данным словом
                    // если больше, выводим наиболее важное значение, порядок - числа, наличие слова, отрицание

                    GridValue val;
                    if (values.OfType <Measure>().Any())
                    {
                        Contract.Assume(hio is Word);
                        val = new GridValue(values.OfType <Measure>());
                    }
                    else if (values.Any(x => x.Equals(true)))
                    {
                        val = new GridValue(true);
                    }
                    else if (values.Any(x => x.Equals(false)))
                    {
                        val = new GridValue(false);
                    }
                    else
                    {
                        val = new GridValue();
                    }

                    if (!GridValues.Keys.Contains(hr))
                    {
                        GridValues[hr] = new Dictionary <IHrItemObject, GridValue>();
                    }
                    GridValues[hr][hio] = val;
                }
            }
        }
Beispiel #14
0
    private static GridValue[,] FillGrid(GridValue[,] grid, DirectionPath path, GridValue a, GridValue b, Vector2Int portPosition, int[,] gridDistance = null)
    {
        int x        = portPosition.x;
        int y        = portPosition.y;
        int distance = 0;

        foreach (var wire in path.Nodes)
        {
            var displacement = NodeToDeplacement(wire.Direction, wire.Distance);
            if (IsHorizontal(wire.Direction))
            {
                for (int i = 0; i < wire.Distance; i++)
                {
                    grid[x, y] = ValueToPutOnGrid(grid[x, y], x, y, a, b);
                    if (gridDistance != null && gridDistance[x, y] == 0)
                    {
                        gridDistance[x, y] = distance;
                    }
                    x += displacement;
                    distance++;
                }
            }
            else
            {
                for (int i = 0; i < wire.Distance; i++)
                {
                    grid[x, y] = ValueToPutOnGrid(grid[x, y], x, y, a, b);
                    if (gridDistance != null && gridDistance[x, y] == 0)
                    {
                        gridDistance[x, y] = distance;
                    }
                    y += displacement;
                    distance++;
                }
            }
        }

        return(grid);
    }
Beispiel #15
0
 public Move(GridPosition pos, GridValue value)
 {
     Position = pos;
     Value = value;
 }
Beispiel #16
0
        public void GivenIndexingDocument_WhenGridPropertyData_ThenDataIndexedInSegregatedFields()
        {
            using (GetSynchronousContentIndex(false, out UmbracoContentIndex index, out _, out ContentValueSetBuilder contentValueSetBuilder, null))
            {
                index.CreateIndex();

                ContentType contentType = ContentTypeBuilder.CreateBasicContentType();
                contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext)
                {
                    Alias = "grid",
                    Name  = "Grid",
                    PropertyEditorAlias = Cms.Core.Constants.PropertyEditors.Aliases.Grid
                });
                Content content = ContentBuilder.CreateBasicContent(contentType);
                content.Id   = 555;
                content.Path = "-1,555";
                var gridVal = new GridValue
                {
                    Name     = "n1",
                    Sections = new List <GridValue.GridSection>
                    {
                        new GridValue.GridSection
                        {
                            Grid = "g1",
                            Rows = new List <GridValue.GridRow>
                            {
                                new GridValue.GridRow
                                {
                                    Id    = Guid.NewGuid(),
                                    Name  = "row1",
                                    Areas = new List <GridValue.GridArea>
                                    {
                                        new GridValue.GridArea
                                        {
                                            Grid     = "g2",
                                            Controls = new List <GridValue.GridControl>
                                            {
                                                new GridValue.GridControl
                                                {
                                                    Editor = new GridValue.GridEditor
                                                    {
                                                        Alias = "editor1",
                                                        View  = "view1"
                                                    },
                                                    Value = "value1"
                                                },
                                                new GridValue.GridControl
                                                {
                                                    Editor = new GridValue.GridEditor
                                                    {
                                                        Alias = "editor1",
                                                        View  = "view1"
                                                    },
                                                    Value = "value2"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var json = JsonConvert.SerializeObject(gridVal);
                content.Properties["grid"].SetValue(json);

                IEnumerable <ValueSet> valueSet = contentValueSetBuilder.GetValueSets(content);
                index.IndexItems(valueSet);

                ISearchResults results = index.Searcher.CreateQuery().Id(555).Execute();
                Assert.AreEqual(1, results.TotalItemCount);

                ISearchResult result = results.First();
                Assert.IsTrue(result.Values.ContainsKey("grid.row1"));
                Assert.AreEqual("value1", result.AllValues["grid.row1"][0]);
                Assert.AreEqual("value2", result.AllValues["grid.row1"][1]);
                Assert.IsTrue(result.Values.ContainsKey("grid"));
                Assert.AreEqual("value1 value2 ", result["grid"]);
                Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineFieldNames.RawFieldPrefix}grid"));
                Assert.AreEqual(json, result[$"{UmbracoExamineFieldNames.RawFieldPrefix}grid"]);
            }
        }
Beispiel #17
0
        //Code d'initialisation
        public SudokuSolver()
        {
            Console.Title = "Sudoku Solver";
            Console.Clear();
            SudokuGridCreator(out GridValue[,] SudokuGrid);
            bool repeatQuerry = true;
            bool solved       = false;
            int  iteration    = 0;

            //Demander la valeur des cases déjà assignées
            do
            {
                (SudokuGrid, repeatQuerry) = SudokuQuerry(SudokuGrid, repeatQuerry);
            }while (repeatQuerry == true);
            SudokuDisplay(SudokuGrid);
            //Résolution du sudoku
            GridValue[,] tempSudokuGrid = new GridValue[9, 9];
            do
            {
                for (int i = 0; i < 9; i++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        //Vérifier si la case a déjà une valeur. Si oui, on skip la valeur pour optimiser le calcul
                        if (SudokuGrid[i, j].AlreadySolved == false)
                        {
                            //Vérifier si la case peut avoir tel ou tel nombre et si non, utiliser un .Remove()
                            SudokuGrid = RowDetection(SudokuGrid, i, j);
                            SudokuGrid = ColumnDetection(SudokuGrid, i, j);
                            SudokuGrid = HouseDetection(SudokuGrid, i, j);
                            SudokuGrid = ObviousSolving(SudokuGrid, i, j);
                            if (SudokuGrid[i, j].AlreadySolved == true)
                            {
                                Console.Clear();
                                SudokuDisplay(SudokuGrid);
                            }
                        }
                    }
                }
                bool breakThrough = false;
                for (int i = 0; i < 9; i++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        if (SudokuGrid[i, j].AlreadySolved == false)
                        {
                            SudokuGrid = RowSolving(SudokuGrid, i, j);
                        }
                        if (SudokuGrid[i, j].AlreadySolved == false)
                        {
                            SudokuGrid = ColumnSolving(SudokuGrid, i, j);
                        }
                        if (SudokuGrid[i, j].AlreadySolved == false)
                        {
                            SudokuGrid = HouseSolving(SudokuGrid, i, j);
                        }
                        if (SudokuGrid[i, j].AlreadySolved == true)
                        {
                            breakThrough = true;
                        }
                        if (breakThrough == true)
                        {
                            break;
                        }
                    }
                    if (breakThrough == true)
                    {
                        break;
                    }
                }
                bool tempSolved = true;
                for (int tempI = 0; tempI < 9; tempI++)
                {
                    for (int tempJ = 0; tempJ < 9; tempJ++)
                    {
                        if (SudokuGrid[tempI, tempJ].AlreadySolved == false)
                        {
                            tempSolved = false;
                            break;
                        }
                    }
                    if (tempSolved == false)
                    {
                        break;
                    }
                }
                solved = tempSolved;
                if (tempSudokuGrid == SudokuGrid)
                {
                    AlmostRandomSolving(SudokuGrid);
                }
                else
                {
                    tempSudokuGrid = SudokuGrid;
                }

                if (iteration > 1000)
                {
                    Console.ReadKey();
                    Environment.Exit(0);
                }
                iteration++;
            }while (solved == false);
            //Choisir le nombre le plus approprié pour chaque case si possible (Si une seule valeur est possible, ou si c'est la seule case pouvant contenir une telle valeur dans la rangée / colonne / carré (3x3)
            //Recommencer

            //Terminer le programme après l'appui de l'usager
            Console.ReadKey();
        } //Version 1.0.0
Beispiel #18
0
 public ConsoleHumanPlayer(string playerName, GridValue playerSide)
 {
     PlayerName = playerName;
     PlayerSide = playerSide;
 }
Beispiel #19
0
 private GameGrid(GridValue?[,] grid)
 {
     _grid = grid;
 }
        public void Index_Property_Data_With_Value_Indexer()
        {
            var contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(Factory.GetInstance <PropertyEditorCollection>(), false);

            using (var luceneDir = new RandomIdRamDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
                                                                        validator: new ContentValueSetValidator(false)))
                    using (indexer.ProcessNonAsync())
                    {
                        indexer.CreateIndex();

                        var contentType = MockedContentTypes.CreateBasicContentType();
                        contentType.AddPropertyType(new PropertyType("test", ValueStorageType.Ntext)
                        {
                            Alias = "grid",
                            Name  = "Grid",
                            PropertyEditorAlias = Core.Constants.PropertyEditors.Aliases.Grid
                        });
                        var content = MockedContent.CreateBasicContent(contentType);
                        content.Id   = 555;
                        content.Path = "-1,555";
                        var gridVal = new GridValue
                        {
                            Name     = "n1",
                            Sections = new List <GridValue.GridSection>
                            {
                                new GridValue.GridSection
                                {
                                    Grid = "g1",
                                    Rows = new List <GridValue.GridRow>
                                    {
                                        new GridValue.GridRow
                                        {
                                            Id    = Guid.NewGuid(),
                                            Name  = "row1",
                                            Areas = new List <GridValue.GridArea>
                                            {
                                                new GridValue.GridArea
                                                {
                                                    Grid     = "g2",
                                                    Controls = new List <GridValue.GridControl>
                                                    {
                                                        new GridValue.GridControl
                                                        {
                                                            Editor = new GridValue.GridEditor
                                                            {
                                                                Alias = "editor1",
                                                                View  = "view1"
                                                            },
                                                            Value = "value1"
                                                        },
                                                        new GridValue.GridControl
                                                        {
                                                            Editor = new GridValue.GridEditor
                                                            {
                                                                Alias = "editor1",
                                                                View  = "view1"
                                                            },
                                                            Value = "value2"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        };

                        var json = JsonConvert.SerializeObject(gridVal);
                        content.Properties["grid"].SetValue(json);

                        var valueSet = contentValueSetBuilder.GetValueSets(content);
                        indexer.IndexItems(valueSet);

                        var searcher = indexer.GetSearcher();

                        var results = searcher.CreateQuery().Id(555).Execute();
                        Assert.AreEqual(1, results.TotalItemCount);

                        var result = results.First();
                        Assert.IsTrue(result.Values.ContainsKey("grid.row1"));
                        Assert.AreEqual("value1", result.AllValues["grid.row1"][0]);
                        Assert.AreEqual("value2", result.AllValues["grid.row1"][1]);
                        Assert.IsTrue(result.Values.ContainsKey("grid"));
                        Assert.AreEqual("value1 value2 ", result["grid"]);
                        Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineIndex.RawFieldPrefix}grid"));
                        Assert.AreEqual(json, result[$"{UmbracoExamineIndex.RawFieldPrefix}grid"]);
                    }
        }
Beispiel #21
0
 private void PrintRow(string rowLabel, GridValue? rowValue1, GridValue? rowValue2, GridValue? rowValue3)
 {
     Console.WriteLine("{0}  {1} | {2} | {3}", rowLabel, GetGridValue(rowValue1), GetGridValue(rowValue2), GetGridValue(rowValue3));
 }