Example #1
0
        protected void draw(Tilemap tilemap, int tx, int ty, bool erase)
        {
            Tilemap tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] desiredIdPattern = new int[3, 3] {
                       { tm.getTileAt(tx-1,ty-1), tm.getTileAt(tx+0,ty-1), tm.getTileAt(tx+1,ty-1) },
                       { tm.getTileAt(tx-1,ty+0), tm.getTileAt(tx+0,ty+0), tm.getTileAt(tx+1,ty+0) },
                       { tm.getTileAt(tx-1,ty+1), tm.getTileAt(tx+0,ty+1), tm.getTileAt(tx+1,ty+1) }
                    };

            bool[,] desiredSolPattern = new bool[3, 3] {
                       { tr.isSolid[tm.getTileAt(tx-1,ty-1)], tr.isSolid[tm.getTileAt(tx+0,ty-1)], tr.isSolid[tm.getTileAt(tx+1,ty-1)] },
                       { tr.isSolid[tm.getTileAt(tx-1,ty+0)], !erase                             , tr.isSolid[tm.getTileAt(tx+1,ty+0)] },
                       { tr.isSolid[tm.getTileAt(tx-1,ty+1)], tr.isSolid[tm.getTileAt(tx+0,ty+1)], tr.isSolid[tm.getTileAt(tx+1,ty+1)] }
            };

            float bestSimilarity = 0;
            int[,] bestPattern = new int[3, 3] {
                       { tm.getTileAt(tx-1,ty-1), tm.getTileAt(tx+0,ty-1), tm.getTileAt(tx+1,ty-1) },
                       { tm.getTileAt(tx-1,ty+0), tm.getTileAt(tx+0,ty+0), tm.getTileAt(tx+1,ty+0) },
                       { tm.getTileAt(tx-1,ty+1), tm.getTileAt(tx+0,ty+1), tm.getTileAt(tx+1,ty+1) }
                    };

            for (int i = 0; i < id_matrices.Count; i++) {
                int[,] m1 = id_matrices[i];
                int[,] m2 = desiredIdPattern;

                bool[,] m3 = solid_matrices[i];
                bool[,] m4 = desiredSolPattern;

                float thisSimilarity = 0;
                for (int px = 0; px < 3; px++) {
                    for (int py = 0; py < 3; py++) {
                        if ((px == 1) && (py == 1)) {
                            if (tr.isSolid[m1[px, py]] == (!erase)) thisSimilarity += 1000;
                            continue;
                        }
                        if (m1[px, py] == m2[px, py]) thisSimilarity += 1;
                        if (m3[px, py] == m4[px, py]) thisSimilarity += 100;

                    }
                }

                if (thisSimilarity > bestSimilarity) { bestSimilarity = thisSimilarity; bestPattern = m1; }

            }

            if (bestSimilarity > 0) {
                int[,] m1 = bestPattern;

                tm.setTileAt(tx - 1, ty - 1, m1[0, 0]);
                tm.setTileAt(tx + 0, ty - 1, m1[0, 1]);
                tm.setTileAt(tx + 1, ty - 1, m1[0, 2]);
                tm.setTileAt(tx - 1, ty + 0, m1[1, 0]);
                tm.setTileAt(tx + 0, ty + 0, m1[1, 1]);
                tm.setTileAt(tx + 1, ty + 0, m1[1, 2]);
                tm.setTileAt(tx - 1, ty + 1, m1[2, 0]);
                tm.setTileAt(tx + 0, ty + 1, m1[2, 1]);
                tm.setTileAt(tx + 1, ty + 1, m1[2, 2]);
            }
        }
Example #2
0
 private void clTilemaps_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentTilemap = (Tilemap)clTilemaps.SelectedItem;
     pbCanvas.Invalidate();
 }
Example #3
0
 public void learn(Tilemap tilemap)
 {
     for (int tx = 0; tx < tilemap.width; tx++) {
         for (int ty = 0; ty < tilemap.height; ty++) {
             learn(tilemap, tx, ty);
         }
     }
 }
Example #4
0
        //if (!careful) {
        //    if (!matrixExists(new int[3, 3] {
        //       { tm.getTileAt(tx-2,ty-1), m1[0, 0], m1[0, 1] },
        //       { getTileAt(tx-2,ty+0), m1[1, 0], m1[1, 1] },
        //       { getTileAt(tx-2,ty+1), m1[2, 0], m1[2, 1] }
        //       })) thisSimilarity -= 100;
        //    if (!matrixExists(new int[3, 3] {
        //       { m1[0, 1], m1[0, 1], getTileAt(tx+2,ty-1)},
        //       { m1[1, 1], m1[1, 2], getTileAt(tx+2,ty+0)},
        //       { m1[2, 1], m1[2, 2], getTileAt(tx+2,ty+1)}
        //       })) thisSimilarity -= 100;
        //}
        public void learn(Tilemap tilemap, int tx, int ty)
        {
            Tilemap tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] m1 = new int[3, 3] {
                           { tm.getTileAt(tx-1,ty-1), tm.getTileAt(tx+0,ty-1), tm.getTileAt(tx+1,ty-1) },
                           { tm.getTileAt(tx-1,ty+0), tm.getTileAt(tx+0,ty+0), tm.getTileAt(tx+1,ty+0) },
                           { tm.getTileAt(tx-1,ty+1), tm.getTileAt(tx+0,ty+1), tm.getTileAt(tx+1,ty+1) }
                        };
            bool[,] m2 = new bool[3, 3] {
                           { tr.isSolid[tm.getTileAt(tx-1,ty-1)], tr.isSolid[tm.getTileAt(tx+0,ty-1)], tr.isSolid[tm.getTileAt(tx+1,ty-1)] },
                           { tr.isSolid[tm.getTileAt(tx-1,ty+0)], tr.isSolid[tm.getTileAt(tx+0,ty+0)], tr.isSolid[tm.getTileAt(tx+1,ty+0)] },
                           { tr.isSolid[tm.getTileAt(tx-1,ty+1)], tr.isSolid[tm.getTileAt(tx+0,ty+1)], tr.isSolid[tm.getTileAt(tx+1,ty+1)] }
                        };

            if (!matrixExists(m1)) {
                id_matrices.Add(m1);
                solid_matrices.Add(m2);
            }
        }
Example #5
0
        public void forget(Tilemap tilemap, int tx, int ty)
        {
            Tilemap tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] m1 = new int[3, 3] {
                           { tm.getTileAt(tx-1,ty-1), tm.getTileAt(tx+0,ty-1), tm.getTileAt(tx+1,ty-1) },
                           { tm.getTileAt(tx-1,ty+0), tm.getTileAt(tx+0,ty+0), tm.getTileAt(tx+1,ty+0) },
                           { tm.getTileAt(tx-1,ty+1), tm.getTileAt(tx+0,ty+1), tm.getTileAt(tx+1,ty+1) }
                        };
            bool[,] m2 = new bool[3, 3] {
                           { tr.isSolid[tm.getTileAt(tx-1,ty-1)], tr.isSolid[tm.getTileAt(tx+0,ty-1)], tr.isSolid[tm.getTileAt(tx+1,ty-1)] },
                           { tr.isSolid[tm.getTileAt(tx-1,ty+0)], tr.isSolid[tm.getTileAt(tx+0,ty+0)], tr.isSolid[tm.getTileAt(tx+1,ty+0)] },
                           { tr.isSolid[tm.getTileAt(tx-1,ty+1)], tr.isSolid[tm.getTileAt(tx+0,ty+1)], tr.isSolid[tm.getTileAt(tx+1,ty+1)] }
                        };

            for (int i = 0; i < id_matrices.Count; i++) {
                if (equal(m1, id_matrices[i])) {
                    id_matrices.RemoveAt(i);
                    solid_matrices.RemoveAt(i);
                }
            }
        }
Example #6
0
 public void erase(Tilemap tilemap, int tx, int ty)
 {
     draw(tilemap, tx, ty, true);
 }
Example #7
0
 public void draw(Tilemap tilemap, int tx, int ty)
 {
     draw(tilemap, tx, ty, false);
 }