-
Notifications
You must be signed in to change notification settings - Fork 0
Appendix: Hello World Game
Dimitris Kremmydas edited this page Oct 20, 2015
·
4 revisions
-
players choose a number from 1 to 100
-
After all users submit their number, the algorithm of the game is:
a) the average of all selected numbers is calculated (world state var).
b) for each player, the distance from the average is calculated (user state var)
c) for each player the overal score is updated following the formula: score=prev_score+rank
The game finishes after some turns
The definition file for this game is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/ellak-monades-aristeias/simbug/3cbaa7f3d5c065c3ebbaf3866632b62a73219ee9/simbug-server/source/main/java/gr/aua/simbug/definition/definition.xsd">
<Configuration>
</Configuration>
<PlayerChoiceVariables>
<PlayerChoiceVariable>
<Name>numberChoice</Name>
<Type>Integer</Type>
</PlayerChoiceVariable>
</PlayerChoiceVariables>
<PlayerStateVariables>
<PlayerStateVariable>
<Name>roundDistanceFromAverage</Name>
<Type>Float</Type>
</PlayerStateVariable>
<PlayerStateVariable>
<Name>roundRank</Name>
<Type>Integer</Type>
</PlayerStateVariable>
<PlayerStateVariable>
<Name>overallScore</Name>
<Type>Integer</Type>
</PlayerStateVariable>
</PlayerStateVariables>
<WorldStateVariables>
<WorldStateVariable>
<Name>averageAllPlayers</Name>
<Type>Float</Type>
</WorldStateVariable>
</WorldStateVariables>
<ExternalParameters>
</ExternalParameters>
<RandomNumberGenerators>
</RandomNumberGenerators>
<ChoicesToStateAlgorithm>
<![CDATA[
//0. define
RESULTS = new Object();
RESULTS['WorldStateVariables'] = new Object();
RESULTS['PlayerStateVariables'] = new Object();
RESULTS['PlayerStateVariables']['roundDistanceFromAverage'] = new Object();
RESULTS['PlayerStateVariables']['roundRank'] = new Object();
RESULTS['PlayerStateVariables']['overallScore'] = new Object();
//1. calculate average of all players (world level)
sum=0;
for (i = 0; i < INFO['num_players']; i++) {
player_id = INFO['players'][i];
sum = sum + PLAYER_CHOICE_VARIABLES['numberChoice'][player_id][INFO['cur_turn']];
}
avg_all = sum/INFO['num_players'];
RESULTS['WorldStateVariables']['averageAllPlayers'] = avg_all;
//2. calculate distance of each player
distance = new Array(INFO['num_players']);
for (i = 0; i < INFO['num_players']; i++) {
player_id = INFO['players'][i];
distance[i] = Math.abs(avg_all - PLAYER_CHOICE_VARIABLES['numberChoice'][player_id][INFO['cur_turn']]);
RESULTS['PlayerStateVariables']['roundDistanceFromAverage'][player_id] = distance[i];
}
//3. compute rank of each player
rank = new Array(INFO['num_players']);
for (i = 0; i < INFO['num_players']; i++) {rank[i]=i;}
rank.sort(function (a, b) { return distance[a] < distance[b] ? 1 : distance[a] > distance[b] ? -1 : 0; });
for (i = 0; i < INFO['num_players']; i++) {
player_id = INFO['players'][i];
RESULTS['PlayerStateVariables']['roundRank'][player_id] = rank[i];
if(INFO['cur_turn']>0) {
RESULTS['PlayerStateVariables']['overallScore'][player_id] = rank[i] + PLAYER_STATE_VARIABLES['overallScore'][player_id][INFO['cur_turn']-1];
}
else {RESULTS['PlayerStateVariables']['overallScore'][player_id] = rank[i];}
}
]]>
</ChoicesToStateAlgorithm>
</Definition>