Example #1
0
 private static void copyBorders()
 {
     // For all cells associated with a symmetry point, copy their association and borders.
     foreach (var cell in cells)
     {
         if (cell.centerPoint != invalid)
         {
             for (int k = 0; k < 4; k++)
             {
                 if (cell.IsBorder((directions)k))
                 {
                     Point      opposite = Symmetry(cell.myPoint, cell.centerPoint);
                     pwCell     newCell  = cells[(int)opposite.x, (int)opposite.y];
                     directions oppside  = (directions)((k + 2) % 4);
                     if (!newCell.IsBorder(oppside))
                     {
                         Console.WriteLine($"Copying border from {cell.myPoint} to {opposite}.");
                         newCell.SetBorder(oppside);
                     }
                 }
             }
         }
     }
 }
Example #2
0
        static void Create(int x, int y, char cell)
        {
            pwCell c = cells[x, y] = new pwCell();

            c.myPoint = new Point {
                x = x, y = y
            };
            if (x == 0)
            {
                c.SetBorder(directions.left);
            }
            if (y == 0)
            {
                c.SetBorder(directions.up);
            }
            if (x == width - 1)
            {
                c.SetBorder(directions.right);
            }
            if (y == height - 1)
            {
                c.SetBorder(directions.down);
            }
            switch (cell)
            {
            case 'w':
                c.associates  = directions.none;    // Associates with itself.
                c.centerPoint = c.myPoint;
                c.filled      = false;
                break;

            case 'b':
                c.associates  = directions.none;    // Associates with itself.
                c.centerPoint = c.myPoint;
                c.filled      = true;
                break;

            case ')':
                c.associates  = directions.left;
                c.centerPoint = new Point {
                    x = x - .5f, y = y
                };
                c.filled = cells[x - 1, y].filled;

                cells[x - 1, y].associates  = directions.right;
                cells[x - 1, y].centerPoint = c.centerPoint;
                break;

            case 'v':
            case 'V':
                c.associates  = directions.up;
                c.centerPoint = new Point {
                    x = x, y = y - .5f
                };
                c.filled = cells[x, y - 1].filled;

                cells[x, y - 1].associates  = directions.down;
                cells[x, y - 1].centerPoint = c.centerPoint;
                break;

            case '\\':     // bottom left of a four.
                c.associates  = directions.up;
                c.centerPoint = new Point {
                    x = x + .5f, y = y - .5f
                };
                c.filled = cells[x, y - 1].filled;

                cells[x, y - 1].associates  = directions.right;
                cells[x, y - 1].centerPoint = c.centerPoint;
                break;

            case '/':      // bottom right of a four.
                           // bottom right
                c.associates  = directions.left;
                c.centerPoint = new Point {
                    x = x - .5f, y = y - .5f
                };
                c.filled = cells[x, y - 1].filled;

                cells[x, y - 1].associates  = directions.down;
                cells[x, y - 1].centerPoint = c.centerPoint;
                break;
            }
        }
Example #3
0
 public static void Initialize(int[,] dotArray)
 {
     width  = (dotArray.GetUpperBound(0) + 1) / 2;
     height = (dotArray.GetUpperBound(1) + 1) / 2;
     cells  = new pwCell[width, height];
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             pwCell c = cells[x, y] = new pwCell();
             c.myPoint = new Point {
                 x = x, y = y
             };
             if (x == 0)
             {
                 c.SetBorder(directions.left);
             }
             if (y == 0)
             {
                 c.SetBorder(directions.up);
             }
             if (x == width - 1)
             {
                 c.SetBorder(directions.right);
             }
             if (y == height - 1)
             {
                 c.SetBorder(directions.down);
             }
         }
     }
     for (int i = 0; i <= dotArray.GetUpperBound(0); i++)
     {
         for (int j = 0; j <= dotArray.GetUpperBound(1); j++)
         {
             Point centerPoint = new Point()
             {
                 x = (float)i / 2.0f, y = (float)j / 2.0f
             };
             pwCell c;
             int    il, ih, jl, jh;
             if (i % 2 == 0)
             {
                 ih = il = i / 2;
             }
             else
             {
                 ih = 1 + (il = (i - 1) / 2);
             }
             if (j % 2 == 0)
             {
                 jh = jl = j / 2;
             }
             else
             {
                 jh = j + (jl = (j - 1) / 2);
             }
             for (int ii = il; ii <= ih; ii++)
             {
                 for (int ij = jl; ij <= jh; ij++)
                 {
                     c             = cells[ii, ij];
                     c.centerPoint = centerPoint;
                     c.filled      = (dotArray[i, j] == 2);
                     c.associates  = directions.none; // Associates with itself.
                     if (ii == il && ij == jl && il != ih)
                     {
                         c.associates = directions.right;
                     }
                     if (ii == ih && ij == jh && il != ih)
                     {
                         c.associates = directions.left;
                     }
                     if (ij == jl && ii == ih && jl != jh)
                     {
                         c.associates = directions.down;
                     }
                     if (ij == jh && ii == il && jl != jh)
                     {
                         c.associates = directions.up;
                     }
                 }
             }
         }
     }
 }