Пример #1
0
        public void Part1MoveExample1()
        {
            const string map =
                @"#######
#.E...#
#.....#
#...G.#
#######";

            var gridPair = GridPair.For(GridOperations.ParseGrid(map));

            GridOperations.CalculateCloseness(gridPair);
            GridCell[,] grid = gridPair.Primary;

            var p = GridOperations.CalculateMove(grid, 2, 1);

            Assert.AreEqual((1, 0), p);
        }
Пример #2
0
        public void NearestIsSelectedInReadingOrder()
        {
            // In the map below, we focus our attention on the square directly
            // belong the only Elf. This is adjacent to two cells in range of
            // two different Goblins. So the distance to each Goblin is 2, meaning
            // there is a tie in the 'nearest' ranking. The rules state that such
            // ties must be broken by using reading order. The Goblin on the 2nd
            // line comes before the one on the 3rd line, so we must check that
            // this is the reported one. (Without taking special steps, it won't
            // be. We populate the closeness map by growing out one step at a time
            // from each Goblin (and from each Elf), meaning that after 1 pass,
            // the 3rd line will look like this:
            //   #.1.1G#
            // with that first 1 denoting a distance of 1 to the Goblin directly
            // beneath it (Goblin 1) and the second denoting a distance of 1 to
            // the Goblin to the right (Goblin 0). Since each pass works through
            // the grid in reading order, we'll see that first 1 before we see
            // the second,
            const string map =
                @"#######
#..E..#
#....G#
#.G...#
#.....#
#######";
            var gridPair = GridPair.For(GridOperations.ParseGrid(map));

            GridOperations.CalculateCloseness(gridPair);
            GridCell[,] grid = gridPair.Primary;

            Assert.AreEqual(0, grid[2, 5].GoblinId, "Test setup error");

            GridCell testCell = grid[1, 3];

            Assert.AreEqual(3, testCell.DistanceToGoblinInRange);
            Assert.AreEqual(0, testCell.GoblinId);
            Assert.AreEqual((5, 1), testCell.GoblinInRangePosition);
        }
        private void BuildGridFromBibTeX_AddGridPair(int row, string key, string value, bool isEditableKey, bool isBoldKey)
        {
            // Check that we have enough rowdefinitions
            while (ObjBibTeXGrid.RowDefinitions.Count < row)
            {
                RowDefinition rd = new RowDefinition();
                rd.Height = GridLength.Auto;
                ObjBibTeXGrid.RowDefinitions.Add(rd);
            }

            GridPair gp = new GridPair();

            // The KEY column
            {
                if (!isEditableKey)
                {
                    TextBlock tb_key = new TextBlock();
                    tb_key.VerticalAlignment = VerticalAlignment.Center;
                    if (isBoldKey)
                    {
                        tb_key.FontWeight = FontWeights.Bold;
                        tb_key.ToolTip    = key + " - this is a recommended field for the article type you have selected.";
                    }
                    else
                    {
                        tb_key.ToolTip = key + " - this is an optional field for the article type you have selected.";
                    }
                    tb_key.Text = key;
                    Grid.SetColumn(tb_key, 0);
                    Grid.SetRow(tb_key, row);
                    ObjBibTeXGrid.Children.Add(tb_key);
                    gp.key     = tb_key;
                    tb_key.Tag = gp;
                }
                else
                {
                    AutoCompleteBox tb_key = new AutoCompleteBox();
                    tb_key.Background        = ThemeColours.Background_Brush_Blue_VeryDark;
                    tb_key.Background        = Brushes.Transparent;
                    tb_key.ToolTip           = "You can add any number of your own BibTeX fields here.  Just click and enter the field name and value.\nYou can use these to powerfully restrict your searches, or use them in your bibliographies if you have a CSL style that understands these specific fields.";
                    tb_key.ItemsSource       = EntryTypes.Instance.FieldTypeList;
                    tb_key.Margin            = new Thickness(1);
                    tb_key.VerticalAlignment = VerticalAlignment.Center;
                    if (isBoldKey)
                    {
                        tb_key.FontWeight = FontWeights.Bold;
                    }
                    tb_key.Text = key;
                    Grid.SetColumn(tb_key, 0);
                    Grid.SetRow(tb_key, row);
                    ObjBibTeXGrid.Children.Add(tb_key);
                    gp.key              = tb_key;
                    tb_key.Tag          = gp;
                    tb_key.TextChanged += tb_key_TextChanged;
                    first_text_change_suppression_set.Add(tb_key);
                }
            }

            // The VALUE column
            {
                TextBox tb_value = new TextBox();
                tb_value.Text = value;
                tb_value.VerticalContentAlignment = VerticalAlignment.Center;
                tb_value.TextWrapping             = TextWrapping.Wrap;
                Grid.SetColumn(tb_value, 2);
                Grid.SetRow(tb_value, row);
                ObjBibTeXGrid.Children.Add(tb_value);
                gp.value = tb_value;
                tb_value.BorderThickness = new Thickness(0, 1, 0, 0);
                tb_value.Tag             = gp;
                tb_value.KeyDown        += tb_value_KeyDown;
                tb_value.TextChanged    += OnGridTextChanged;

                tb_value.ToolTip = "Enter the value associated with the field name to the left.\nHint: pressing CTRL and ; simultaneously will insert today's date.  That should help you populate those 'Accessed' fields...";
            }
        }
        private void UpdateFromGrid(bool do_reparse)
        {
            if (rebuilding_grid)
            {
                return;
            }

            BibTexItem bibtex_item = new BibTexItem();

            bibtex_item.Type = (string)ComboRecordType.Text;
            bibtex_item.Key  = TxtRecordKey.Text;

            foreach (object child_obj in ObjBibTeXGrid.Children)
            {
                FrameworkElement child = child_obj as FrameworkElement;
                if (null != child)
                {
                    GridPair gp = child.Tag as GridPair;
                    if (null != gp)
                    {
                        if (gp.key == child)
                        {
                            string key = null;
                            { TextBlock tb = gp.key as TextBlock; if (null != tb)
                              {
                                  key = tb.Text;
                              }
                            }
                            { AutoCompleteBox tb = gp.key as AutoCompleteBox; if (null != tb)
                              {
                                  key = tb.Text;
                              }
                            }
                            string value = null;
                            { TextBox tb = gp.value as TextBox; if (null != tb)
                              {
                                  value = tb.Text;
                              }
                            }

                            if (!String.IsNullOrEmpty(key) && !String.IsNullOrEmpty(value))
                            {
                                bibtex_item[key] = value;
                            }
                        }
                    }
                }
            }



            // Check that the BibTeX is not completely empty
            string bibtex = bibtex_item.ToBibTex();

            if ("@{\n}" == bibtex)
            {
                bibtex = "";
            }

            // Update the bibtex field
            updating_from_grid = true && !do_reparse;
            BibTeX             = bibtex;
            updating_from_grid = false;
        }