Example #1
0
 public Cell(T data, Honeycomb <T> honeycomb, int column, int row)
 {
     Data      = data;
     Honeycomb = honeycomb;
     Column    = column;
     Row       = row;
 }
Example #2
0
        public Cell <long> Walk()
        {
            Cell <long> startPoint = Honeycomb[0, 0];
            Cell <long> position   = startPoint;
            Dictionary <string, long> endPoints = Step(position, Steps);

            foreach (string cellKey in endPoints.Keys)
            {
                Honeycomb[cellKey].Data = endPoints[cellKey];
            }

            long        maxEndings = long.MinValue;
            Cell <long> mostLikely = null;

            Honeycomb.ForEachCell((Cell <long> cell) =>
            {
                if (cell.Data > maxEndings)
                {
                    maxEndings = cell.Data;
                    mostLikely = cell;
                }
            });

            return(mostLikely);
        }
Example #3
0
        public Walker(Honeycomb <long> honeycomb, int steps)
        {
            Honeycomb = honeycomb;
            Steps     = steps;

            InitNStepsFrom();
        }
Example #4
0
        private Dictionary <string, long> CreateOccurrenceDictionary()
        {
            var newOD = new Dictionary <string, long>();

            Honeycomb.ForEachCell((Cell <long> cell) => newOD[cell.Key] = 0);
            return(newOD);
        }
        public static Cell <T> Create(T data)
        {
            var newHoneycomb = new Honeycomb <T>();
            var newCell      = new Cell <T>(data, newHoneycomb, 0, 0);

            newHoneycomb.AddCell(newCell);

            return(newCell);
        }
Example #6
0
 private void InitNStepsFrom()
 {
     nStepsFrom = new Dictionary <string, List <Dictionary <string, long> > >();
     // for each cell create a list for each number of steps
     Honeycomb.ForEachCell((Cell <long> cell) => nStepsFrom[cell.Key] = CreateDestinationsByStep());
 }
        private static Honeycomb <long> CreateHex19()
        {
            Cell <long> seed = Honeycomb <long> .Create(0);

            Honeycomb <long> bhc = seed.Honeycomb;
            Cell <long>      cell;

            // 15 columns - col[0] -> col[14]
            // seed is top of col11 - tops[11]

            var tops    = new Cell <long> [15];
            var bottoms = new Cell <long> [15];

            // create tops 1->13 starting from seed - tops[11]
            // tops 12->13 - going east from seed
            tops[11] = seed;
            // top of col 12 is SE of top of col 11
            tops[12] = bhc.AddSouthEast(tops[11], 0);
            // top of col 13 is NE of top of col 12
            tops[13] = bhc.AddNorthEast(tops[12], 0);

            // fill columns 11->13 - going south each time
            // col 11 - 8 cells, need to create 7 more
            cell        = bhc.AddSouth(tops[11], 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            bottoms[11] = cell;
            // col 12 - 5 cells, need to create 4 more
            cell        = bhc.AddSouth(tops[12], 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            bottoms[12] = cell;
            // col 13 - 5 cells, need to create 4 more
            cell        = bhc.AddSouth(tops[13], 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            bottoms[13] = cell;

            // col 14 is one cell to the NE of the bottom of col 13
            tops[14]    = bhc.AddNorthEast(bottoms[13], 0);
            bottoms[14] = tops[14];

            // tops 10->1 going west from seed - tops[11]

            // top of col 10 is S then SW of top of col 11
            tops[10] = bhc.AddSouthWest(tops[11].South, 0);
            // col 10 - 10 cells, need to add 9 more
            cell        = bhc.AddSouth(tops[10], 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            cell        = bhc.AddSouth(cell, 0);
            bottoms[10] = cell;

            // top of col 9 is S then SW of top of col 10
            tops[9] = bhc.AddSouthWest(tops[10].South, 0);
            // col 9 - 9 cells, need to add 8 more
            cell       = bhc.AddSouth(tops[9], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[9] = cell;

            // top of col 8 is SW of top of col 9
            tops[8] = bhc.AddSouthWest(tops[9], 0);
            // col 8 - 8 cells, need to add 7 more
            cell       = bhc.AddSouth(tops[8], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[8] = cell;

            // top of col 7 is SW of top of col 8
            tops[7] = bhc.AddSouthWest(tops[8], 0);
            // col 7 - 4 cells, need to add 3 more
            cell       = bhc.AddSouth(tops[7], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[7] = cell;

            // top of col 6 is SW of top of col 7
            tops[6] = bhc.AddSouthWest(tops[7], 0);
            // col 6 - 3 cells, need to add 2 more
            cell       = bhc.AddSouth(tops[6], 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[6] = cell;

            // top of col 5 is NW of top of col 6
            tops[5] = bhc.AddNorthWest(tops[6], 0);
            // col 5 - 3 cells, need to add 2 more
            cell       = bhc.AddSouth(tops[5], 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[5] = cell;

            // top of col 4 is NW of top of col 5
            tops[4] = bhc.AddNorthWest(tops[5], 0);
            // col 4 - 4 cells, need to add 3 more
            cell       = bhc.AddSouth(tops[4], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[4] = cell;

            // top of col 3 is NW of top of col 4
            tops[3] = bhc.AddNorthWest(tops[4], 0);
            // col 3 - 4 cells, need to add 3 more
            cell       = bhc.AddSouth(tops[3], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[3] = cell;

            // top of col 2 is NW of top of col 3
            tops[2] = bhc.AddNorthWest(tops[3], 0);
            // col 2 - 4 cells, need to add 3 more
            cell       = bhc.AddSouth(tops[2], 0);
            cell       = bhc.AddSouth(cell, 0);
            cell       = bhc.AddSouth(cell, 0);
            bottoms[2] = cell;

            // top of col 1 is NW of top of col 2
            tops[1] = bhc.AddNorthWest(tops[2], 0);
            // col 1 - 4 cells, need to add 3 more and mind the gap in the middle
            cell = bhc.AddSouth(tops[1], 0);
            // gap!
            // bottom of col 1 is SW of bottom of col 2
            bottoms[1] = bhc.AddSouthWest(bottoms[2], 0);
            cell       = bhc.AddNorth(bottoms[1], 0);

            // col 0 is one cell SW of bottom of col 1
            tops[0]    = bhc.AddSouthWest(bottoms[1], 0);
            bottoms[0] = tops[0];

            return(bhc);
        }