コード例 #1
0
ファイル: Form1.cs プロジェクト: adnowak/EcosystemSimulation
        public override void nextRound()
        {
            if (humidity >= Constants.HUMIDITY_DECREASE)
            {
                humidity -= Constants.HUMIDITY_DECREASE;
            }

            if (RandomNumber.Between(0, 1000) <= Constants.RAIN_PROB)
            {
                humidity += Constants.RAIN_HUMIDITY_INCREASE;
            }

            bool neighbourNeighboursWater = false;
            bool neighboursGrass          = false;
            bool neighboursDenseGrass     = false;
            bool neighboursStone          = false;
            int  neighbouringSoils        = 0;

            for (int i = 0; i < Constants.NEIGHBOURS_AMOUNT; i++)
            {
                for (int j = 0; j < Constants.NEIGHBOURS_AMOUNT; j++)
                {
                    if (neighbours[i].getNeighbours()[j].getType() == 3)
                    {
                        neighbourNeighboursWater = true;
                    }
                }

                if (neighbours[i].getType() == 2)
                {
                    neighboursStone = true;
                }

                if (neighbours[i].hasGrass() == true)
                {
                    neighboursGrass = true;
                }

                if (neighbours[i].hasDenseGrass() == true)
                {
                    neighboursDenseGrass = true;
                }

                if (neighbours[i].getType() == 0)
                {
                    neighbouringSoils++;
                }
            }

            if (neighbourNeighboursWater && RandomNumber.Between(0, 1000) <= Constants.SAND_GETS_HUMID_PROB)
            {
                if (humidity < 500)
                {
                    humidity += 500;
                }
                else
                {
                    humidity = 1000;
                }
            }

            if (neighboursWater() && RandomNumber.Between(0, 1000) <= Constants.SAND_GETS_HUMID_PROB)
            {
                humidity = 1000;
            }

            if (RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB)
            {
                grass = true;
            }
            else if (neighboursGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB * Constants.NEIGHBOURING_GRASS_BONUS)
            {
                grass = true;
            }
            else if (neighboursDenseGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB * Constants.NEIGHBOURING_DENSE_GRASS_BONUS)
            {
                grass = true;
            }
            else
            {
                if (humidity < Constants.MIN_HUMIDITY_FOR_MOIST)
                {
                    grass      = false;
                    denseGrass = false;
                }
                else
                {
                    if (grass && !denseGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_DENSES_ON_SAND_PROB)
                    {
                        denseGrass = true;
                    }
                    else if (denseGrass && (neighboursStone || neighbouringSoils >= 1) && neighboursWater() && RandomNumber.Between(0, 1000) <= Constants.TURN_TO_SOIL_PROB)
                    {
                        turnToSoil();
                    }
                    else if (grass && neighbouringSoils >= 2 && humidity >= 500)
                    {
                        turnToSoil();
                    }
                    else if (grass && neighbouringSoils >= 1 && humidity >= 500 && RandomNumber.Between(0, 1000) <= Constants.TURN_TO_SOIL_PROB)
                    {
                        turnToSoil();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: adnowak/EcosystemSimulation
        public Form1()
        {
            InitializeComponent();

            for (int i = 0; i < Constants.MAP_SIZE; i++)
            {
                for (int j = 0; j < Constants.MAP_SIZE; j++)
                {
                    int rand = RandomNumber.Between(0, Constants.FIELD_TYPES_AMOUNT * 100);
                    if (rand < 20)
                    {
                        map[i, j] = new Stone(this, i, j);
                    }
                    else
                    {
                        map[i, j] = new Sand(this, i, j);
                    }

                    display[i, j] = new PictureBox();

                    display[i, j].Size     = new System.Drawing.Size(16, 16);
                    display[i, j].Location = new System.Drawing.Point(i * 16, j * 16);

                    display[i, j].Click += new EventHandler(this.click);//
                }
            }

            for (int xPos = 0; xPos < Constants.MAP_SIZE; xPos++)
            {
                for (int yPos = 0; yPos < Constants.MAP_SIZE; yPos++)
                {
                    int sum = 0;

                    if (xPos > 0 && xPos < Constants.MAP_SIZE - 1)
                    {
                        if (yPos > 0 && yPos < Constants.MAP_SIZE - 1)
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else if (yPos == 0)
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, Constants.MAP_SIZE - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, 0].getZPos());
                        }
                    }
                    else if (xPos == 0)
                    {
                        if (yPos > 0 && yPos < Constants.MAP_SIZE - 1)
                        {
                            sum = sumFour(map[Constants.MAP_SIZE - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else if (yPos == 0)
                        {
                            sum = sumFour(map[Constants.MAP_SIZE - 1, yPos].getZPos(), map[xPos, Constants.MAP_SIZE - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else
                        {
                            sum = sumFour(map[Constants.MAP_SIZE - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[xPos + 1, yPos].getZPos(), map[xPos, 0].getZPos());
                        }
                    }
                    else
                    {
                        if (yPos > 0 && yPos < Constants.MAP_SIZE - 1)
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[0, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else if (yPos == 0)
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, Constants.MAP_SIZE - 1].getZPos(), map[0, yPos].getZPos(), map[xPos, yPos + 1].getZPos());
                        }
                        else
                        {
                            sum = sumFour(map[xPos - 1, yPos].getZPos(), map[xPos, yPos - 1].getZPos(), map[0, yPos].getZPos(), map[xPos, 0].getZPos());
                        }
                    }

                    sum += map[xPos, yPos].getZPos();

                    averageHeight[xPos, yPos] = sum / 5;
                }
            }

            for (int i = 0; i < Constants.MAP_SIZE; i++)
            {
                for (int j = 0; j < Constants.MAP_SIZE; j++)
                {
                    if (averageHeight[i, j] < 39)
                    {
                        map[i, j] = new Water(this, i, j);
                    }
                    map[i, j].setZPos(averageHeight[i, j]);
                }
            }

            runDisplay();

            for (int i = 0; i < Constants.MAP_SIZE; i++)
            {
                for (int j = 0; j < Constants.MAP_SIZE; j++)
                {
                    this.Controls.Add(display[i, j]);
                }
            }

            assignNeighboursToAll();

            for (int i = 0; i < Constants.MAP_SIZE; i++)
            {
                for (int j = 0; j < Constants.MAP_SIZE; j++)
                {
                    display[i, j].Name = map[i, j].toString();
                }
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: adnowak/EcosystemSimulation
        public override void nextRound()
        {
            if (humidity >= Constants.HUMIDITY_DECREASE)
            {
                humidity -= Constants.HUMIDITY_DECREASE;
            }

            if (RandomNumber.Between(0, 1000) <= Constants.RAIN_PROB)
            {
                humidity += Constants.RAIN_HUMIDITY_INCREASE;
            }

            bool neighbourNeighboursWater = false;
            bool neighboursGrass          = false;
            bool neighboursDenseGrass     = false;

            for (int i = 0; i < Constants.NEIGHBOURS_AMOUNT; i++)
            {
                for (int j = 0; j < Constants.NEIGHBOURS_AMOUNT; j++)
                {
                    if (neighbours[i].getNeighbours()[j].getType() == 3)
                    {
                        neighbourNeighboursWater = true;
                    }
                }

                if (neighbours[i].hasGrass() == true)
                {
                    neighboursGrass = true;
                }

                if (neighbours[i].hasDenseGrass() == true)
                {
                    neighboursDenseGrass = true;
                }
            }

            if (neighbourNeighboursWater && RandomNumber.Between(0, 1000) <= Constants.SAND_GETS_HUMID_PROB)
            {
                if (humidity < 500)
                {
                    humidity += 500;
                }
                else
                {
                    humidity = 1000;
                }
            }

            if (neighboursWater() && RandomNumber.Between(0, 1000) <= Constants.SOIL_GETS_HUMID_PROB)
            {
                humidity = 1000;
            }

            if (RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB)
            {
                grass = true;
            }
            else if (neighboursGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB * Constants.NEIGHBOURING_GRASS_BONUS)
            {
                grass = true;
            }
            else if (neighboursDenseGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_GROWS_PROB * Constants.NEIGHBOURING_DENSE_GRASS_BONUS)
            {
                grass = true;
            }
            else if (grass && !denseGrass && RandomNumber.Between(0, 1000) <= Constants.GRASS_DENSES_ON_SOIL_PROB)
            {
                denseGrass = true;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: adnowak/EcosystemSimulation
        public override void nextRound()
        {
            thirst += ((100 * (Constants.MAX_HUMIDITY - locationField.getHumidity())) / Constants.MAX_HUMIDITY);
            hunger += 50;

            /*
             * What should be taken into account:
             * thirst
             * hunger
             * locationField type
             * locationField hasGrass
             * locationField hasDenseGrass
             * locationField humidity
             * locationField areaHumidity (average humidity of locationField and it's neighbours)
             * neighbour0 type
             * neighbour0 hasGrass
             * neighbour0 hasDenseGrass
             * neighbour0 humidity
             * neighbour0 areaHumidity
             * neighbour0 hasAnimal
             * neighbour1 type
             * neighbour1 hasGrass
             * neighbour1 hasDenseGrass
             * neighbour1 humidity
             * neighbour1 areaHumidity
             * neighbour1 hasAnimal
             * neighbour2 type
             * neighbour2 hasGrass
             * neighbour2 hasDenseGrass
             * neighbour2 humidity
             * neighbour2 areaHumidity
             * neighbour2 hasAnimal
             * neighbour3 type
             * neighbour3 hasGrass
             * neighbour3 hasDenseGrass
             * neighbour3 humidity
             * neighbour3 areaHumidity
             * neighbour3 hasAnimal
             */


            int direction = RandomNumber.Between(0, 5);

            switch (direction)
            {
            default:
                stay();
                break;

            case 1:
                if (!locationField.getNorthernNeighbour().hasAnimal() && locationField.getNorthernNeighbour().getType() != 3)
                {
                    moveNorth();
                }
                else
                {
                    stay();
                }
                break;

            case 2:
                if (!locationField.getSouthernNeighbour().hasAnimal() && locationField.getSouthernNeighbour().getType() != 3)
                {
                    moveSouth();
                }
                else
                {
                    stay();
                }
                break;

            case 3:
                if (!locationField.getEasternNeighbour().hasAnimal() && locationField.getEasternNeighbour().getType() != 3)
                {
                    moveEast();
                }
                else
                {
                    stay();
                }
                break;

            case 4:
                if (!locationField.getWesternNeighbour().hasAnimal() && locationField.getWesternNeighbour().getType() != 3)
                {
                    moveWest();
                }
                else
                {
                    stay();
                }
                break;
            }

            if (thirst >= 1000)
            {
                die();
            }
            else if (hunger >= 1000)
            {
                die();
            }
            else
            {
            }
        }