Skip to content

Introducing a new Decision

MFHolm edited this page Jan 31, 2018 · 2 revisions

A new decision can be introduced by adding it to the scenario in index.ts. In the default scenario there are four decisions: Heating subsidies and renewable investments for respectively EAST and WEST. A decision is created using the constructor of Decision.ts. A new example decision has been created to illustrate how this is done. The code below shows the new decision. The decision is created as a pair, one for each of the roles EAST and WEST.

var newDecision1 = new Decision("newDec1", "New Decision", 0, 0, 100, "D", "New decision description");
var newDecision2 = new Decision("newDec2", "New Decision", 0, 0, 100, "D", "New decision description");

The code below shows the arguments of the constructor of Decision.

constructor(p_id, p_name, p_value, p_minValue, p_maxValue, p_unit, p_description)

For this decision the ids are "newDec1" and "newDec2", the name is "New Decision", the initial value is 0, the minimum value is 0, the maximum value is 100, the unit is “D” and the description is “New decision description”. When the roles are created it is defined which decisions they each have access to. The code below shows how role EAST is created. To give participants access to your new decision you need to add it to the decision list of at least one of the roles. In this example newDecision1 should be added to role1 and newDecision2 should be added to role2.

var role1: Role = new Role("East", [dec1, dec2], [ind2, ind3, ind4], 'AA3939');

After the new decision has been added to the role should look like this:

var role1: Role = new Role("East", [dec1, dec2, newDecision1], [ind2, ind3, ind4], 'AA3939');

By doing this the new decision has been created and is visible to the chosen role, but it does not yet influence the indicators. To add the value of this decision to the game logic some modifications of the files in gameLogic is required. First the new decision must be added to decision.ts. Decision is an abstract class and the new decision only needs to be an empty class that extends this class in the same way as the two original decisions. The code below shows this. This can be found in the bottom of the file decision.ts.

export class NewDecision extends Decision {

}

Afterwards the new decision needs to be added to mainGameLogic.ts. First a new array needs to be introduced for the values of the new decision. To do this the new decision needs to be imported from the decision file using the code below.

import { EnergySubsidies, InvestmentInRenewables, NewDecision } from './decision';

Then the new array can be created:

private newDecision: Array<NewDecision> = [];

The new decision array needs to be initialized in the same way as the other decisions in the constructor of GameLogic using:

this.newDecision.push(new NewDecision(organizationID));

The new decision also needs to be added to the ResetWorld() function by adding

this.newDecision[organizationID].reset(); 

to the loop and setting the initial values by adding:

 this.newDecision[0].decisionValuePush = 0;
 this.newDecision[1].decisionValuePush = 0;

Now the value of the new decision needs to be added to the game logic. This is done using the CalculateMonthValues function. First we need to add a new argument for the new decision. Then the value of the new decision needs to be added using the code below:

this.newDecision[orgID].decisionValuePush = aNewDecision[orgID];

The CalculateMonthValues function is invoked from the function executeTick in ModelDev.ts and the value of the new decision needs to be added as an argument to CalculateMonthValues here. Below it is shown how the value of the new decision is added.

this.m_currentScenario.getGameLogic().CalculateMonthValues(this.m_time, this.m_time, [dec.East.SubEast, dec.West.SubWest], [dec.East.ResEast, dec.West.ResWest], [dec.East.newDec1, dec.West.newDec2]);

Finally to make this decision influence the indicators this needs to be added in availableData.ts. In this example we will show how this decision could influence GDP. First the new decision needs to be imported the same way as in mainGameLogic.ts. Then the new decision must be added as an argument to CalculateValue of GDP. The code below shows an example of how the new decision could influence the GDP.

let gdpValue = gdpLastMonth * (1 + newDecisionLastMonth * this.newDecisionImpactOnNextYearGDP
+ investmentInRenewableLastMonth * this.renewInvestImpactOnNextYearsGDP
+ (sixMonthMinComfort - this.sixMonthMinComfortImpactOnGDPthreshold) * this.sixMonthMinComfortImpactOnGDP)
* (1 + this.defaultGrowth);

In this example a new constant has also been created:

private newDecisionImpactOnNextYearGDP: number = -0.000025;

CalculateValue is invoked from CalculateMonthValues in mainGameLogic.ts and the hence the value of the new decision needs to be added as an argument to CalculateValue here as well. The code below shows how this is done.

this.gdpPerPerson[orgID].CalculateValue(month, this.energySubsidies[orgID], this.investmentInRenewables[orgID], this.comfortableHousingTemperature[orgID], this.newDecision[orgID]);

The new decision has now been created and is usable for participants. You are encouraged to update the welcome message in WelcomeDialog.ts to include an explanation of the new decision.

The code that has been created for this example is included in the source code and is ready for you to fill in your own new decision. Some of the code has been commented out to prevent it from influencing the game before a new decision has been created.