Пример #1
0
        public void HandleEvent(IFallable sender, FallEventArgs e)
        {
            if (sender == null || e == null)
            {
                return;
            }

            if (sender is Mino)
            {
                Mino mino = sender as Mino;
                Counter += mino.Game.TargetElapsedTime;
                if (Counter >= FallTimeSpan)
                {
                    mino.Position += new Vector2(0, FallVelocity);
                    Counter       -= FallTimeSpan;
                }
            }

            if (sender is Polyomino)
            {
                Polyomino polyomino = sender as Polyomino;
                Counter += polyomino.Game.TargetElapsedTime;
                if (Counter >= FallTimeSpan)
                {
                    foreach (Mino mino in polyomino.Minoes)
                    {
                        mino.Position += new Vector2(0, FallVelocity);
                    }
                    Counter -= FallTimeSpan;
                }
            }
        }
Пример #2
0
    private static void polyomino_lp_write_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_LP_WRITE_TEST tests POLYOMINO_LP_WRITE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    17 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const string filename = "reid.lp";
        const string label    = "\\ LP file for the Reid example, created by POLYOMINO_LP_WRITE.";
        int          m        = 0;
        int          n        = 0;

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_LP_WRITE_TEST:");

        Console.WriteLine("  POLYOMINO_LP_WRITE writes an LP file associated");
        Console.WriteLine("  with a binary programming problem for tiling a region");
        Console.WriteLine("  with copies of a single polyomino.");
        //
        //  Get the coefficients and right hand side for the Reid system.
        //
        polyomino_monohedral_example_reid_size(ref m, ref n);

        int[] a = new int[m * n];
        int[] b = new int[m];

        polyomino_monohedral_example_reid_system(m, n, a, b);
        //
        //  Create the LP file.
        //
        Polyomino.polyomino_lp_write(filename, label, m, n, a, b);

        Console.WriteLine("");
        Console.WriteLine("  Created the LP file '" + filename + "'");

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_LP_WRITE_TEST:");
        Console.WriteLine("  Normal end of execution.");
    }
Пример #3
0
    private static void polyomino_embed_number_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_EMBED_NUMBER_TEST tests POLYOMINO_EMBED_NUMBER.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int mp = 3;
        const int mr = 4;
        const int np = 2;
        const int nr = 4;

        int[] p =
        {
            0, 0, 1,
            1, 1, 1
        };
        int[] r =
        {
            0, 1, 1, 1,
            1, 1, 1, 0,
            1, 0, 1, 1,
            1, 1, 1, 1
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_EMBED_NUMBER_TEST:");
        Console.WriteLine("  POLYOMINO_EMBED_NUMBER reports the number of ways a");
        Console.WriteLine("  fixed polyomino can be embedded in a region.");

        Polyomino.polyomino_print(mr, nr, r, "  The given region R:");

        Polyomino.polyomino_print(mp, np, p, "  The given polyomino P:");

        int number = Polyomino.polyomino_embed_number(mr, nr, r, mp, np, p);

        Console.WriteLine("");
        Console.WriteLine("  As a fixed polyomino, P can be embedded in R in " + number + " ways");
    }
Пример #4
0
        public void HandleEvent(IRotatable sender, RotateEventArgs e)
        {
            if (sender == null || e == null)
            {
                return;
            }

            if (e.Direction != LastDirection)
            {
                DirectionChanged = true;
                LastDirection    = e.Direction;
            }
            else
            {
                DirectionChanged = false;
            }

            if (e.Direction == RotatingDirections.None)
            {
                return;
            }

            if (sender is Polyomino)
            {
                Polyomino polyomino = sender as Polyomino;

                if (DirectionChanged)
                {
                    foreach (Mino mino in polyomino.Minoes)
                    {
                        Vector2 vector = mino.Position - polyomino.OriginMino.Position;
                        float   r      = 0;
                        switch (e.Direction)
                        {
                        case RotatingDirections.Clockwise:
                            r = +MathHelper.PiOver2;
                            break;

                        case RotatingDirections.Counterclockwise:
                            r = -MathHelper.PiOver2;
                            break;

                        default:
                            break;
                        }
                        var x = MathHelper.Clamp(Convert.ToSingle(vector.X * Math.Cos(r) - vector.Y * Math.Sin(r)), float.MinValue, float.MaxValue);
                        var y = MathHelper.Clamp(Convert.ToSingle(vector.X * Math.Sin(r) + vector.Y * Math.Cos(r)), float.MinValue, float.MaxValue);
                        mino.Position = polyomino.OriginMino.Position + new Vector2(x, y);
                    }
                }
            }
        }
Пример #5
0
    public static Block generate(int depth, Polyomino frame = null)
    {
        frame = frame ?? candidates.Sample().Single();
        var offset = new Point2(Random.Range(0, TileContainer.Instance.size - frame.constraints.x),
                                Random.Range(0, TileContainer.Instance.size - frame.constraints.y));

        List <Tile> tiles = new List <Tile> ();

        foreach (var point in frame.points)
        {
            tiles.Add(TileContainer.Instance.getTile(point + offset, depth));
        }
        return(new Block(tiles, frame));
    }
Пример #6
0
    private static void polyomino_enumerate_free_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_ENUMERATE_FREE_TEST tests POLYOMINO_ENUMERATE_FREE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    13 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int  n_data = 0;
        long number = 0;
        int  order  = 0;

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_ENUMERATE_FREE_TEST:");
        Console.WriteLine("  POLYOMINO_ENUMERATE_FREE returns the number of free");
        Console.WriteLine("  polyominoes of a given order;");

        n_data = 0;
        Console.WriteLine("");
        Console.WriteLine("   Order      Number");
        Console.WriteLine("");

        for (;;)
        {
            Polyomino.polyomino_enumerate_free(ref n_data, ref order, ref number);

            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  " + order.ToString().PadLeft(4)
                              + "  " + number.ToString().PadLeft(24) + "");
        }
    }
Пример #7
0
        public void HandleEvent(IShiftable sender, ShiftEventArgs e)
        {
            if (sender == null || e == null)
            {
                return;
            }

            if (e.Direction != LastDirection)
            {
                Counter          = TimeSpan.Zero;
                LastDirection    = e.Direction;
                DirectionChanged = true;
            }
            else
            {
                DirectionChanged = false;
            }

            if (sender is Mino)
            {
                Mino mino = sender as Mino;

                Counter += mino.Game.TargetElapsedTime;
                bool isHolding = !(Counter < HoldThreshold);

                if (DirectionChanged || !DirectionChanged && isHolding)
                {
                    mino.Position = Adjust(mino.Position, e.Direction);
                }
            }

            if (sender is Polyomino)
            {
                Polyomino polyomino = sender as Polyomino;

                Counter += polyomino.Game.TargetElapsedTime;
                bool isHolding = !(Counter < HoldThreshold);

                if (DirectionChanged || !DirectionChanged && isHolding)
                {
                    foreach (Mino mino in polyomino.Minoes)
                    {
                        mino.Position = Adjust(mino.Position, e.Direction);
                    }
                }
            }
        }
Пример #8
0
    private static void polyomino_condense_demo(int mp, int np, int[] p)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    polyomino_condense_demo demonstrates POLYOMINO_CONDENSE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    29 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int MP, NP, the number of rows and columns in the representation
    //    of the polyomino P.
    //
    //    Input, int P[MP*NP], a matrix representing the polyomino.
    //
    //    Local, int MQ, NQ, the number of rows and columns in the representation
    //    of the condensed polyomino Q.
    //
    //    Local, int Q[MQ*NQ], a matrix representing the condensed polyomino.
    //
    {
        int mq = 0;
        int nq = 0;

        int[] q = null;

        string label = "  The initial (" + mp + "," + np + ") polynomino P:";

        Polyomino.polyomino_print(mp, np, p, label);

        Polyomino.polyomino_condense(mp, np, p, ref mq, ref nq, ref q);

        label = "  The condensed (" + mq + "," + nq + ") polynomino Q:";
        Polyomino.polyomino_print(mq, nq, q, label);
    }
Пример #9
0
    public static void polyomino_chiral_count_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_CHIRAL_COUNT_VALUES_TEST tests POLYOMINO_CHIRAL_COUNT_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        long number = 0;
        int  order  = 0;

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_CHIRAL_COUNT_VALUES_TEST:");
        Console.WriteLine("  POLYOMINO_CHIRAL_COUNT_VALUES returns the number of chiral");
        Console.WriteLine("  polyominoes of a given order;");
        int n_data = 0;

        Console.WriteLine("");
        Console.WriteLine("   Order      Number");
        Console.WriteLine("");
        for (;;)
        {
            Polyomino.polyomino_chiral_count_values(ref n_data, ref order, ref number);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  " + order.ToString().PadLeft(4) + order
                              + "  " + number.ToString().PadLeft(24) + number + "");
        }
    }
Пример #10
0
 public Block(IEnumerable <Tile> tiles, Polyomino polymino)
 {
     this.tiles    = tiles.ToList();
     this.polymino = polymino;
 }
Пример #11
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            /*
             * SimpleTetris.Core.Shape.Polyomino.Tetromino.TetrominoBuilder builder = new Core.Shape.Polyomino.Tetromino.TetrominoBuilder();
             * SimpleTetris.Core.Shape.Polyomino.Tetromino.BuildDirectors.MinoSimpleDirector director = new Core.Shape.Polyomino.Tetromino.BuildDirectors.MinoSimpleDirector(builder);
             *
             * director.Texture = SimpleTetris.Core.Graphics.Helpers.CreateTexture(graphics.GraphicsDevice, System.Convert.ToInt32(SimpleTetris.Core.Settings.GraphicalSettings.UnitWidth), System.Convert.ToInt32(SimpleTetris.Core.Settings.GraphicalSettings.UnitHeight), x => Color.Blue);
             * director.Direct(Core.Shape.Polyomino.Tetromino.Tetrominoes.S);
             *
             * testingMino = builder.Build();
             *
             * textureTile = Content.Load<Texture2D>("tile");
             */

            /*
             * this.Components.Add(new Core2.Piece.Mino(this, new System.Func<Texture2D>(() => {
             *  int w = 32;
             *  int h = 32;
             *  int sz = w * h;
             *
             *  Texture2D texture = new Texture2D(GraphicsDevice, w, h);
             *
             *  Color[] colors = new Color[sz];
             *
             *  for (int i = 0; i < sz; ++i) colors[i] = Color.ForestGreen;
             *
             *  texture.SetData(colors);
             *
             *  return texture;
             * })()));
             */

            /*
             * int unitWidth = 32;
             * int unitHeight = 32;
             *
             * Texture2D texture = new System.Func<Texture2D>(() => {
             *  int w = 32;
             *  int h = 32;
             *  int sz = w * h;
             *
             *  Texture2D tex = new Texture2D(GraphicsDevice, w, h);
             *
             *  Color[] colors = new Color[sz];
             *
             *  for (int i = 0; i < sz; ++i) colors[i] = Color.ForestGreen;
             *
             *  tex.SetData(colors);
             *
             *  return tex;
             * })();
             *
             * Polyomino piece = new Polyomino(this);
             *
             * piece.Minoes.AddRange(new [] {
             *  new Mino(this, texture) {
             *      Position = new Vector2(1 * unitWidth, 0 * unitHeight)
             *  },
             *  new Mino(this, texture) {
             *      Position = new Vector2(0 * unitWidth, 1 * unitHeight)
             *  },
             *  new Mino(this, texture) {
             *      Position = new Vector2(1 * unitWidth, 1 * unitHeight)
             *  },
             *  new Mino(this, texture) {
             *      Position = new Vector2(2 * unitWidth, 1 * unitHeight)
             *  }
             * });
             *
             * this.Components.Add(piece);
             */

            int unitWidth  = Properties.Settings.Default.UnitWidth;
            int unitHeight = Properties.Settings.Default.UnitHeight;

            Texture2D texture = new Func <Texture2D>(() => {
                int w  = unitWidth;
                int h  = unitHeight;
                int sz = w * h;

                Texture2D tex = new Texture2D(GraphicsDevice, w, h);

                Color[] colors = new Color[sz];

                for (int i = 0; i < sz; ++i)
                {
                    colors[i] = Color.ForestGreen;
                }

                tex.SetData(colors);

                return(tex);
            })();

            Action <object[]> painter = new Action <object[]>((args) => {
                if (args.Length == 0)
                {
                    return;
                }
                if (args[0] is Sprite)
                {
                    Sprite sprite = args[0] as Sprite;
                    spriteBatch.Begin();
                    if (sprite.SpriteMode == SpriteModes.Single)
                    {
                        spriteBatch.Draw(
                            sprite.SamplingTexture,
                            sprite.Position * new Vector2(unitWidth, unitHeight),
                            null,
                            Color.White,
                            sprite.RotationAngle,
                            Vector2.Zero,
                            sprite.Scale,
                            SpriteEffects.None,
                            0
                            );
                    }
                    spriteBatch.End();
                }
            });

            List <Mino> minoList = new List <Mino> {
                new Mino(this)
                {
                    Position = new Vector2(1, 0),
                },
                new Mino(this)
                {
                    Position = new Vector2(0, 1)
                },
                new Mino(this)
                {
                    Position = new Vector2(1, 1)
                },
                new Mino(this)
                {
                    Position = new Vector2(2, 1)
                }
            };

            foreach (Mino mino in minoList)
            {
                mino.SamplingTexture = texture;
                mino.Painter         = painter;
            }

            Polyomino polyomino = new Polyomino(this)
            {
                FallMechanics   = new MinoFall(),
                ShiftMechanics  = new MinoShift(),
                RotateMechanics = new MinoRotate()
            };

            foreach (Mino mino in minoList)
            {
                polyomino.Minoes.Add(mino);
            }

            polyomino.OriginMino = polyomino.Minoes[2];

            Components.Add(polyomino);
        }
Пример #12
0
    private static void polyomino_transform_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_TRANSFORM_TEST tests POLYOMINO_TRANSFORM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    28 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Local parameters:
    //
    //    Local, int M, N, the number of rows and columns in the representation
    //    of the polyomino P.
    //
    //    Local, int P[M*N], a matrix of 0"s and 1"s representing the
    //    polyomino.  The matrix should be "tight", that is, there should be a
    //    1 in row 1, and in column 1, and in row M, and in column N.
    //
    {
        const int m  = 3;
        int       mq = 0;
        const int n  = 3;
        int       nq = 0;

        //
        //  P is given by columns, not rows.
        //
        int[] p =
        {
            0, 1, 0,
            1, 1, 1,
            1, 0, 0
        };
        int[] q = null;
        int   reflect;

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_TRANSFORM_TEST:");

        Console.WriteLine("  POLYOMINO_TRANSFORM can transform a polyomino.");
        Console.WriteLine("  Generate all 8 combinations of rotation and reflection");
        Console.WriteLine("  applied to a polyomino represented by a binary matrix.");

        Polyomino.polyomino_print(m, n, p, "  The given polyomino P:");

        for (reflect = 0; reflect <= 1; reflect++)
        {
            int rotate;
            for (rotate = 0; rotate <= 3; rotate++)
            {
                Polyomino.polyomino_transform(m, n, p, rotate, reflect, ref mq, ref nq, ref q);

                string label = "  P after " + reflect + " reflections and " + rotate + " rotations:";

                Polyomino.polyomino_print(mq, nq, q, label);
            }
        }

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_TRANSFORM_TEST:");
        Console.WriteLine("  Normal end of execution.");
    }
Пример #13
0
    private static void polyomino_index_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_INDEX_TEST tests POLYOMINO_INDEX.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       i;
        const int m = 3;
        const int n = 4;

        //
        //  P is listed in column-major order;
        //
        int[] p =
        {
            1, 1, 0,
            0, 1, 1,
            1, 1, 1,
            1, 0, 0
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_INDEX_TEST");

        Console.WriteLine("  POLYOMINO_INDEX assigns an index to each nonzero entry");
        Console.WriteLine("  of a polyomino.");

        Polyomino.polyomino_print(m, n, p, "  The polyomino P:");

        int[] pin = Polyomino.polyomino_index(m, n, p);

        Console.WriteLine("");
        Console.WriteLine("  PIN: Index vector for P:");
        Console.WriteLine("");
        for (i = 0; i < m; i++)
        {
            string cout = "";
            int    j;
            for (j = 0; j < n; j++)
            {
                cout += " " + pin[i + j * m];
            }

            Console.WriteLine(cout);
        }

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_INDEX_TEST");
        Console.WriteLine("  Normal end of execution.");
    }
Пример #14
0
    private static void polyomino_embed_list_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_EMBED_LIST_TEST tests POLYOMINO_EMBED_LIST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       k;
        const int mp = 3;
        const int mr = 4;
        const int np = 2;
        const int nr = 4;

        int[] p =
        {
            0, 0, 1,
            1, 1, 1
        };
        int[] q = new int[4 * 4];
        int[] r =
        {
            0, 1, 1, 1,
            1, 1, 1, 0,
            1, 0, 1, 1,
            1, 1, 1, 1
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_EMBED_LIST_TEST:");
        Console.WriteLine("  POLYOMINO_EMBED_LIST lists the offsets used");
        Console.WriteLine("  to embed a fixed polyomino in a region.");

        Polyomino.polyomino_print(mr, nr, r, "  The given region R:");

        Polyomino.polyomino_print(mp, np, p, "  The given polyomino P:");
        //
        //  Get the number of embeddings.
        //
        int number = Polyomino.polyomino_embed_number(mr, nr, r, mp, np, p);

        Console.WriteLine("");
        Console.WriteLine("  As a fixed polyomino, P can be embedded in R in " + number + " ways");

        /*
         * Get the list of embeddings.
         */
        int[] list = Polyomino.polyomino_embed_list(mr, nr, r, mp, np, p, number);

        for (k = 0; k < number; k++)
        {
            int mk = list[k + 0 * number];
            int nk = list[k + 1 * number];

            int i;
            int j;
            for (j = 0; j < nr; j++)
            {
                for (i = 0; i < mr; i++)
                {
                    q[i + j * mr] = r[i + j * mr];
                }
            }

            for (j = 0; j < np; j++)
            {
                for (i = 0; i < mp; i++)
                {
                    q[i + mk + (j + nk) * mr] += p[i + j * mp];
                }
            }

            Console.WriteLine("");
            Console.WriteLine("  Embedding number " + k + ":");
            Console.WriteLine("");
            for (i = 0; i < mr; i++)
            {
                string cout = "";
                for (j = 0; j < nr; j++)
                {
                    cout += " " + q[i + j * mr];
                }

                Console.WriteLine(cout);
            }
        }
    }