This article extends the work from article Monopoly #1 - Basic Example for the Visit Frequency of the Fields by considering the go-to-jail directive. In the Monoopoly Board Game there are possibilities for going to jail:
Note that the full code is provided in the attached SAS program. In this article only those code elements are explained that differ from the version shown in the article Monopoly #1 - Basic Example for the Visit Frequency of the Fields.
In the macro variables an additional macro parameter &ConsiderJail is used.
%let cnt_players = 5;
%let cnt_games = 1000;
%let cnt_rounds = 100;
%let ConsiderJail = yes;
%let Doublet3Jail = no;
%let ConsiderChance = no;
%let seed = 1;
%let ScenarioName = "2. Consider Jail";
In the datastep an additional ARRAY "PlayerInJail" is specified. This ARRAY contains the information whether the respective player currently is in jail.
data work.MNP_Sim1(where=(Round ne 0)) ;
format Game Round Player Dice1 Dice2 DiceSum 8.;
ARRAY PlayerPos {&cnt_players.} PlayerPos1 - PlayerPos&cnt_players. ;
ARRAY PlayerInJail {&cnt_players.} PlayerInJail1 - PlayerInJail&cnt_players.;
At the beginning of each game, the value for each player is initialized with 0, meaning the the player is not in jail.
do Game = 1 to &cnt_games;
*** Init-Block;
Round=0; Dice1=.; Dice2=.;
do Player = 1 to &cnt_players;
PlayerPos[Player]=1;
PlayerInJail[Player]=0;
end;
In IF-THEN statement checks, if the player is not in jail.
if PlayerInJail[player]=0 then do;
Dice1 = ceil(rand('Uniform')*6);
Dice2 = ceil(rand('Uniform')*6);
DiceSum = sum(Dice1,Dice2);
if Dice1 = Dice2 then do; ** First Doublet;
output;
Dice1 = ceil(rand('Uniform')*6);
Dice2 = ceil(rand('Uniform')*6);
DiceSum + sum(Dice1,Dice2);
if Dice1 = Dice2 then do; ** Second Doublet;
output;
Dice1 = ceil(rand('Uniform')*6);
Dice2 = ceil(rand('Uniform')*6);
DiceSum + sum(Dice1,Dice2);
end; ** Second Doublet;
end; ** First Doublet;
PlayerPos[Player] + DiceSum;
PlayerPos[Player] = mod(PlayerPos[Player]-1,40)+1;
end;
else PlayerInJail[player] + (-1);
In the next step the macro parameter &ConsiderJail is evaluated.
%if %upcase(&ConsiderJail) = YES %then %do;
if PlayerPos[Player]=31 then do;
PlayerPos[Player] = 11; *** Go to Jail;
PlayerInJail[player]=3;
end;
%end; ** Jail;
The field visit statistics should only show event where a player lands on a certain field. If the player stays in jail, he position will remain the same also in the next round until he can leave the jail. Therefore the occurrence of the "Jail Field" would be overrepresented by considering not only the "landing" on this field, but also staying at this field. Therefore the PlayerPos value is set to MISSING if the player is already in jail (and did not land there in this round).
data work.MNP_Sim1_LastRec;
set work.MNP_Sim1;
by Game Round Player;
drop dice1 dice2 dicesum;
*** Set Location to MISSING, if Player is in Jail to avoid double/triple counting;
ARRAY PlayerPos {&cnt_players.} PlayerPos1 - PlayerPos&cnt_players. ;
ARRAY PlayerInJail {&cnt_players.} PlayerInJail1 - PlayerInJail&cnt_players.;
do Player = 1 to &cnt_players;
if PlayerInJail[Player] then PlayerPos[Player]=.;
end;
*** Keep only last record per round;
if last.round then output;
run;
proc sgplot data=work.player_location;
title Scenario: &scenarioname.;
histogram value / binstart=1 binwidth=1;
yaxis max = 6 label = "Proportion of Visits (%)";
xaxis label = "Field Number";
run;
title;
When you plot the visit distribution using the SGPLOT procedure, you see the following results.
The following video has been recorded for the SAS ask-the-expert session on Monopoly simulations which I used to talk about them in the session.
%let ConsiderJail = yes;
%let Doublet3Jail = yes;
%let ConsiderChance = no;
%let seed = 1;
%let ScenarioName = "3. Consider Jail and 3Doublet";
if Dice1 = Dice2 then do; ** First Doublet;
output;
Dice1 = ceil(rand('Uniform')*6);
Dice2 = ceil(rand('Uniform')*6);
DiceSum + sum(Dice1,Dice2);
if Dice1 = Dice2 then do; ** Second Doublet;
output;
Dice1 = ceil(rand('Uniform')*6);
Dice2 = ceil(rand('Uniform')*6);
DiceSum + sum(Dice1,Dice2);
%if %upcase(&doublet3jail.) = YES %then %do;
if Dice1 = Dice2 then do; ** Third Doublet;
PlayerInJail[player]=3;
PlayerPos[Player]=31;
end; ** Third Doublet;
%end;
end; ** Second Doublet;
end; ** First Doublet;
if PlayerInJail[player] ne 3 then do; ** was just sent to jail, do not move forward;
PlayerPos[Player] + DiceSum;
PlayerPos[Player] = mod(PlayerPos[Player]-1,40)+1;
end; ** PlayerJail Check = 0;
end;
else PlayerInJail[player] + (-1);
The following video has been recorded for the SAS ask-the-expert session on Monopoly simulations which I used to talk about them in the session.
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.