winik {villager} | R Documentation |
Winik
Description
This is an object that represents a villager (winik).
Details
This class acts as an abstraction for handling villager-level logic. It can take a number of functions that run at each timestep. It also has an associated
Methods
as_table()
Represents the current state of the winik as a tibble
get_age()
Returns age in terms of years
get_gender()
get_days_sincelast_birth()
Get the number of days since the winik last gave birth
initialize()
Create a new winik
propagate()
Runs every day
Create a new winik
Public fields
identifier
A unique identifier that can be used to identify and find the winik
first_name
The winik's first name
last_name
The winik's last name
age
The winik's age
mother_id
The identifier of the winik's mother
father_id
The identifier of the winik's father
profession
The winik's profession
partner
The identifier of the winik's partner
gender
The winik's gender
alive
A boolean flag that represents whether the villager is alive or dead
children
A list of children identifiers
health
A percentage value of the winik's current health
Methods
Public methods
Method new()
Used to created new winik objects.
Usage
winik$new( identifier = NA, first_name = NA, last_name = NA, age = 0, mother_id = NA, father_id = NA, partner = NA, children = vector(mode = "character"), gender = NA, profession = NA, alive = TRUE, health = 100 )
Arguments
identifier
The winik's identifier
first_name
The winik's first name
last_name
The winik's last naem
age
The age of the winik
mother_id
The identifier of the winik's monther
father_id
The identifier of the winik' father
partner
The identifier of the winik's partner
children
An ordered list of of the children from this winik
gender
The gender of the winik
profession
The winik's profession
alive
Boolean whether the winik is alive or not
health
A percentage value of the winik's current health
Returns
A new winik object A function that returns true or false whether the villager dies This is run each day
Method is_alive()
Usage
winik$is_alive()
Returns
A boolean whether the winik is alive (true for yes) Gets the number of days from the last birth. This is also the age of the most recently born winik
Method get_days_since_last_birth()
Usage
winik$get_days_since_last_birth()
Returns
The number of days since last birth Connects a child to the winik. This method ensures that the 'children' vector is ordered.
Method add_child()
Usage
winik$add_child(child)
Arguments
child
The Winik object representing the child
Returns
None Returns a data.frame representation of the winik
Method as_table()
I hope there's a more scalable way to do this in R; Adding every new attribute to this function isn't practical
Usage
winik$as_table()
Details
The village_state holds a copy of all of the villagers at each timestep; this method is used to turn the winik properties into the object inserted in the village_state.
Returns
A data.frame representation of the winik
Method clone()
The objects of this class are cloneable with this method.
Usage
winik$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.