Beispiel #1
0
        private Tunneler acttunneler(Tunneler t, int action)//action: 0-move straight,  1-turn, 2-cross other tunnel, 3-stepback&turn
        {
            updtallcells();
            int d = tnextstep(t);

            t.prevactsuc = false;
            if (action == 0)
            {
                if (d == 1 || d == 3)
                {
                    if (t.cur.neighbours[d].neighbours[0].type == 0 && t.cur.neighbours[d].neighbours[2].type == 0 && cellvalid(t.cur.neighbours[d]))
                    {
                        t.prev     = t.cur;
                        t.cur      = t.prev.neighbours[d];
                        t.cur.type = 1;
                        floorcur   = floorcur + 1;
                        t.lenght--;
                        t.prevactsuc = true;
                    }
                }
                else if (d == 2 || d == 0)
                {
                    if (t.cur.neighbours[d].neighbours[1].type == 0 && t.cur.neighbours[d].neighbours[3].type == 0 && cellvalid(t.cur.neighbours[d]))
                    {
                        t.prev     = t.cur;
                        t.cur      = t.prev.neighbours[d];
                        t.cur.type = 1;
                        floorcur   = floorcur + 1;
                        t.lenght--;
                        t.prevactsuc = true;
                    }
                }
            }
            if (action == 1)
            {
                if (t.wide == 1)
                {
                    int turn = choosetdir(t.cur, 0);
                    if (turn < 0)
                    {
                        t.prevactsuc = false;
                    }
                    else
                    {
                        t.prev       = t.cur;
                        t.cur        = t.cur.neighbours[turn];
                        t.cur.type   = 1;
                        floorcur     = floorcur + 1;
                        t.lenght     = t.lenght - 1;
                        t.prevactsuc = true;
                    }
                }
                else
                {
                    bool   l   = true;
                    bool   r   = true;
                    Random rnd = new Random();
                    while (r || l)
                    {
                        int c = rnd.Next(0, 2);
                        if (c == 0 || r == false)
                        {
                            l = false;
                            int turn = choosetdir(t.left, 0);
                            if (turn < 0)
                            {
                                t.prevactsuc = false;
                            }
                            else
                            {
                                t.prev       = t.left;
                                t.cur        = t.left.neighbours[turn];
                                t.cur.type   = 1;
                                floorcur     = floorcur + 1;
                                t.lenght     = t.lenght - 1;
                                t.prevactsuc = true;
                                r            = false;
                                break;
                            }
                        }
                        else
                        {
                            r = false;
                            int turn = choosetdir(t.right, 0);
                            if (turn < 0)
                            {
                                t.prevactsuc = false;
                            }
                            else
                            {
                                t.prev       = t.right;
                                t.cur        = t.right.neighbours[turn];
                                t.cur.type   = 1;
                                floorcur     = floorcur + 1;
                                t.lenght     = t.lenght - 1;
                                t.prevactsuc = true;
                                l            = false;
                                break;
                            }
                        }
                    }
                }
            }
            if (action == 2)
            {
                for (int i = 0; i < 5; i++)
                {
                    t.prev = t.cur;
                    t.cur  = t.prev.neighbours[d];
                    if (t.cur.neighbours[d].type == 0)
                    {
                        t.prevactsuc = true;
                        t            = acttunneler(t, 0);
                        break;
                    }
                    if (t.cur.type == 0)
                    {
                        break;
                    }
                }
            }
            if (action == 3)
            {
                MapTile temp = t.cur;
                t.cur  = t.prev;
                t.prev = temp;
                int turn = choosetdir(t.cur, 0);
                if (turn < 0)
                {
                    t.prevactsuc = false;
                }
                else
                {
                    Random r  = new Random();
                    int    ra = r.Next(0, 2);
                    if (ra == 0)
                    {
                        t.prev.type = 0;
                        floorcur    = floorcur - 1;
                    }
                    else
                    {
                        widetun(t, 1);
                    }
                    t.prev       = t.cur;
                    t.cur        = t.prev.neighbours[turn];
                    t.cur.type   = 1;
                    floorcur     = floorcur + 1;
                    t.lenght     = t.lenght - 1;
                    t.prevactsuc = true;
                }
            }
            return(t);
        }
Beispiel #2
0
        private Tunneler widetun(Tunneler t, int type)//wide out tunnels//type- 0=regular, 1=wideprev, 2=widestraight(for making straight nit "cavelike" tunnels)(not implemented)
        {
            updtallcells();
            int    d   = tnextstep(t);
            Random rnd = new Random();

            if (d == 1 || d == 3)
            {
                int     w     = t.wide;
                MapTile left  = t.cur;
                MapTile right = t.cur;
                if (type == 1)
                {
                    left  = t.prev;
                    right = t.prev;
                }
                bool r = true;
                bool l = true;
                while ((l || r) && w > 1)
                {
                    int chose = rnd.Next(0, 2);
                    if (chose == 0)
                    {
                        if (cellvalid(left.neighbours[0]) && left.neighbours[0].neighbours[0].type == 0)
                        {
                            left      = left.neighbours[0];
                            left.type = 1;
                            t.left    = left;
                            w--;
                            floorcur++;
                            t.allcells.Add(left);
                        }
                        else
                        {
                            l = false;
                        }
                    }
                    else
                    {
                        if (cellvalid(right.neighbours[2]) && right.neighbours[2].neighbours[2].type == 0)
                        {
                            right      = right.neighbours[2];
                            right.type = 1;
                            t.right    = right;
                            w--;
                            floorcur++;
                            t.allcells.Add(right);
                        }
                        else
                        {
                            r = false;
                        }
                    }
                }
            }
            else
            {
                int     w     = t.wide;
                MapTile left  = t.cur;
                MapTile right = t.cur;
                if (type == 1)
                {
                    left  = t.prev;
                    right = t.prev;
                }
                bool r = true;
                bool l = true;
                while ((l || r) && w > 1)
                {
                    int chose = rnd.Next(0, 2);
                    if (chose == 0)
                    {
                        if (cellvalid(left.neighbours[1]) && left.neighbours[1].neighbours[1].type == 0)
                        {
                            left      = left.neighbours[1];
                            left.type = 1;
                            t.left    = left;
                            w--;
                            floorcur++;
                            t.allcells.Add(left);
                        }
                        else
                        {
                            l = false;
                        }
                    }
                    else
                    {
                        if (cellvalid(right.neighbours[3]) && right.neighbours[3].neighbours[3].type == 0)
                        {
                            right      = right.neighbours[3];
                            right.type = 1;
                            t.right    = right;
                            w--;
                            floorcur++;
                            t.allcells.Add(right);
                        }
                        else
                        {
                            r = false;
                        }
                    }
                }
            }
            return(t);
        }
Beispiel #3
0
        public void generatemap(int de)//creating new map
        {
            deep                = de;
            valcells            = new Filtvalcells();
            valcells.bestcells  = new List <MapTile>();
            valcells.normdcells = new List <MapTile>();
            valcells.badcells   = new List <MapTile>();
            floornum            = 0;
            floorcur            = 0;
            Random r = new Random();

            sethw(deep);
            cavesize = getmaxcavesize();
            widtun   = getmaxtunwidth();
            tiles    = new MapTile[height, width];
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    tiles[i, j]            = new MapTile();
                    tiles[i, j].neighbours = new MapTile[4];
                }
            }
            iniccells();
            int entdp = (height - 3) * (width - 3);

            for (int i = 1; i < height - 2; i++)
            {
                for (int j = 1; j < width - 2; j++)
                {
                    if (entdp > 0)
                    {
                        int t = r.Next(0, entdp);
                        if (t == 0 || entdp == 1)
                        {
                            tiles[i, j].type = 1;
                            tiles[i, j].qual = 0;
                            floorcur++;
                            updtallcells();
                            valcells.bestcells.Add(tiles[i, j]);
                            //tiles[i, j].backgrnd = Brushes.Red;
                            tiles[i, j].contains.Add("enter");
                            enter.y = i;
                            enter.x = j;
                            entdp   = 0;
                            createmap();        //aand starting mapgen
                            while (exit.x == 0) //sometimes exit doesnt created. there must be some fixable issue but i dont want to adress it right now, so just try until it creates(FIX LATER!)
                            {
                                makeexit(tiles[i, j], 0, 1, new List <MapTile>()
                                {
                                    tiles[i, j]
                                });
                            }
                            i = height;
                            j = width;
                        }
                        entdp = entdp - 1;
                    }
                }
            }
        }
Beispiel #4
0
        private int choosetdir(MapTile mt, int type)//0-regular(random valid cell), 1-first cell(best valid cell)//returns neighbour index for valid direction of next move
        {
            //updtallcells();//_______________________________________________________________________________________________________________
            Random r = new Random();
            int    d = r.Next(0, 4);

            if (type == 0)
            {
                bool[] b = new bool[4] {
                    false, false, false, false
                };
                while (b[0] == false || b[1] == false || b[2] == false || b[3] == false)
                {
                    while (b[d])
                    {
                        d = r.Next(0, 4);
                    }
                    if (cellvalid(mt.neighbours[d]))
                    {
                        if (d == 1 || d == 3)
                        {
                            if (mt.neighbours[d].neighbours[0].type == 0 && mt.neighbours[d].neighbours[2].type == 0 && mt.neighbours[d].neighbours[d].type == 0)
                            {
                                return(d);
                            }
                            else
                            {
                                b[d] = true;
                            }
                        }
                        else
                        {
                            if (mt.neighbours[d].neighbours[1].type == 0 && mt.neighbours[d].neighbours[3].type == 0 && mt.neighbours[d].neighbours[d].type == 0)
                            {
                                return(d);
                            }
                            else
                            {
                                b[d] = true;
                            }
                        }
                    }
                    else
                    {
                        b[d] = true;
                    }
                }
                if (!Array.Exists(b, x => x == false))
                {
                    d = -1;
                }
            }
            else
            {
                int[] b = new int[4] {
                    -1, -1, -1, -1
                };
                for (int i = 0; i < 4; i++)
                {
                    if (cellvalid(mt.neighbours[i]))
                    {
                        if (i == 1 || i == 3)
                        {
                            if (mt.neighbours[i].neighbours[0].type == 0 && mt.neighbours[i].neighbours[2].type == 0 && mt.neighbours[i].neighbours[i].type == 0)
                            {
                                int t = dcv2(mt.neighbours[i], 0, new List <MapTile>());
                                if (t > 250)
                                {
                                    b[i] = 0;
                                }
                                else if (t <= 250 && t > 100)
                                {
                                    b[i] = 1;
                                }
                                else
                                {
                                    b[i] = 2;
                                }
                            }
                            else
                            {
                                b[i] = -1;
                            }
                        }
                        else
                        {
                            if (mt.neighbours[i].neighbours[1].type == 0 && mt.neighbours[i].neighbours[3].type == 0 && mt.neighbours[i].neighbours[i].type == 0)
                            {
                                int t = dcv2(mt.neighbours[i], 0, new List <MapTile>());
                                if (t > 250)
                                {
                                    b[i] = 0;
                                }
                                else if (t <= 250 && t > 100)
                                {
                                    b[i] = 1;
                                }
                                else
                                {
                                    b[i] = 2;
                                }
                            }
                            else
                            {
                                b[i] = -1;
                            }
                        }
                    }
                    else
                    {
                        b[i] = -1;
                    }
                }
                if (!Array.Exists(b, x => x != -1))
                {
                    return(-1);
                }
                for (int i = 0; i < 3; i++)
                {
                    if (Array.Exists(b, x => x == i))
                    {
                        while (b[d] != i)
                        {
                            d = r.Next(0, 4);
                        }
                        return(d);
                    }
                }
            }
            return(d);
        }