Commit 5c2ded6ecd68b79a5e5a2e6fa4a0d378babc0146

Authored by Carlos Picanco
1 parent f174c320
Exists in master

experiment runner - load and save configuration files

units/game_actors.pas
@@ -96,18 +96,19 @@ type @@ -96,18 +96,19 @@ type
96 FAppendiceLossSingular, 96 FAppendiceLossSingular,
97 FAppendiceEarnPlural, 97 FAppendiceEarnPlural,
98 FAppendiceEarnSingular, 98 FAppendiceEarnSingular,
99 - FNicname: string; 99 + FPrepend: string;
100 FStyle : TConsequenceStyle; 100 FStyle : TConsequenceStyle;
101 FP : TGamePoint; 101 FP : TGamePoint;
102 FTimer : TTimer; 102 FTimer : TTimer;
103 FMessage : TPopupNotifier; 103 FMessage : TPopupNotifier;
  104 + function GetCsqString: string;
104 function GetShouldPublishMessage: Boolean; 105 function GetShouldPublishMessage: Boolean;
105 protected 106 protected
106 FConsequenceByPlayerID : TStringList; 107 FConsequenceByPlayerID : TStringList;
107 procedure StopTimer(Sender:TObject;var ACloseAction:TCloseAction); 108 procedure StopTimer(Sender:TObject;var ACloseAction:TCloseAction);
108 procedure SelfDestroy(Sender:TOBject);virtual; 109 procedure SelfDestroy(Sender:TOBject);virtual;
109 public 110 public
110 - constructor Create(AOwner:TComponent; ACsqString, ANicname, 111 + constructor Create(AOwner:TComponent; ACsqString, APrepend,
111 APrependLoss,AAppendiceLossSingular,AAppendiceLossPlural, 112 APrependLoss,AAppendiceLossSingular,AAppendiceLossPlural,
112 APrependEarn,AAppendiceEarnSingular,AAppendiceEarnPlural,AAppendiceZero:string);overload; 113 APrependEarn,AAppendiceEarnSingular,AAppendiceEarnPlural,AAppendiceZero:string);overload;
113 constructor Create(AOwner:TComponent; AP:integer; AStyle: TConsequenceStyle; AMessage:array of string);overload; 114 constructor Create(AOwner:TComponent; AP:integer; AStyle: TConsequenceStyle; AMessage:array of string);overload;
@@ -120,7 +121,7 @@ type @@ -120,7 +121,7 @@ type
120 procedure PresentPoints(A, B, I, G : TLabel); 121 procedure PresentPoints(A, B, I, G : TLabel);
121 procedure PresentPoints(APlayerBox: TPlayerBox; G: TLabel); overload; 122 procedure PresentPoints(APlayerBox: TPlayerBox; G: TLabel); overload;
122 property ShouldPublishMessage : Boolean read GetShouldPublishMessage; 123 property ShouldPublishMessage : Boolean read GetShouldPublishMessage;
123 - property PlayerNicname : string read FNicname write FNicname; 124 + property Prepend : string read FPrepend;
124 property AppendiceLossSingular : string read FAppendiceLossSingular; 125 property AppendiceLossSingular : string read FAppendiceLossSingular;
125 property AppendiceLossPlural : string read FAppendiceLossPlural; 126 property AppendiceLossPlural : string read FAppendiceLossPlural;
126 property AppendiceEarnSingular : string read FAppendiceEarnSingular; 127 property AppendiceEarnSingular : string read FAppendiceEarnSingular;
@@ -128,6 +129,7 @@ type @@ -128,6 +129,7 @@ type
128 property AppendiceZero : string read FAppendiceZero; 129 property AppendiceZero : string read FAppendiceZero;
129 property PrependLoss : string read FPrependLoss; 130 property PrependLoss : string read FPrependLoss;
130 property PrependEarn : string read FPrependEarn; 131 property PrependEarn : string read FPrependEarn;
  132 + property CsqString : string read GetCsqString;
131 property Style : TConsequenceStyle read FStyle; 133 property Style : TConsequenceStyle read FStyle;
132 property ConsequenseByPlayerID : TStringList read FConsequenceByPlayerID; 134 property ConsequenseByPlayerID : TStringList read FConsequenceByPlayerID;
133 end; 135 end;
@@ -184,6 +186,7 @@ type @@ -184,6 +186,7 @@ type
184 procedure Clean;override; 186 procedure Clean;override;
185 property Question: string read FPromptMessage; 187 property Question: string read FPromptMessage;
186 property PromptResult:string read FResult; 188 property PromptResult:string read FResult;
  189 + property PromptStyle : TPromptStyle read FPromptStyle;
187 190
188 end; 191 end;
189 192
@@ -582,7 +585,7 @@ end; @@ -582,7 +585,7 @@ end;
582 585
583 { TConsequence } 586 { TConsequence }
584 587
585 -constructor TConsequence.Create(AOwner: TComponent; ACsqString, ANicname, 588 +constructor TConsequence.Create(AOwner: TComponent; ACsqString, APrepend,
586 APrependLoss, AAppendiceLossSingular, AAppendiceLossPlural, APrependEarn, 589 APrependLoss, AAppendiceLossSingular, AAppendiceLossPlural, APrependEarn,
587 AAppendiceEarnSingular, AAppendiceEarnPlural, AAppendiceZero: string); 590 AAppendiceEarnSingular, AAppendiceEarnPlural, AAppendiceZero: string);
588 var 591 var
@@ -591,7 +594,7 @@ begin @@ -591,7 +594,7 @@ begin
591 inherited Create(AOwner); 594 inherited Create(AOwner);
592 595
593 // custom message 596 // custom message
594 - FNicname:=ANicname; 597 + FPrepend:=APrepend;
595 FPrependLoss:=APrependLoss; 598 FPrependLoss:=APrependLoss;
596 FAppendiceLossSingular:=AAppendiceLossSingular; 599 FAppendiceLossSingular:=AAppendiceLossSingular;
597 FAppendiceLossPlural:=AAppendiceLossPlural; 600 FAppendiceLossPlural:=AAppendiceLossPlural;
@@ -619,7 +622,7 @@ begin @@ -619,7 +622,7 @@ begin
619 inherited Create(AOwner); 622 inherited Create(AOwner);
620 FP := TGamePoint.Create(AOwner,AP); 623 FP := TGamePoint.Create(AOwner,AP);
621 FStyle:=AStyle; 624 FStyle:=AStyle;
622 - FNicname:=AMessage[0]; 625 + FPrepend:=AMessage[0];
623 FPrependLoss:=AMessage[1]; 626 FPrependLoss:=AMessage[1];
624 FAppendiceLossSingular:=AMessage[2]; 627 FAppendiceLossSingular:=AMessage[2];
625 FAppendiceLossPlural:=AMessage[3]; 628 FAppendiceLossPlural:=AMessage[3];
@@ -637,7 +640,7 @@ begin @@ -637,7 +640,7 @@ begin
637 inherited Create(AOwner); 640 inherited Create(AOwner);
638 FP := TGamePoint.Create(AOwner,ExtractDelimited(1,AConsequenceString,['|'])); 641 FP := TGamePoint.Create(AOwner,ExtractDelimited(1,AConsequenceString,['|']));
639 FStyle:=GetConsequenceStyleFromString(ExtractDelimited(2,AConsequenceString,['|'])); 642 FStyle:=GetConsequenceStyleFromString(ExtractDelimited(2,AConsequenceString,['|']));
640 - FNicname:=ExtractDelimited(3,AConsequenceString,['|']); 643 + FPrepend:=ExtractDelimited(3,AConsequenceString,['|']);
641 FPrependLoss:=ExtractDelimited(4,AConsequenceString,['|']); 644 FPrependLoss:=ExtractDelimited(4,AConsequenceString,['|']);
642 FAppendiceLossSingular:=ExtractDelimited(5,AConsequenceString,['|']); 645 FAppendiceLossSingular:=ExtractDelimited(5,AConsequenceString,['|']);
643 FAppendiceLossPlural:=ExtractDelimited(6,AConsequenceString,['|']); 646 FAppendiceLossPlural:=ExtractDelimited(6,AConsequenceString,['|']);
@@ -664,7 +667,7 @@ function TConsequence.AsString(AID: string): string; @@ -664,7 +667,7 @@ function TConsequence.AsString(AID: string): string;
664 begin 667 begin
665 Result := IntToStr(FP.ValueWithVariation) + '|'; 668 Result := IntToStr(FP.ValueWithVariation) + '|';
666 Result += GetConsequenceStyleString(FStyle)+'|'; 669 Result += GetConsequenceStyleString(FStyle)+'|';
667 - Result += FNicname +'|'; 670 + Result += FPrepend +'|';
668 Result += FPrependLoss + '|'; 671 Result += FPrependLoss + '|';
669 Result += FAppendiceLossSingular + '|'; 672 Result += FAppendiceLossSingular + '|';
670 Result += FAppendiceLossPlural + '|'; 673 Result += FAppendiceLossPlural + '|';
@@ -678,7 +681,7 @@ end; @@ -678,7 +681,7 @@ end;
678 681
679 function TConsequence.GenerateMessage(ForGroup: Boolean): string; 682 function TConsequence.GenerateMessage(ForGroup: Boolean): string;
680 begin 683 begin
681 - Result := FP.PointMessage(FNicname,FPrependLoss,FAppendiceLossSingular,FAppendiceLossPlural, 684 + Result := FP.PointMessage(FPrepend,FPrependLoss,FAppendiceLossSingular,FAppendiceLossPlural,
682 FPrependEarn,FAppendiceEarnSingular,FAppendiceEarnPlural,FAppendiceZero, ForGroup); 685 FPrependEarn,FAppendiceEarnSingular,FAppendiceEarnPlural,FAppendiceZero, ForGroup);
683 FMessage.Text := Result; 686 FMessage.Text := Result;
684 end; 687 end;
@@ -738,6 +741,12 @@ begin @@ -738,6 +741,12 @@ begin
738 Result := gscBroadcastMessage in FStyle; 741 Result := gscBroadcastMessage in FStyle;
739 end; 742 end;
740 743
  744 +function TConsequence.GetCsqString: string;
  745 +begin
  746 + Result := IntToStr(FP.Value)+','+IntToStr(FP.Variation) + '|';
  747 + Result += GetConsequenceStyleString(FStyle);
  748 +end;
  749 +
741 procedure TConsequence.StopTimer(Sender: TObject; var ACloseAction: TCloseAction 750 procedure TConsequence.StopTimer(Sender: TObject; var ACloseAction: TCloseAction
742 ); 751 );
743 begin 752 begin
units/game_actors_point.pas
@@ -35,7 +35,8 @@ type @@ -35,7 +35,8 @@ type
35 function PointMessage(APrepend, APrependLoss, AAppendiceLossSingular,AAppendiceLossPlural, 35 function PointMessage(APrepend, APrependLoss, AAppendiceLossSingular,AAppendiceLossPlural,
36 APrependEarn,AAppendiceEarnSingular,AAppendiceEarnPlural,AAppendiceZero: string; IsGroupPoint: Boolean) : string; 36 APrependEarn,AAppendiceEarnSingular,AAppendiceEarnPlural,AAppendiceZero: string; IsGroupPoint: Boolean) : string;
37 property ValueWithVariation : integer read GetValue write FValue; 37 property ValueWithVariation : integer read GetValue write FValue;
38 - property Variation : integer read FVariation write FVariation; 38 + property Value : integer read FValue;
  39 + property Variation : integer read FVariation;
39 property AsString : string read GetResultAsString; 40 property AsString : string read GetResultAsString;
40 property ResultAsInteger : integer read GetResult; 41 property ResultAsInteger : integer read GetResult;
41 end; 42 end;
units/game_experiment.pas
@@ -46,7 +46,7 @@ type @@ -46,7 +46,7 @@ type
46 FShowChat: Boolean; 46 FShowChat: Boolean;
47 FMatrixType: TGameMatrixType; 47 FMatrixType: TGameMatrixType;
48 private 48 private
49 - FAppPath, 49 + FExperimentPath,
50 FLastReportColNames : string; 50 FLastReportColNames : string;
51 FRegData : TRegData; 51 FRegData : TRegData;
52 FRegChat : TRegData; 52 FRegChat : TRegData;
@@ -719,7 +719,7 @@ var @@ -719,7 +719,7 @@ var
719 c,i: integer; 719 c,i: integer;
720 LRow : string; 720 LRow : string;
721 begin 721 begin
722 - if Assigned(FRegData) then 722 + if Assigned(FRegData) and Assigned(Condition[c].Prompt) then
723 begin 723 begin
724 c := CurrentCondition; 724 c := CurrentCondition;
725 LRow := ''; 725 LRow := '';
@@ -750,15 +750,13 @@ constructor TExperiment.Create(AOwner: TComponent); @@ -750,15 +750,13 @@ constructor TExperiment.Create(AOwner: TComponent);
750 begin 750 begin
751 inherited Create(AOwner); 751 inherited Create(AOwner);
752 FTurnsRandom := TStringList.Create; 752 FTurnsRandom := TStringList.Create;
753 - LoadExperimentFromResource(Self);  
754 - CheckNeedForRandomTurns;  
755 end; 753 end;
756 754
757 constructor TExperiment.Create(AOwner: TComponent;AppPath:string); 755 constructor TExperiment.Create(AOwner: TComponent;AppPath:string);
758 var LDataPath : string; 756 var LDataPath : string;
759 begin 757 begin
760 inherited Create(AOwner); 758 inherited Create(AOwner);
761 - FAppPath := AppPath; 759 + FExperimentPath := AppPath;
762 FTurnsRandom := TStringList.Create; 760 FTurnsRandom := TStringList.Create;
763 //LoadExperimentFromResource(Self); 761 //LoadExperimentFromResource(Self);
764 //LDataPath := AppPath+VAL_RESEARCHER+'es'+PathDelim+Researcher+PathDelim+ExperimentName+PathDelim; 762 //LDataPath := AppPath+VAL_RESEARCHER+'es'+PathDelim+Researcher+PathDelim+ExperimentName+PathDelim;
@@ -804,8 +802,8 @@ begin @@ -804,8 +802,8 @@ begin
804 if Result then 802 if Result then
805 FFilename := AFilename 803 FFilename := AFilename
806 else Exit; 804 else Exit;
807 -  
808 - LDataPath := FAppPath+VAL_RESEARCHER+'es'+PathDelim+Researcher+PathDelim+ExperimentName+PathDelim; 805 + FExperimentPath := ExtractFilePath(FFilename);
  806 + LDataPath := FExperimentPath+ExperimentName+PathDelim;
809 807
810 SetTargetInterlockingEvent; 808 SetTargetInterlockingEvent;
811 SetContingenciesEvents; 809 SetContingenciesEvents;
@@ -816,7 +814,7 @@ begin @@ -816,7 +814,7 @@ begin
816 FReportReader.UseRange:=True; 814 FReportReader.UseRange:=True;
817 FReportReader.SetXLastRows(Condition[CurrentCondition].EndCriterium.LastCycles); 815 FReportReader.SetXLastRows(Condition[CurrentCondition].EndCriterium.LastCycles);
818 816
819 - FRegData := TRegData.Create(Self, LDataPath+'000.dat'); 817 + FRegData := TRegData.Create(Self, LDataPath+'000.data');
820 FRegChat := TRegData.Create(Self, LDataPath+'000.chat'); 818 FRegChat := TRegData.Create(Self, LDataPath+'000.chat');
821 WriteReportHeader; 819 WriteReportHeader;
822 end; 820 end;
@@ -943,7 +941,8 @@ begin @@ -943,7 +941,8 @@ begin
943 for i := 0 to ContingenciesCount[c]-1 do 941 for i := 0 to ContingenciesCount[c]-1 do
944 Contingency[c,i].Clean; 942 Contingency[c,i].Clean;
945 943
946 - Condition[c].Prompt.Clean; 944 + if Assigned(Condition[c].Prompt) then
  945 + Condition[c].Prompt.Clean;
947 946
948 FRegData.CloseAndOpen; 947 FRegData.CloseAndOpen;
949 end; 948 end;
units/game_file_methods.pas
@@ -20,7 +20,7 @@ uses @@ -20,7 +20,7 @@ uses
20 20
21 21
22 function LoadExperimentFromResource(var AExperiment: TExperiment):Boolean; 22 function LoadExperimentFromResource(var AExperiment: TExperiment):Boolean;
23 - function LoadExperimentFromFile(var AExperiment: TExperiment; AFilename : string):Boolean; 23 + function LoadExperimentFromFile(AExperiment: TExperiment; AFilename : string):Boolean;
24 procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename : string); 24 procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename : string);
25 25
26 resourcestring 26 resourcestring
@@ -145,7 +145,7 @@ begin @@ -145,7 +145,7 @@ begin
145 end; 145 end;
146 end; 146 end;
147 147
148 -function LoadExperimentFromFile(var AExperiment: TExperiment; AFilename: string):Boolean; 148 +function LoadExperimentFromFile(AExperiment: TExperiment; AFilename: string):Boolean;
149 var 149 var
150 LIniFile : TIniFile; 150 LIniFile : TIniFile;
151 i: Integer; 151 i: Integer;
@@ -181,67 +181,76 @@ var @@ -181,67 +181,76 @@ var
181 end; 181 end;
182 end; 182 end;
183 183
184 - procedure ReadContingencies(ACondition:integer;IsMeta : Boolean); 184 + function ReadContingenciesCount(ACondition: integer;LC_KEY:String):integer;
185 var 185 var
186 - i : integer;  
187 - LS,LCK : string;  
188 - LConsequence : TConsequence;  
189 - LCriteria:TCriteria;  
190 -  
191 - procedure SetLCK(i:integer);  
192 - begin  
193 - if IsMeta then  
194 - LCK := KEY_METACONTINGENCY+IntToStr(i+1)  
195 - else  
196 - LCK := KEY_CONTINGENCY+IntToStr(i+1);  
197 - end; 186 + LCK, LS: String;
198 begin 187 begin
  188 + Result := 0;
199 LS := SEC_CONDITION+IntToStr(ACondition+1); 189 LS := SEC_CONDITION+IntToStr(ACondition+1);
200 - i := AExperiment.AppendContingency(ACondition);  
201 - SetLCK(i); 190 + LCK := LC_KEY+IntToStr(Result+1);
202 with LIniFile do 191 with LIniFile do
203 - while ValueExists(LS, LCK+KEY_CONSEQUE) and ValueExists(LS, LCK+KEY_CRITERIA)do 192 + while ValueExists(LS, LCK+KEY_CONT_NAME) and ValueExists(LS, LCK+KEY_CONSEQUE) and ValueExists(LS, LCK+KEY_CRITERIA)do
204 begin 193 begin
205 - AExperiment.Condition[ACondition].Contingencies[i].ContingencyName := ReadString(LS, LCK+KEY_CONT_NAME, '');  
206 - ReadString(LS, LCK+KEY_CONSEQUE, '');  
207 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND,'');  
208 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND_LOSS,'');  
209 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_S,'');  
210 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_P,'');  
211 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND_EARN,'');  
212 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_S,'');  
213 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_P,'');  
214 - ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_ZERO, '');  
215 -  
216 -  
217 - LConsequence := TConsequence.Create(AExperiment,  
218 - ReadString(LS,LCK+KEY_CONSEQUE,DEF_CONSEQUENCE));  
219 - LCriteria := GetCriteriaFromString(ReadString(LS, LCK+KEY_CRITERIA, ''));  
220 - AExperiment.Condition[ACondition].Contingencies[i] := TContingency.Create(AExperiment,LConsequence,LCriteria,IsMeta);  
221 - i := AExperiment.AppendContingency(ACondition);  
222 - SetLCK(i); 194 + Inc(Result);
  195 + LCK := LC_KEY+IntToStr(Result+1);
223 end; 196 end;
224 end; 197 end;
225 198
  199 + function ReadContingency(AConditionIndex:integer; LCK:string) : TContingency;
  200 + var
  201 + LS : string;
  202 + LConsequence : TConsequence;
  203 + LCriteria:TCriteria;
  204 +
  205 + begin
  206 + LS := SEC_CONDITION+IntToStr(AConditionIndex+1);
  207 + with LIniFile do
  208 + begin
  209 + LConsequence := TConsequence.Create(AExperiment,
  210 + ReadString(LS, LCK+KEY_CONSEQUE, ''),
  211 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND,''),
  212 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND_LOSS,''),
  213 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_S,''),
  214 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_P,''),
  215 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_PREPEND_EARN,''),
  216 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_S,''),
  217 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_P,''),
  218 + ReadString(LS, LCK+KEY_CONSEQUE_MESSAGE_APPEND_ZERO, '')
  219 + );
  220 +
  221 + LCriteria := GetCriteriaFromString(ReadString(LS, LCK+KEY_CRITERIA, ''));
  222 + end;
  223 + Result := TContingency.Create(AExperiment,LConsequence,LCriteria,Pos(KEY_METACONTINGENCY,LCK)>0);
  224 + end;
  225 +
226 procedure ReadConditions; 226 procedure ReadConditions;
227 var 227 var
228 - s1, LS : string;  
229 - i : integer; 228 + s1, LS , LPromptStyle, LPromptMessa: string;
  229 + i,j , LContingenciesCount, LMetaContingenCount: integer;
230 C :TCondition; 230 C :TCondition;
231 begin 231 begin
232 - //i := 0;  
233 - i := AExperiment.AppendCondition; 232 + i := 0;
234 LS := SEC_CONDITION+IntToStr(i+1); 233 LS := SEC_CONDITION+IntToStr(i+1);
235 with LIniFile do 234 with LIniFile do
236 while SectionExists(LS) do 235 while SectionExists(LS) do
237 begin 236 begin
238 - //if i = 0 then  
239 - // i := AExperiment.AppendCondition;  
240 with C do 237 with C do
241 begin 238 begin
242 ConditionName := ReadString(LS,KEY_COND_NAME,LS); 239 ConditionName := ReadString(LS,KEY_COND_NAME,LS);
243 Points.Count := GetPointsFromString(ReadString(LS, KEY_POINTS_COUNT,DEF_POINTS)); 240 Points.Count := GetPointsFromString(ReadString(LS, KEY_POINTS_COUNT,DEF_POINTS));
244 - Points.OnStart := GetPointsFromString(ReadString(LS, KEY_POINTS_ONSTART,DEF_POINTS)); 241 +
  242 + if AExperiment.ABPoints then
  243 + begin
  244 + Points.OnStart.A := ReadInteger(LS, KEY_POINTS_ONSTART_A,0);
  245 + Points.OnStart.B := ReadInteger(LS, KEY_POINTS_ONSTART_B,0);
  246 + Points.OnStart.G := ReadInteger(LS, KEY_POINTS_ONSTART_G,0);
  247 + end
  248 + else
  249 + begin
  250 + Points.OnStart.A := ReadInteger(LS, KEY_POINTS_ONSTART_I,0);
  251 + Points.OnStart.G := ReadInteger(LS, KEY_POINTS_ONSTART_G,0);
  252 + end;
  253 +
245 Turn.Count:= ReadInteger(LS, KEY_TURN_COUNT,0); 254 Turn.Count:= ReadInteger(LS, KEY_TURN_COUNT,0);
246 Turn.Value:= ReadInteger(LS, KEY_TURN_VALUE,2); 255 Turn.Value:= ReadInteger(LS, KEY_TURN_VALUE,2);
247 Turn.Random:= ReadBool(LS, KEY_TURN_RANDOM,False); 256 Turn.Random:= ReadBool(LS, KEY_TURN_RANDOM,False);
@@ -254,19 +263,36 @@ var @@ -254,19 +263,36 @@ var
254 EndCriterium.InterlockingPorcentage:= GetEndCriteriaPorcentageFromString(s1); 263 EndCriterium.InterlockingPorcentage:= GetEndCriteriaPorcentageFromString(s1);
255 EndCriterium.LastCycles:= GetEndCriteriaLastCyclesFromString(s1); 264 EndCriterium.LastCycles:= GetEndCriteriaLastCyclesFromString(s1);
256 265
257 - ReadContingencies(i,True);  
258 - ReadContingencies(i,False); 266 + LContingenciesCount := ReadContingenciesCount(i,KEY_CONTINGENCY);
  267 + LMetaContingenCount := ReadContingenciesCount(i,KEY_METACONTINGENCY);
  268 +
  269 + if LContingenciesCount > 0 then
  270 + for j := 0 to LContingenciesCount-1 do
  271 + begin
  272 + SetLength(Contingencies,Length(Contingencies)+1);
  273 + Contingencies[Length(Contingencies)-1] := ReadContingency(i,KEY_CONTINGENCY+IntToStr(j+1));
  274 + end;
  275 +
  276 + if LMetaContingenCount > 0 then;
  277 + for j := 0 to LMetaContingenCount-1 do
  278 + begin
  279 + SetLength(Contingencies,Length(Contingencies)+1);
  280 + Contingencies[Length(Contingencies)-1] := ReadContingency(i,KEY_METACONTINGENCY+IntToStr(j+1));
  281 + end;
259 282
260 - Prompt := TPrompt.Create(  
261 - AExperiment  
262 - , GetPromptStyleFromString(ReadString(LS,KEY_PROMPT_STYLE,''))  
263 - , Contingencies  
264 - , ReadString(LS,KEY_PROMPT_MESSAGE,'')  
265 - ); 283 + LPromptStyle := ReadString(LS,KEY_PROMPT_STYLE,'');
  284 + LPromptMessa := ReadString(LS,KEY_PROMPT_MESSAGE,'');
266 285
  286 + if (LPromptMessa <> '') and (LPromptStyle <> '') then
  287 + Prompt := TPrompt.Create(
  288 + AExperiment
  289 + , GetPromptStyleFromString(LPromptStyle)
  290 + , Contingencies
  291 + , LPromptMessa
  292 + );
267 end; 293 end;
268 - AExperiment.Condition[i]:= C;  
269 - i := AExperiment.AppendCondition; 294 + AExperiment.Condition[AExperiment.AppendCondition]:= C;
  295 + Inc(i);
270 LS := SEC_CONDITION+IntToStr(i+1); 296 LS := SEC_CONDITION+IntToStr(i+1);
271 end; 297 end;
272 end; 298 end;
@@ -290,11 +316,10 @@ var @@ -290,11 +316,10 @@ var
290 Choice := GetChoiceFromString(ReadString(LS,KEY_PLAYER_CHOICE_LAST,'0,NONE,')); 316 Choice := GetChoiceFromString(ReadString(LS,KEY_PLAYER_CHOICE_LAST,'0,NONE,'));
291 ID := ReadString(LS,KEY_PLAYER_ID,'ID'); 317 ID := ReadString(LS,KEY_PLAYER_ID,'ID');
292 Nicname := ReadString(LS,KEY_PLAYER_NICNAME,GenResourceName(i)); 318 Nicname := ReadString(LS,KEY_PLAYER_NICNAME,GenResourceName(i));
293 - 319 + Points := GetPPointsFromString(ReadString(LS,KEY_PLAYER_POINTS,'0,0,'));
294 // currently not in use 320 // currently not in use
295 //Login := ReadString(LS,KEY_PLAYER_LOGIN,'jogador'+IntToStr(i+1)); 321 //Login := ReadString(LS,KEY_PLAYER_LOGIN,'jogador'+IntToStr(i+1));
296 //Password := ReadString(LS,KEY_PLAYER_PASSWORD,'1234'); 322 //Password := ReadString(LS,KEY_PLAYER_PASSWORD,'1234');
297 - //Points := GetPPointsFromString(ReadString(LS,KEY_PLAYER_POINTS,'0,0,'));  
298 //Status := GetStatusFromString(ReadString(LS,KEY_PLAYER_STATUS,'esperando')); 323 //Status := GetStatusFromString(ReadString(LS,KEY_PLAYER_STATUS,'esperando'));
299 //Data.Values[KEY_PLAYER_TEMP] := ReadString(LS,KEY_PLAYER_TEMP,''); 324 //Data.Values[KEY_PLAYER_TEMP] := ReadString(LS,KEY_PLAYER_TEMP,'');
300 end; 325 end;
@@ -312,7 +337,6 @@ begin @@ -312,7 +337,6 @@ begin
312 with LIniFile do 337 with LIniFile do
313 if SectionExists(SEC_EXPERIMENT) then 338 if SectionExists(SEC_EXPERIMENT) then
314 begin 339 begin
315 - AExperiment := TExperiment.Create(AExperiment.Owner);  
316 ReadExperiment; 340 ReadExperiment;
317 ReadConditions; 341 ReadConditions;
318 ReadPlayers; 342 ReadPlayers;
@@ -325,21 +349,21 @@ begin @@ -325,21 +349,21 @@ begin
325 else 349 else
326 begin 350 begin
327 ShowMessage(ERROR_NO_CONTINGENCIES+SEC_CONDITION+IntToStr(i+1)); 351 ShowMessage(ERROR_NO_CONTINGENCIES+SEC_CONDITION+IntToStr(i+1));
  352 + LIniFile.Free;
328 Exit; 353 Exit;
329 end 354 end
330 else 355 else
331 begin 356 begin
332 ShowMessage(ERROR_NO_CONDITIONS); 357 ShowMessage(ERROR_NO_CONDITIONS);
  358 + LIniFile.Free;
333 Exit; 359 Exit;
334 end; 360 end;
335 -  
336 Result := True; 361 Result := True;
  362 + AExperiment.CurrentCondition:=0;
337 end 363 end
338 else 364 else
339 - begin  
340 - ShowMessage(ERROR_SECTION_NOT_FOUND+SEC_EXPERIMENT);  
341 - Exit;  
342 - end; 365 + ShowMessage(ERROR_SECTION_NOT_FOUND+SEC_EXPERIMENT);
  366 +
343 LIniFile.Free; 367 LIniFile.Free;
344 end 368 end
345 else 369 else
@@ -348,7 +372,7 @@ end; @@ -348,7 +372,7 @@ end;
348 372
349 procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename: string); 373 procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename: string);
350 var 374 var
351 - i,j : Integer; 375 + i,j , MI, CI: Integer;
352 LWriter : TRegData; 376 LWriter : TRegData;
353 LIniFile : TIniFile; 377 LIniFile : TIniFile;
354 LC, 378 LC,
@@ -362,34 +386,59 @@ begin @@ -362,34 +386,59 @@ begin
362 LIniFile.WriteString(SEC_EXPERIMENT,KEY_RESEARCHER,AExperiment.Researcher); 386 LIniFile.WriteString(SEC_EXPERIMENT,KEY_RESEARCHER,AExperiment.Researcher);
363 387
364 with LIniFile do 388 with LIniFile do
365 - for i := 0 to AExperiment.ConditionsCount do 389 + for i := 0 to AExperiment.ConditionsCount-1 do
366 begin 390 begin
367 LC := SEC_CONDITION+IntToStr(i+1); 391 LC := SEC_CONDITION+IntToStr(i+1);
368 with AExperiment.Condition[i] do 392 with AExperiment.Condition[i] do
369 begin 393 begin
370 WriteString(LC,KEY_ENDCRITERIA,GetEndCriteriaString(EndCriterium)); 394 WriteString(LC,KEY_ENDCRITERIA,GetEndCriteriaString(EndCriterium));
371 WriteString(LC, KEY_POINTS_COUNT,GetPointsString(Points.Count)); 395 WriteString(LC, KEY_POINTS_COUNT,GetPointsString(Points.Count));
372 - WriteString(LC, KEY_POINTS_ONSTART,GetPointsString(Points.OnStart)); 396 + if AExperiment.ABPoints then
  397 + begin
  398 + WriteInteger(LC, KEY_POINTS_ONSTART_A,Points.OnStart.A);
  399 + WriteInteger(LC, KEY_POINTS_ONSTART_B,Points.OnStart.B);
  400 + WriteInteger(LC, KEY_POINTS_ONSTART_G,Points.OnStart.G);
  401 + end
  402 + else
  403 + begin
  404 + WriteInteger(LC, KEY_POINTS_ONSTART_I,Points.OnStart.A);
  405 + WriteInteger(LC, KEY_POINTS_ONSTART_G,Points.OnStart.G);
  406 + end;
373 WriteInteger(LC, KEY_TURN_COUNT,Turn.Count); 407 WriteInteger(LC, KEY_TURN_COUNT,Turn.Count);
374 WriteInteger(LC, KEY_TURN_VALUE,Turn.Value); 408 WriteInteger(LC, KEY_TURN_VALUE,Turn.Value);
375 WriteBool(LC, KEY_TURN_RANDOM,Turn.Random); 409 WriteBool(LC, KEY_TURN_RANDOM,Turn.Random);
376 WriteInteger(LC, KEY_CYCLES_COUNT,Cycles.Count); 410 WriteInteger(LC, KEY_CYCLES_COUNT,Cycles.Count);
377 WriteInteger(LC, KEY_CYCLES_VALUE,Cycles.Value); 411 WriteInteger(LC, KEY_CYCLES_VALUE,Cycles.Value);
378 WriteInteger(LC, KEY_CYCLES_GEN,Cycles.Generation); 412 WriteInteger(LC, KEY_CYCLES_GEN,Cycles.Generation);
379 - //WriteBool(LC, KEY_PROMPT_VALUE,Prompt.Value);  
380 - //WriteString(LC, KEY_PROMPT_MESSAGE, Prompt.PromptMessage);  
381 - //WriteString(LC, KEY_PROMPT_STYLE, GetPromptStyleString(Prompt.PromptStyle)); 413 + WriteString(LC, KEY_PROMPT_MESSAGE, Prompt.Question);
  414 + WriteString(LC, KEY_PROMPT_STYLE, GetPromptStyleString(Prompt.PromptStyle));
382 415
  416 + MI := 0;
  417 + CI := 0;
383 for j := 0 to High(Contingencies) do 418 for j := 0 to High(Contingencies) do
384 begin 419 begin
385 if Contingencies[j].Meta then 420 if Contingencies[j].Meta then
386 - LCK := KEY_METACONTINGENCY+IntToStr(j+1) 421 + begin
  422 + LCK := KEY_METACONTINGENCY+IntToStr(MI+1);
  423 + Inc(MI);
  424 + end
387 else 425 else
388 - LCK := KEY_CONTINGENCY+IntToStr(j+1); 426 + begin
  427 + LCK := KEY_CONTINGENCY+IntToStr(CI+1);
  428 + Inc(CI);
  429 + end;
389 430
390 with Contingencies[j] do 431 with Contingencies[j] do
391 begin 432 begin
392 - WriteString(LC,LCK+KEY_CONSEQUE,Consequence.AsString('')); 433 + WriteString(LC,LCK+KEY_CONSEQUE,Consequence.CsqString);
  434 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_PREPEND,Consequence.Prepend);
  435 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_PREPEND_LOSS,Consequence.PrependLoss);
  436 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_S,Consequence.AppendiceLossSingular);
  437 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_APPEND_LOSS_P,Consequence.AppendiceLossPlural);
  438 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_PREPEND_EARN,Consequence.PrependEarn);
  439 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_S,Consequence.AppendiceEarnSingular);
  440 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_APPEND_EARN_P,Consequence.AppendiceEarnPlural);
  441 + WriteString(LC,LCK+KEY_CONSEQUE_MESSAGE_APPEND_ZERO, Consequence.AppendiceZero);
393 WriteString(LC,LCK+KEY_CRITERIA,CriteriaString); 442 WriteString(LC,LCK+KEY_CRITERIA,CriteriaString);
394 end; 443 end;
395 end; 444 end;
@@ -397,20 +446,21 @@ begin @@ -397,20 +446,21 @@ begin
397 end; 446 end;
398 447
399 with LIniFile do 448 with LIniFile do
400 - for i:=0 to AExperiment.PlayersCount do  
401 - with AExperiment.Player[i] do  
402 - begin  
403 - LC := SEC_PLAYER+IntToStr(i+1);  
404 - WriteInteger(LC,KEY_PLAYER_TURN,AExperiment.Player[i].Turn);  
405 - WriteString(LC,KEY_PLAYER_CHOICE_LAST,GetChoiceString(AExperiment.Player[i].Choice));  
406 - WriteString(LC,KEY_PLAYER_ID,AExperiment.Player[i].ID);  
407 - WriteString(LC,KEY_PLAYER_NICNAME,AExperiment.Player[i].Nicname);  
408 - WriteString(LC,KEY_PLAYER_LOGIN,AExperiment.Player[i].Login);  
409 - WriteString(LC,KEY_PLAYER_PASSWORD,AExperiment.Player[i].Password);  
410 - WriteString(LC,KEY_PLAYER_POINTS,GetPPointsString(AExperiment.Player[i].Points));  
411 - WriteString(LC,KEY_PLAYER_STATUS,GetStatusString(AExperiment.Player[i].Status));  
412 - WriteString(LC,KEY_PLAYER_TEMP,AExperiment.Player[i].Data.Values[KEY_PLAYER_TEMP]);  
413 - end; 449 + if AExperiment.PlayersCount > 0 then
  450 + for i:=0 to AExperiment.PlayersCount-1 do
  451 + with AExperiment.Player[i] do
  452 + begin
  453 + LC := SEC_PLAYER+IntToStr(i+1);
  454 + WriteString(LC,KEY_PLAYER_ID,AExperiment.Player[i].ID);
  455 + WriteString(LC,KEY_PLAYER_NICNAME,AExperiment.Player[i].Nicname);
  456 + WriteInteger(LC,KEY_PLAYER_TURN,AExperiment.Player[i].Turn);
  457 + WriteString(LC,KEY_PLAYER_CHOICE_LAST,GetChoiceString(AExperiment.Player[i].Choice));
  458 + WriteString(LC,KEY_PLAYER_POINTS,GetPPointsString(AExperiment.Player[i].Points));
  459 + //WriteString(LC,KEY_PLAYER_LOGIN,AExperiment.Player[i].Login);
  460 + //WriteString(LC,KEY_PLAYER_PASSWORD,AExperiment.Player[i].Password);
  461 + //WriteString(LC,KEY_PLAYER_STATUS,GetStatusString(AExperiment.Player[i].Status));
  462 + //WriteString(LC,KEY_PLAYER_TEMP,AExperiment.Player[i].Data.Values[KEY_PLAYER_TEMP]);
  463 + end;
414 end; 464 end;
415 465
416 end. 466 end.