4 Replies - 173 Views - Last Post: 09 February 2020 - 01:29 PM Rate Topic: -----

#1 Yeshuah   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-October 17

A "Population Management" Game

Posted 09 February 2020 - 10:07 AM

Hello! I am building a "Population Management" simulation game using Visual Basic.

I was curious as to what approach i should use in regards to calculating population, individual traits for each person in a population(Name, occupation, age, etc.). The people dont need graphics, as its simply mathematical and displayed with numbers. But lets say I want to start out with 2 people, whats a good way to have the population grow if all requirements are met?(Both have food and water, are opposite sex, etc.) I've never been good with advanced mathematics and I know i will need it here, so and help/advice will be much appreciated!!

Let me know if you need any more information to make a supportive suggestion!

Is This A Good Question/Topic? 0
  • +

Replies To: A "Population Management" Game

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: A "Population Management" Game

Posted 09 February 2020 - 11:21 AM

What sort of mathematics are you thinking you'll need?

I would be more concerned about the class structure, what data needs to be tracked generation to generation (if any), and collections of said class objects.
Was This Post Helpful? 0
  • +
  • -

#3 Yeshuah   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-October 17

Re: A "Population Management" Game

Posted 09 February 2020 - 12:34 PM

Im honestly not sure, I know i need to be able to do at least the following;

Track the total number of people
Track the total numbers for male and female from total population
Each individual "number" acts as a person, with personalized stats(Age, Name, Gender, Occupation, Able to Reproduce, etc.)

I know there is some type of sub or function that will allow me to basically create an array of integers, and apply attributes to each individual integer in that array, but I cannot think of it for some reason.
Was This Post Helpful? 0
  • +
  • -

#4 Yeshuah   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 06-October 17

Re: A "Population Management" Game

Posted 09 February 2020 - 01:25 PM

Do you think this would work? I need to be able to encrypt/decrypt it to/from a .sav file for future use.(Obviously a saving/loading system) and as far as I can see, I can make this work to be writable/read to/from a text file and saved as an encrypted .sav file. Please correct me if I'm wrong. its only worrisome to me, because what if I have a population of 100,000,000,000 people? It seems to me it would make an outrageously large .sav file.

Public Class Intelligence
    Private _name As String
    Private _sex As String
    Private _age As Integer
    'Private mother As Integer
    'Private father As Integer
    'Private ableToReproduce As Boolean
    'Private job As String
    'Private wellness As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Property Sex() As String
        Get
            Return _sex
        End Get
        Set(ByVal value As String)
            _sex = value
        End Set
    End Property

    Public Property Age() As Integer
        Get
            Return _age
        End Get
        Set(value As Integer)
            _age = value
        End Set
    End Property


End Class

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: A "Population Management" Game

Posted 09 February 2020 - 01:29 PM

There's nothing really special about it. It's just counting which, with any given collection, is done in a for loop.


https://docs.microso...ect-initializer

Class Foo
    Public Property Val As String '-- public property to get said value

    Public Sub New() '-- constructor
        Val = String.Empty
    End Sub

End Class


'-- the collection of our class.
        Dim bar As List(Of Foo) = New List(Of Foo)
        bar.Add(New Foo() With {.Val = "a"})
        bar.Add(New Foo() With {.Val = "b"})
        bar.Add(New Foo() With {.Val = "a"})
        bar.Add(New Foo() With {.Val = "a"})
        bar.Add(New Foo() With {.Val = "b"})
        bar.Add(New Foo() With {.Val = "b"})
        bar.Add(New Foo() With {.Val = "b"})

        Dim a_count As Int32 = 0
        Dim b_count As Int32 = 0

        Dim a_count2 As Int32 = 0
        Dim b_count2 As Int32 = 0

'-- Example of just counting objects with a certain property value.
        For Each i As Foo In bar
            If i.Val = "a" Then
                a_count += 1
            End If
        Next

'-- Example of just counting objects with a certain property value.
        For Each i As Foo In bar
            If i.Val = "b" Then
                b_count += 1
            End If
        Next
        Console.WriteLine($"total count: {bar.Count}")
        Console.WriteLine($"a count: {a_count}")
        Console.WriteLine($"b count: {b_count}")
        '------------------
'-- doing the same thing with Linq
        a_count2 = (From x In bar
                    Where x.Val = "a"
                    Select x).Count

        b_count2 = (From x In bar
                    Where x.Val = "b"
                    Select x).Count

        Console.WriteLine($"a count 2: {a_count2}")
        Console.WriteLine($"b count 2: {b_count2}")

'-- getting a distinct types with Linq
        Dim nuts As List(Of String) = (From x In bar
                                       Select x.Val).Distinct.ToList()

        For Each i As String In nuts
            Console.WriteLine($"{i}")
        Next



total count: 7
a count: 3
b count: 4
a count 2: 3
b count 2: 4
a
b

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1