Example #1
0
 public static FogShip createFromGen( float[] gen, DynamicConfig config )
 {
     FogShip rlt = new FogShip( );
     rlt.isAlive = true;
     // * Create ship attributes from gens
     // # A gens varies from 0 to 99
     rlt.energy = gen[0];
     rlt.attack = gen[1];
     rlt.reproduction = gen[2];
     rlt.speed = gen[3];
     rlt.size = gen[4];
     rlt.aggressive = gen[5];
     rlt.energy_gain = gen[6];
     rlt.energy_capacity = gen[7];
     // * Save the gen and config.
     rlt.gen = gen;
     FogShip.config = config;
     // * Create a name of the ship according to its gen
     // # Each name letter represents a gen approximate value
     // # A name letter varies from A to F
     rlt.name = "";
     foreach ( float g in gen )
         rlt.name += generateNameChar( g );
     return rlt;
 }
 public static DynamicConfig generate( int _seed )
 {
     DynamicConfig config = new DynamicConfig( );
     config.seed = _seed;
     Random r = new Random( config.seed );
     config.chance_of_0_19_event = r.Next( 20 );
     config.chance_of_0_19_encounter = r.Next( 20 );
     config.chance_of_aggressive_limit_0_100_a = r.Next( 101 );
     config.chance_of_aggressive_limit_0_100_b = r.Next( 101 );
     config.scale_log_e_of_1_100_attack_success = Math.Log( r.Next( 100 ) ) + 1;
     config.scale_demi_of_01_2_energy_drain_a = ((float)r.Next( 201 )) / 100.0f;
     config.scale_demi_of_01_2_energy_drain_a = ((float)r.Next( 201 )) / 100.0f;
     config.scale_demi_of_01_1_energy_gain = ((float)r.Next( 101 )) / 100.0f;
     config.scale_demi_of_01_1_reproduce_intent_a = ((float)r.Next( 101 )) / 100.0f;
     config.scale_demi_of_01_1_reproduce_intent_b = ((float)r.Next( 101 )) / 100.0f;
     config.scale_demi_of_01_1_chance_gen_of_a = ((float)r.Next( 101 )) / 100.0f;
     config.scale_demi_of_01_1_percentage_genergy_cost_a = ((float)r.Next( 101 )) / 100.0f;
     config.scale_demi_of_01_1_percentage_genergy_cost_b = 1 - config.scale_demi_of_01_1_percentage_genergy_cost_a;
     config.scale_log_e_of_0_100_wandering_gain = (float)Math.Log( r.Next( 101 ) );
     config.chance_of_0_100_pass_lost = r.Next( 101 );
     return config;
 }
Example #3
0
        public void run( int _seed )
        {
            seed = _seed;
            List<FogShip> shipList = new List<FogShip>( );
            config = DynamicConfig.generate( seed );
            // * Initialize limits
            int timeCount = 1000;
            int shipCount = 1000;
            int shipMax = 10000;
            int scaleSize = 100;
            int currentYear = 0;

            // * Generate ships
            for ( int i = 0; i < shipCount; i++ )
            {
                FogShip newShip = FogShip.createFromGen( new float[] {
                    RandomEx.r.Next(scaleSize), RandomEx.r.Next(scaleSize),
                    RandomEx.r.Next(scaleSize), RandomEx.r.Next(scaleSize),
                    RandomEx.r.Next(scaleSize), RandomEx.r.Next(scaleSize),
                    RandomEx.r.Next(scaleSize), RandomEx.r.Next(scaleSize)
                }, config );
                shipList.Add( newShip );
            }

            // * Run simulation
            for ( int i = 0; i < timeCount; i++ )
            {
                // {} Loop through ships
                foreach ( FogShip ship in shipList )
                {
                    // ? Check whether the unit is still alive
                    if ( ship.isAlive == false )
                        continue;
                    // * Chance for an event!
                    int dice20 = RandomEx.r.Next( 20 ) + 1;
                    // ? Chance for event or wandering
                    if ( dice20 >= config.chance_of_0_19_event )
                    {
                        // * Get a random ship B
                        FogShip B = shipList[RandomEx.r.Next( shipList.Count )];
                        // ? Chance for encounter or reproduce
                        if ( RandomEx.r.Next( 20 ) > config.chance_of_0_19_encounter )	// 50%
                            FogShip.encounter( ship, B );
                        else
                            FogShip.reproduce( ship, B );
                    }
                    else FogShip.wandering( ship );
                    // * Time pass!
                    FogShip.timePass( ship );
                }
                // * Remove dead ships
                shipList.RemoveAll( ship => ship.isAlive == false );
                // [] Debug outputs
                Console.Clear( );
                Console.WriteLine( i + "|" + shipList.Count );
                Console.WriteLine( i + "|" + shipList.Count );
                Console.WriteLine( i + "|" + shipList.Count );
                currentYear = i;
                // [] Time to stop debuging
                if ( shipList.Count < 10 || shipList.Count > shipMax )
                    break;
            }

            // * A list of ships that still remain on the battle field.
            rlt_remainList = new Dictionary<string, List<FogShip>>( );
            // [] Time to stop debuging
            Console.Clear( );
            Console.WriteLine( "" );
            Console.WriteLine( "" );
            Console.WriteLine( "" );
            Console.WriteLine( "" );
            Console.WriteLine( "" );
            // * Set up the result set
            // {} Loop through remained shiped
            foreach ( FogShip ship in shipList )
            {
                // [] Output remained ship's name and energy.
                Console.Write( ship.name + "|" + ship.energy + ", " );
                // ? Check if it's the same type of ship.
                if ( rlt_remainList.ContainsKey( ship.name ) )
                {
                    // * Add them together, if it is.
                    rlt_remainList[ship.name].Add( ship );
                }
                else
                {
                    // * Create a new list if it's not
                    List<FogShip> newList = new List<FogShip>( );
                    newList.Add( ship );
                    rlt_remainList.Add( ship.name, newList );
                }
            }
            // * Set up general result information
            rlt_endYear = currentYear;
            rlt_shipCount = shipList.Count;
            // [] Print the end year and total ship count
            Console.WriteLine( "" );
            Console.WriteLine( "" );
            Console.WriteLine( "Year: " + rlt_endYear );
            Console.WriteLine( "Alive: " + rlt_shipCount );
            // [] Print general ship types and counts.
            foreach ( var pair in rlt_remainList )
            {
                Console.Write( pair.Key + "|" + pair.Value.Count + ", " );
            }
        }