Esempio n. 1
0
    public Map(Map otherMap)
    {
        this.map_width  = otherMap.map_width;
        this.map_height = otherMap.map_height;

        this._sites = new Site[this.map_width, this.map_height];
        Array.Copy(otherMap._sites, this._sites, this.map_width * this.map_height);
    }
Esempio n. 2
0
 private Map(ushort width, ushort height) {
     _sites = new Site[width, height];
     for (ushort x = 0; x < width; x++) {
         for (ushort y = 0; y < height; y++) {
             _sites[x, y] = new Site();
         }
     }
 }
Esempio n. 3
0
    public Map(ushort width, ushort height)
    {
        this.map_height = height;
        this.map_width  = width;

        this._sites = new Site[width, height];
        for (ushort x = 0; x < width; x++)
        {
            for (ushort y = 0; y < height; y++)
            {
                this._sites[x, y] = new Site();
            }
        }
    }
Esempio n. 4
0
 public Map(Map otherMap)
 {
     map_width  = otherMap.map_width;
     map_height = otherMap.map_height;
     contents   = new Site[otherMap.contents.GetLength(0), otherMap.contents.GetLength(1)];
     for (int i = 0; i < contents.GetLength(0); i++)
     {
         for (int j = 0; j < contents.GetLength(1); j++)
         {
             contents[i, j]            = new Site();
             contents[i, j].owner      = otherMap.contents[i, j].owner;
             contents[i, j].production = otherMap.contents[i, j].production;
             contents[i, j].strength   = otherMap.contents[i, j].strength;
             contents[i, j].id         = otherMap.contents[i, j].id;
             contents[i, j].gain       = otherMap.contents[i, j].gain;
         }
     }
 }
Esempio n. 5
0
        public Map(string[] production, string[] state, int width, int height)
        {
            map_width  = width;
            map_height = height;
            contents   = new Site[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    contents[i, j]            = new Site();
                    contents[i, j].production = int.Parse(production[j * width + i]);
                    contents[i, j].strength   = int.Parse(state[state.Length - width * height + j * width + i]);
                }
            }

            int bound = -1;
            int owner = 0;
            int index = 0;

            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    int now = j * width + i;
                    if (now > bound)
                    {
                        bound += int.Parse(state[index]);
                        owner  = int.Parse(state[index + 1]);
                        index += 2;
                    }
                    contents[i, j].owner = owner;
                }
            }

            updateGain();
        }
Esempio n. 6
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            int numberOfRows = 3;

            IList <Site> colActiveSites = GetSites();

            Site[,] aryActiveSites = CovertListToMultiDimensionalArray(numberOfRows, colActiveSites);

            for (int row = 0; row < aryActiveSites.GetUpperBound(0) + 1; row++)
            {
                TableRow tempRow = new TableRow();
                for (int col = 0; col < aryActiveSites.GetUpperBound(1) + 1; col++)
                {
                    if (aryActiveSites[row, col] != null)
                    {
                        TableCell cell01   = new TableCell();
                        CheckBox  chkSite1 = new CheckBox();
                        chkSite1.ID              = SITE_ID + aryActiveSites[row, col].SiteID.ToString();
                        chkSite1.AutoPostBack    = false;
                        chkSite1.ClientIDMode    = ClientIDMode.Static;
                        chkSite1.EnableViewState = true;
                        cell01.Controls.Add(chkSite1);
                        cell01.CssClass = "chk";
                        tempRow.Cells.Add(cell01);

                        TableCell cell02 = new TableCell();
                        cell02.Text     = aryActiveSites[row, col].SiteName.ToString();
                        cell02.CssClass = "txt";
                        tempRow.Cells.Add(cell02);
                    }
                }
                tblSites.Rows.Add(tempRow);
            }
        }
Esempio n. 7
0
 private Map(ushort width, ushort height)
 {
     _sites = new Site[width, height];
     for (ushort x = 0; x < width; x++) {
         for (ushort y = 0; y < height; y++) {
             _sites[x, y] = new Site();
         }
     }
 }
Esempio n. 8
0
        public Map(int width, int height, int numberOfPlayers, int seed)
        {
            //Pseudorandom number generator.
            Random rand = new Random(seed);

            //Decides whether to put more players along the horizontal or the vertical.
            bool preferHorizontal = rand.Next(2) == 0 ? true : false;

            int dw, dh;

            //Find number closest to square that makes the match symmetric.
            if (preferHorizontal)
            {
                dh = (int)Math.Sqrt(numberOfPlayers);
                while (numberOfPlayers % dh != 0)
                {
                    dh--;
                }
                dw = numberOfPlayers / dh;
            }
            else
            {
                dw = (int)Math.Sqrt(numberOfPlayers);
                while (numberOfPlayers % dw != 0)
                {
                    dw--;
                }
                dh = numberOfPlayers / dw;
            }

            //Figure out chunk width and height accordingly.
            //Matches width and height as closely as it can, but is not guaranteed to match exactly.
            //It is guaranteed to be smaller if not the same size, however.
            int cw = width / dw;
            int ch = height / dh;

            //Ensure that we'll be able to move the tesselation by a uniform amount.
            if (preferHorizontal)
            {
                while (ch % numberOfPlayers != 0)
                {
                    ch--;
                }
            }
            else
            {
                while (cw % numberOfPlayers != 0)
                {
                    cw--;
                }
            }

            map_width  = cw * dw;
            map_height = ch * dh;

            Region prodRegion = new Region(cw, ch, rand);

            double[,] prodChunk = prodRegion.getFactors();

            Region strengthRegion = new Region(cw, ch, rand);

            double[,] strengthChunk = strengthRegion.getFactors();



            //We'll first tesselate the map; we'll apply our various translations and transformations later.
            SiteD[,] tesselation = new SiteD[map_height, map_width];
            for (int i = 0; i < map_height; i++)
            {
                for (int j = 0; j < map_width; j++)
                {
                    tesselation[i, j] = new SiteD();
                }
            }
            for (int a = 0; a < dh; a++)
            {
                for (int b = 0; b < dw; b++)
                {
                    for (int c = 0; c < ch; c++)
                    {
                        for (int d = 0; d < cw; d++)
                        {
                            tesselation[a * ch + c, b *cw + d].production = prodChunk[c, d];
                            tesselation[a * ch + c, b *cw + d].strength   = strengthChunk[c, d];
                        }
                    }
                    tesselation[a * ch + ch / 2, b *cw + cw / 2].owner = a * dw + b + 1;  //Set owners.
                }
            }

            //We'll now apply the reflections to the map.
            bool reflectVertical = dh % 2 == 0, reflectHorizontal = dw % 2 == 0; //Am I going to reflect in the horizontal vertical directions at all?

            SiteD[,] reflections = new SiteD[map_height, map_width];
            for (int a = 0; a < dh; a++)
            {
                for (int b = 0; b < dw; b++)
                {
                    bool vRef = reflectVertical && a % 2 != 0, hRef = reflectHorizontal && b % 2 != 0; //Do I reflect this chunk at all?
                    for (int c = 0; c < ch; c++)
                    {
                        for (int d = 0; d < cw; d++)
                        {
                            reflections[a * ch + c, b *cw + d] = tesselation[a * ch + (vRef ? ch - c - 1 : c), b *cw + (hRef ? cw - d - 1 : d)];
                        }
                    }
                }
            }

            //Next, let's apply our shifts to create the shifts map.
            SiteD[,] shifts = new SiteD[map_height, map_width];
            if (preferHorizontal)
            {
                int shift = rand.Next(dw) * (map_height / dw); //A vertical shift.
                for (int a = 0; a < dh; a++)
                {
                    for (int b = 0; b < dw; b++)
                    {
                        for (int c = 0; c < ch; c++)
                        {
                            for (int d = 0; d < cw; d++)
                            {
                                shifts[a * ch + c, b *cw + d] = reflections[(a * ch + b * shift + c) % map_height, b *cw + d];
                            }
                        }
                    }
                }
            }
            else
            {
                int shift = rand.Next(dh) * (map_width / dh); //A horizontal shift.
                for (int a = 0; a < dh; a++)
                {
                    for (int b = 0; b < dw; b++)
                    {
                        for (int c = 0; c < ch; c++)
                        {
                            for (int d = 0; d < cw; d++)
                            {
                                shifts[a * ch + c, b *cw + d] = reflections[a * ch + c, (b * cw + a * shift + d) % map_width];
                            }
                        }
                    }
                }
            }

            //Apply a final blur to create the blur map. This will fix the edges where our transformations have created jumps or gaps.
            const double OWN_WEIGHT = 0.66667;

            SiteD[,] blur = shifts;
            for (int z = 0; z <= 2 * Math.Sqrt(map_width * map_height) / 10; z++)
            {
                SiteD[,] newBlur = blur;
                for (int a = 0; a < map_height; a++)
                {
                    int mh = a - 1, ph = a + 1;
                    if (mh < 0)
                    {
                        mh += map_height;
                    }
                    if (ph == map_height)
                    {
                        ph = 0;
                    }
                    for (int b = 0; b < map_width; b++)
                    {
                        int mw = b - 1, pw = b + 1;
                        if (mw < 0)
                        {
                            mw += map_width;
                        }
                        if (pw == map_width)
                        {
                            pw = 0;
                        }
                        newBlur[a, b].production *= OWN_WEIGHT;
                        newBlur[a, b].production += blur[mh, b].production * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].production += blur[ph, b].production * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].production += blur[a, mw].production * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].production += blur[a, pw].production * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].strength   *= OWN_WEIGHT;
                        newBlur[a, b].strength   += blur[mh, b].strength * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].strength   += blur[ph, b].strength * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].strength   += blur[a, mw].strength * (1 - OWN_WEIGHT) / 4;
                        newBlur[a, b].strength   += blur[a, pw].strength * (1 - OWN_WEIGHT) / 4;
                    }
                }
                blur = newBlur;
            }

            //Let's now normalize the map values.
            double maxProd = 0, maxStr = 0;

            SiteD[,] normalized = blur;
            for (int a = 0; a < normalized.GetLength(0); a++)
            {
                for (int b = 0; b < normalized.GetLength(1); b++)
                {
                    if (normalized[a, b].production > maxProd)
                    {
                        maxProd = normalized[a, b].production;
                    }
                    if (normalized[a, b].strength > maxStr)
                    {
                        maxStr = normalized[a, b].strength;
                    }
                }
            }
            for (int a = 0; a < normalized.GetLength(0); a++)
            {
                for (int b = 0; b < normalized.GetLength(1); b++)
                {
                    normalized[a, b].production /= maxProd;
                    normalized[a, b].strength   /= maxStr;
                }
            }

            //Finally, fill in the contents vector.
            int TOP_PROD = rand.Next(10) + 6;
            int TOP_STR  = rand.Next(106) + 150;

            contents = new Site[map_height, map_width];
            for (int i = 0; i < map_height; i++)
            {
                for (int j = 0; j < map_width; j++)
                {
                    contents[i, j] = new Site();
                }
            }
            for (int a = 0; a < map_height; a++)
            {
                for (int b = 0; b < map_width; b++)
                {
                    contents[a, b].owner      = normalized[a, b].owner;
                    contents[a, b].strength   = (int)Math.Round(normalized[a, b].strength * TOP_STR);
                    contents[a, b].production = (int)Math.Round(normalized[a, b].production * TOP_PROD);
                    if (contents[a, b].owner != 0 && contents[a, b].production == 0)
                    {
                        contents[a, b].production = 1;
                    }
                }
            }

            int tt = map_width;

            map_width  = map_height;
            map_height = tt;

            updateGain();
        }
Esempio n. 9
0
        public int map_width, map_height; //Number of rows and columns, NOT maximum index.

        Map()
        {
            map_width  = 0;
            map_height = 0;
            contents   = new Site[map_height, map_width];
        }
Esempio n. 10
0
    public Map(ushort width, ushort height, int numberOfPlayers, ulong _Seed, bool force = false) : this(width, height)
    {
        //Pseudorandom number generator.
        this.prg = new MT19937();
        this.prg.init_genrand(_Seed);

        //Decides whether to put more players along the horizontal or the vertical.
        var preferHorizontal = this.prg.genrand_int31() % 2 == 1;

        int dw, dh;

        //Find number closest to square that makes the match symmetric.
        if (preferHorizontal)
        {
            dh = (int)Math.Sqrt(numberOfPlayers);
            while (numberOfPlayers % dh != 0)
            {
                dh--;
            }
            dw = numberOfPlayers / dh;
        }
        else
        {
            dw = (int)Math.Sqrt(numberOfPlayers);
            while (numberOfPlayers % dw != 0)
            {
                dw--;
            }
            dh = numberOfPlayers / dw;
        }

        //Figure out chunk width and height accordingly.
        //Matches width and height as closely as it can, but is not guaranteed to match exactly.
        //It is guaranteed to be smaller if not the same size, however.
        var cw = width / dw;
        var ch = height / dh;

        //Ensure that we'll be able to move the tesselation by a uniform amount.
        if (preferHorizontal)
        {
            while (ch % numberOfPlayers != 0)
            {
                ch--;
            }
        }
        else
        {
            while (cw % numberOfPlayers != 0)
            {
                cw--;
            }
        }

        this.map_width  = cw * dw;
        this.map_height = ch * dh;


        var prodRegion = new Region(cw, ch, () => this.prg.genrand_real1());
        List <List <double> > prodChunk = prodRegion.GetFactors();

        var strengthRegion = new Region(cw, ch, () => this.prg.genrand_real1());
        List <List <double> > strengthChunk = strengthRegion.GetFactors();


        //We'll first tesselate the map; we'll apply our various translations and transformations later.
        var tesselation = new SiteD[this.map_height, this.map_width];

        for (var a = 0; a < dh; a++)
        {
            for (var b = 0; b < dw; b++)
            {
                for (var c = 0; c < ch; c++)
                {
                    for (var d = 0; d < cw; d++)
                    {
                        tesselation[a * ch + c, b *cw + d].production = prodChunk[c][d];
                        tesselation[a * ch + c, b *cw + d].strength   = strengthChunk[c][d];
                    }
                }
                tesselation[a * ch + ch / 2, b *cw + cw / 2].owner = (char)(a * dw + b + 1);  //Set owners.
            }
        }


        //We'll now apply the reflections to the map.
        bool reflectVertical = dh % 2 == 0, reflectHorizontal = dw % 2 == 0; //Am I going to reflect in the horizontal vertical directions at all?
        var  reflections = new SiteD[this.map_height, this.map_width];

        for (var a = 0; a < dh; a++)
        {
            for (var b = 0; b < dw; b++)
            {
                bool vRef = reflectVertical && a % 2 != 0, hRef = reflectHorizontal && b % 2 != 0; //Do I reflect this chunk at all?
                for (var c = 0; c < ch; c++)
                {
                    for (var d = 0; d < cw; d++)
                    {
                        reflections[a * ch + c, b *cw + d] = tesselation[a * ch + (vRef ? ch - c - 1 : c), b *cw + (hRef ? cw - d - 1 : d)];
                    }
                }
            }
        }

        //Next, let's apply our shifts to create the shifts map.
        var shifts = new SiteD[this.map_height, this.map_height];

        if (preferHorizontal)
        {
            var shift = (this.prg.genrand_int31() % dw == 1 ? 1 : 0) * (this.map_height / dw); //A vertical shift.
            for (var a = 0; a < dh; a++)
            {
                for (var b = 0; b < dw; b++)
                {
                    for (var c = 0; c < ch; c++)
                    {
                        for (var d = 0; d < cw; d++)
                        {
                            shifts[a * ch + c, b *cw + d] = reflections[(a * ch + b * shift + c) % this.map_height, b *cw + d];
                        }
                    }
                }
            }
        }
        else
        {
            var shift = (this.prg.genrand_int31() % dh == 1 ? 1 : 0) * (this.map_width / dh); //A horizontal shift.
            for (var a = 0; a < dh; a++)
            {
                for (var b = 0; b < dw; b++)
                {
                    for (var c = 0; c < ch; c++)
                    {
                        for (var d = 0; d < cw; d++)
                        {
                            shifts[a * ch + c, b *cw + d] = reflections[a * ch + c, (b * cw + a * shift + d) % this.map_width];
                        }
                    }
                }
            }
        }

        //Apply a final blur to create the blur map. This will fix the edges where our transformations have created jumps or gaps.
        const double OWN_WEIGHT = 0.66667;
        var          blur       = new SiteD[this.map_height, this.map_width];

        Array.Copy(shifts, blur, this.map_height * this.map_width);

        for (var z = 0; z <= 2 * Math.Sqrt(this.map_width * this.map_height) / 10; z++)
        {
            var newBlur = new SiteD[this.map_height, this.map_width];
            Array.Copy(blur, newBlur, this.map_height * this.map_width);

            for (var a = 0; a < this.map_height; a++)
            {
                int mh = a - 1, ph = a + 1;
                if (mh < 0)
                {
                    mh += this.map_height;
                }
                if (ph == this.map_height)
                {
                    ph = 0;
                }
                for (var b = 0; b < this.map_width; b++)
                {
                    int mw = b - 1, pw = b + 1;
                    if (mw < 0)
                    {
                        mw += this.map_width;
                    }
                    if (pw == this.map_width)
                    {
                        pw = 0;
                    }

                    newBlur[a, b].production *= OWN_WEIGHT;
                    newBlur[a, b].production += blur[mh, b].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[ph, b].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[a, mw].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].production += blur[a, pw].production * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   *= OWN_WEIGHT;
                    newBlur[a, b].strength   += blur[mh, b].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[ph, b].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[a, mw].strength * (1 - OWN_WEIGHT) / 4;
                    newBlur[a, b].strength   += blur[a, pw].strength * (1 - OWN_WEIGHT) / 4;
                }
            }
            blur = newBlur;
        }

        //Let's now normalize the map values.
        double maxProduction = 0, maxStrength = 0;
        var    normalized = new SiteD[this.map_height, this.map_width];

        Array.Copy(blur, normalized, this.map_height * this.map_width);

        foreach (var b in normalized)
        {
            if (b.production > maxProduction)
            {
                maxProduction = b.production;
            }
            if (b.strength > maxStrength)
            {
                maxStrength = b.strength;
            }
        }

        for (var i = 0; i < this.map_height; i++)
        {
            for (var j = 0; j < this.map_width; j++)
            {
                normalized[i, j].production /= maxProduction;
                normalized[i, j].strength   /= maxStrength;
            }
        }

        //Finally, fill in the contents vector.
        var TOP_PROD = (int)(this.prg.genrand_int31() % 10 + 6);
        var TOP_STR  = (int)(this.prg.genrand_int31() % 106 + 150);

        this._sites = new Site[this.map_width, this.map_height];

        for (var a = 0; a < this.map_height; a++)
        {
            for (var b = 0; b < this.map_width; b++)
            {
                this._sites[b, a].Owner      = normalized[a, b].owner;
                this._sites[b, a].Strength   = (ushort)Math.Round(normalized[a, b].strength * TOP_STR);
                this._sites[b, a].Production = (ushort)Math.Round(normalized[a, b].production * TOP_PROD);
                if (this._sites[b, a].Owner != 0 && this._sites[b, a].Production == 0)
                {
                    this._sites[b, a].Production = 1;
                }
            }
        }
    }