Commit eac0a6c9848d4f7968c89cf0f66c7963fded2956

Authored by Carlos Picanco
1 parent 0b963003
Exists in master

implement group, A and B messages,also fix turn, cycle count conditionals

units/game_actors.pas
@@ -5,7 +5,7 @@ unit game_actors; @@ -5,7 +5,7 @@ unit game_actors;
5 interface 5 interface
6 6
7 uses 7 uses
8 - Classes, SysUtils, Forms,PopupNotifier 8 + Classes, SysUtils, Forms,PopupNotifier, ExtCtrls
9 , game_actors_point 9 , game_actors_point
10 ; 10 ;
11 type 11 type
@@ -80,26 +80,26 @@ type @@ -80,26 +80,26 @@ type
80 private 80 private
81 FAppendicePlural: string; 81 FAppendicePlural: string;
82 FAppendiceSingular: string; 82 FAppendiceSingular: string;
83 - FLastPresentedMessage: string;  
84 FNicname: string; 83 FNicname: string;
85 FStyle : TConsequenceStyle; 84 FStyle : TConsequenceStyle;
86 FP : TGamePoint; 85 FP : TGamePoint;
  86 + FTimer : TTimer;
87 FMessage : TPopupNotifier; 87 FMessage : TPopupNotifier;
88 function GetShouldPublishMessage: Boolean; 88 function GetShouldPublishMessage: Boolean;
89 protected 89 protected
90 FConsequenceByPlayerID : TStringList; 90 FConsequenceByPlayerID : TStringList;
91 procedure StopTimer(Sender:TObject;var ACloseAction:TCloseAction); 91 procedure StopTimer(Sender:TObject;var ACloseAction:TCloseAction);
92 - procedure TimerTimer(Sender:TOBject);virtual; 92 + procedure SelfDestroy(Sender:TOBject);virtual;
93 public 93 public
94 constructor Create(AOwner:TComponent; AP:TGamePoint; AStyle:TConsequenceStyle; AAppendiceSingular,AAppendicePlural:string);overload; 94 constructor Create(AOwner:TComponent; AP:TGamePoint; AStyle:TConsequenceStyle; AAppendiceSingular,AAppendicePlural:string);overload;
95 constructor Create(AOwner:TComponent; AP:integer; AStyle: TConsequenceStyle; AMessage:array of string);overload; 95 constructor Create(AOwner:TComponent; AP:integer; AStyle: TConsequenceStyle; AMessage:array of string);overload;
96 constructor Create(AOwner:TComponent; AConsequenceString: string);virtual;overload; 96 constructor Create(AOwner:TComponent; AConsequenceString: string);virtual;overload;
97 destructor Destroy;override; 97 destructor Destroy;override;
98 function AsString(AID :string): string; 98 function AsString(AID :string): string;
99 - function PointMessage(ForGroup: Boolean):string;  
100 - procedure Present(ForGroup: Boolean); 99 + function GenerateMessage(ForGroup: Boolean):string;
  100 + procedure PresentMessage;
  101 + procedure PresentPoints;
101 property ShouldPublishMessage : Boolean read GetShouldPublishMessage; 102 property ShouldPublishMessage : Boolean read GetShouldPublishMessage;
102 - property LastPresentedMessage : string read FLastPresentedMessage;  
103 property PlayerNicname : string read FNicname write FNicname; 103 property PlayerNicname : string read FNicname write FNicname;
104 property AppendiceSingular : string read FAppendiceSingular; 104 property AppendiceSingular : string read FAppendiceSingular;
105 property AppendicePlural : string read FAppendicePlural; 105 property AppendicePlural : string read FAppendicePlural;
@@ -248,7 +248,7 @@ begin @@ -248,7 +248,7 @@ begin
248 Result += '|'; 248 Result += '|';
249 end; 249 end;
250 250
251 -function TContingency.ResponseMeetsCriteriaI(R : TGameRow; C : TGameColor): Boolean; 251 +function TContingency.ResponseMeetsCriteriaI(R : TGameRow; C : TGameColor): Boolean; // should be for admin only
252 var 252 var
253 LMod : TGameRow; 253 LMod : TGameRow;
254 LRow, LColor:Boolean; 254 LRow, LColor:Boolean;
@@ -270,7 +270,7 @@ begin @@ -270,7 +270,7 @@ begin
270 CriteriaEvent; 270 CriteriaEvent;
271 end; 271 end;
272 272
273 -function TContingency.ResponseMeetsCriteriaG(Players: TPlayers): Boolean; 273 +function TContingency.ResponseMeetsCriteriaG(Players: TPlayers): Boolean; // must be for admin only
274 var i : integer; 274 var i : integer;
275 Cs : array of TGameColor; 275 Cs : array of TGameColor;
276 Rs : array of TGameRow; 276 Rs : array of TGameRow;
@@ -509,11 +509,12 @@ constructor TConsequence.Create(AOwner: TComponent; AP: integer; @@ -509,11 +509,12 @@ constructor TConsequence.Create(AOwner: TComponent; AP: integer;
509 AStyle:TConsequenceStyle; AMessage: array of string); 509 AStyle:TConsequenceStyle; AMessage: array of string);
510 begin 510 begin
511 inherited Create(AOwner); 511 inherited Create(AOwner);
  512 + FP := TGamePoint.Create(AOwner,AP);
512 FStyle:=AStyle; 513 FStyle:=AStyle;
513 FNicname:=AMessage[0]; 514 FNicname:=AMessage[0];
514 FAppendiceSingular:=AMessage[1]; 515 FAppendiceSingular:=AMessage[1];
515 FAppendicePlural:=AMessage[2]; 516 FAppendicePlural:=AMessage[2];
516 - FP := TGamePoint.Create(AOwner,AP); 517 +
517 FMessage := TPopupNotifier.Create(AOwner); 518 FMessage := TPopupNotifier.Create(AOwner);
518 FConsequenceByPlayerID := TStringList.Create; 519 FConsequenceByPlayerID := TStringList.Create;
519 end; 520 end;
@@ -527,7 +528,12 @@ begin @@ -527,7 +528,12 @@ begin
527 FNicname:=ExtractDelimited(3,AConsequenceString,['|']); 528 FNicname:=ExtractDelimited(3,AConsequenceString,['|']);
528 FAppendiceSingular:=ExtractDelimited(4,AConsequenceString,['|']); 529 FAppendiceSingular:=ExtractDelimited(4,AConsequenceString,['|']);
529 FAppendicePlural:=ExtractDelimited(5,AConsequenceString,['|']); 530 FAppendicePlural:=ExtractDelimited(5,AConsequenceString,['|']);
530 - FMessage := TPopupNotifier.Create(AOwner); 531 +
  532 + FMessage := TPopupNotifier.Create(Self);
  533 + FTimer := TTimer.Create(Self);
  534 + FTimer.Enabled:=False;
  535 + FTimer.Interval:=6000;
  536 + FTimer.OnTimer:=@SelfDestroy;
531 FConsequenceByPlayerID := TStringList.Create; 537 FConsequenceByPlayerID := TStringList.Create;
532 end; 538 end;
533 539
@@ -543,40 +549,47 @@ begin @@ -543,40 +549,47 @@ begin
543 Result += GetConsequenceStylesString(FStyle)+'|'; 549 Result += GetConsequenceStylesString(FStyle)+'|';
544 Result += FNicname +'|'; 550 Result += FNicname +'|';
545 Result += FAppendiceSingular + '|'; 551 Result += FAppendiceSingular + '|';
546 - Result += FAppendicePlural + '|'; 552 + Result += FAppendicePlural + '|+';
547 FConsequenceByPlayerID.Values[AID]:=Result; 553 FConsequenceByPlayerID.Values[AID]:=Result;
548 end; 554 end;
549 555
550 -function TConsequence.PointMessage(ForGroup: Boolean): string; 556 +function TConsequence.GenerateMessage(ForGroup: Boolean): string;
551 begin 557 begin
552 Result := FP.PointMessage(FNicname,FAppendicePlural, FAppendiceSingular,ForGroup); 558 Result := FP.PointMessage(FNicname,FAppendicePlural, FAppendiceSingular,ForGroup);
  559 + FMessage.Text := Result;
  560 +end;
553 561
  562 +procedure TConsequence.PresentMessage;
  563 +var
  564 + PopUpPos : TPoint;
  565 +begin
554 if gscA in FStyle then 566 if gscA in FStyle then
555 - FormMatrixGame.LabelIndACount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndACount.Caption) + FP.ResultAsInteger); 567 + begin
  568 + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110;
  569 + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10;
  570 + end;
556 571
557 if gscB in FStyle then 572 if gscB in FStyle then
558 - FormMatrixGame.LabelIndBCount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndBCount.Caption) + FP.ResultAsInteger); 573 + begin
  574 + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left+110;
  575 + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10;
  576 + end;
559 577
560 if gscG in FStyle then 578 if gscG in FStyle then
561 - FormMatrixGame.LabelGroupCount.Caption:= IntToStr(StrToInt(FormMatrixGame.LabelGroupCount.Caption) + FP.ResultAsInteger);  
562 -end;  
563 -  
564 -  
565 -procedure TConsequence.Present(ForGroup: Boolean);  
566 -var  
567 - PopUpPos : TPoint;  
568 -begin  
569 - PopUpPos.X := FormMatrixGame.GBIndividualAB.Left;  
570 - PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; 579 + begin
  580 + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110;
  581 + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height+100;
  582 + end;
571 PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos); 583 PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos);
572 -  
573 FMessage.Color:=clTeal; 584 FMessage.Color:=clTeal;
574 FMessage.Title:=''; 585 FMessage.Title:='';
575 - FMessage.Text := FP.PointMessage(FNicname,FAppendicePlural, FAppendiceSingular,ForGroup);  
576 - FLastPresentedMessage := FMessage.Text;  
577 - FMessage.OnClose:=@StopTimer;  
578 - FormMatrixGame.Timer.OnTimer := @TimerTimer; 586 + FMessage.ShowAtPos(PopUpPos.X, PopUpPos.Y);
  587 + FTimer.Enabled:=True;
  588 +end;
579 589
  590 +procedure TConsequence.PresentPoints;
  591 +begin
  592 + //is gscPoints in FStyle then just in case...
580 if gscA in FStyle then 593 if gscA in FStyle then
581 FormMatrixGame.LabelIndACount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndACount.Caption) + FP.ResultAsInteger); 594 FormMatrixGame.LabelIndACount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndACount.Caption) + FP.ResultAsInteger);
582 595
@@ -585,13 +598,9 @@ begin @@ -585,13 +598,9 @@ begin
585 598
586 if gscG in FStyle then 599 if gscG in FStyle then
587 FormMatrixGame.LabelGroupCount.Caption:= IntToStr(StrToInt(FormMatrixGame.LabelGroupCount.Caption) + FP.ResultAsInteger); 600 FormMatrixGame.LabelGroupCount.Caption:= IntToStr(StrToInt(FormMatrixGame.LabelGroupCount.Caption) + FP.ResultAsInteger);
588 -  
589 - if gscBroadcastMessage in FStyle then Exit;  
590 - FMessage.ShowAtPos(PopUpPos.X, PopUpPos.Y);  
591 - FormMatrixGame.Timer.Enabled:=True;  
592 end; 601 end;
593 602
594 -function TConsequence.GetShouldPublishMessage: Boolean; 603 +function TConsequence.GetShouldPublishMessage: Boolean; // for players only
595 begin 604 begin
596 Result := gscBroadcastMessage in FStyle; 605 Result := gscBroadcastMessage in FStyle;
597 end; 606 end;
@@ -599,12 +608,13 @@ end; @@ -599,12 +608,13 @@ end;
599 procedure TConsequence.StopTimer(Sender: TObject; var ACloseAction: TCloseAction 608 procedure TConsequence.StopTimer(Sender: TObject; var ACloseAction: TCloseAction
600 ); 609 );
601 begin 610 begin
602 - FormMatrixGame.Timer.Enabled:=False; 611 + //FormMatrixGame.Timer.Enabled:=False;
603 end; 612 end;
604 613
605 -procedure TConsequence.TimerTimer(Sender: TOBject); 614 +procedure TConsequence.SelfDestroy(Sender: TOBject);
606 begin 615 begin
607 FMessage.Visible:=False; 616 FMessage.Visible:=False;
  617 + Free;
608 end; 618 end;
609 619
610 620
units/game_control.pas
@@ -2,7 +2,7 @@ unit game_control; @@ -2,7 +2,7 @@ unit game_control;
2 2
3 {$mode objfpc}{$H+} 3 {$mode objfpc}{$H+}
4 4
5 -{$DEFINE DEBUG} 5 +//{$DEFINE DEBUG}
6 6
7 interface 7 interface
8 8
@@ -49,7 +49,8 @@ type @@ -49,7 +49,8 @@ type
49 procedure CleanMatrix(AEnabled : Boolean); 49 procedure CleanMatrix(AEnabled : Boolean);
50 procedure EnablePlayerMatrix(AID:UTF8string; ATurn:integer; AEnabled:Boolean); 50 procedure EnablePlayerMatrix(AID:UTF8string; ATurn:integer; AEnabled:Boolean);
51 private 51 private
52 - function ShouldStartCycle : Boolean; 52 + function ShouldStartExperiment: Boolean;
  53 + function ShouldEndCycle : Boolean;
53 function ShouldAskQuestion : Boolean; 54 function ShouldAskQuestion : Boolean;
54 procedure KickPlayer(AID:string); 55 procedure KickPlayer(AID:string);
55 procedure NextTurn(Sender: TObject); 56 procedure NextTurn(Sender: TObject);
@@ -130,15 +131,20 @@ end; @@ -130,15 +131,20 @@ end;
130 131
131 { TGameControl } 132 { TGameControl }
132 133
133 -function TGameControl.ShouldStartCycle: Boolean; // starts experiment too 134 +function TGameControl.ShouldStartExperiment: Boolean;
134 begin 135 begin
135 Result := FExperiment.PlayersCount = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value; 136 Result := FExperiment.PlayersCount = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value;
136 end; 137 end;
137 138
  139 +function TGameControl.ShouldEndCycle: Boolean;
  140 +begin
  141 + Result := FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value-1;
  142 +end;
  143 +
138 function TGameControl.ShouldAskQuestion: Boolean; // end cycle, restart alias 144 function TGameControl.ShouldAskQuestion: Boolean; // end cycle, restart alias
139 begin 145 begin
140 // TODO: prompt only when an odd row was selected 146 // TODO: prompt only when an odd row was selected
141 - Result := ShouldStartCycle and FExperiment.Condition[FExperiment.CurrentCondition].Contingencies[3].Fired; 147 + Result := ShouldEndCycle and FExperiment.Condition[FExperiment.CurrentCondition].Contingencies[3].Fired;
142 end; 148 end;
143 149
144 procedure TGameControl.KickPlayer(AID: string); 150 procedure TGameControl.KickPlayer(AID: string);
@@ -149,27 +155,35 @@ end; @@ -149,27 +155,35 @@ end;
149 procedure TGameControl.NextTurn(Sender: TObject); 155 procedure TGameControl.NextTurn(Sender: TObject);
150 begin 156 begin
151 // update admin view 157 // update admin view
152 - FormMatrixGame.LabelExpCountTurn.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count);  
153 -  
154 - // inform players  
155 - 158 + FormMatrixGame.LabelExpCountTurn.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count+1);
156 159
157 end; 160 end;
158 161
159 procedure TGameControl.NextCycle(Sender: TObject); 162 procedure TGameControl.NextCycle(Sender: TObject);
  163 +var
  164 + i,
  165 + LCount : integer;
  166 + LConsequences : string;
160 begin 167 begin
161 // prompt question to all players 168 // prompt question to all players
162 - FormMatrixGame.LabelExpCountCycle.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Count); 169 + FormMatrixGame.LabelExpCountCycle.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Count+1);
163 {$IFDEF DEBUG} 170 {$IFDEF DEBUG}
164 - WriteLn('cycle:',FExperiment.ConsequenceStringFromChoices); 171 + WriteLn('cycle:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
165 {$ENDIF} 172 {$ENDIF}
166 - //FZMQActor.SendMessage([K_CYCLES]) 173 +
  174 +
  175 + //P := FExperiment.PlayerFromID[Self.ID];
  176 + LConsequences := FExperiment.ConsequenceStringFromChoices;
  177 + LCount := WordCount(LConsequences,['+']);
  178 + if LCount > 0 then
  179 + for i := 1 to LCount do
  180 + FZMQActor.SendMessage([K_CYCLES,ExtractDelimited(i,LConsequences,['+'])]); // as string generates the pts result
167 end; 181 end;
168 182
169 procedure TGameControl.NextLineage(Sender: TObject); 183 procedure TGameControl.NextLineage(Sender: TObject);
170 begin 184 begin
171 // pause, kick older player, wait for new player, resume 185 // pause, kick older player, wait for new player, resume
172 - FormMatrixGame.LabelExpCountGeneration.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Generation); 186 + FormMatrixGame.LabelExpCountGeneration.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Generation+1);
173 end; 187 end;
174 188
175 procedure TGameControl.NextCondition(Sender: TObject); 189 procedure TGameControl.NextCondition(Sender: TObject);
@@ -186,7 +200,7 @@ end; @@ -186,7 +200,7 @@ end;
186 200
187 procedure TGameControl.Interlocking(Sender: TObject); 201 procedure TGameControl.Interlocking(Sender: TObject);
188 begin 202 begin
189 - FormMatrixGame.LabelExpCountInterlocks.Caption:= IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Interlocks.Count); 203 + FormMatrixGame.LabelExpCountInterlocks.Caption:= IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Interlocks.Count+1);
190 204
191 end; 205 end;
192 206
@@ -410,7 +424,7 @@ end; @@ -410,7 +424,7 @@ end;
410 procedure TGameControl.ShowPopUp(AText: string); 424 procedure TGameControl.ShowPopUp(AText: string);
411 var PopUpPos : TPoint; 425 var PopUpPos : TPoint;
412 begin 426 begin
413 - PopUpPos.X := FormMatrixGame.GBIndividualAB.Left; 427 + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110;
414 PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; 428 PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10;
415 PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos); 429 PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos);
416 FormMatrixGame.PopupNotifier.Title:=''; 430 FormMatrixGame.PopupNotifier.Title:='';
@@ -473,12 +487,12 @@ begin @@ -473,12 +487,12 @@ begin
473 FExperiment.OnInterlocking:=@Interlocking; 487 FExperiment.OnInterlocking:=@Interlocking;
474 FExperiment.OnConsequence:=@Consequence; 488 FExperiment.OnConsequence:=@Consequence;
475 489
476 - NextTurn(Self);  
477 - NextCycle(Self);  
478 - NextLineage(Self);  
479 - NextCondition(Self);  
480 - Interlocking(Self);  
481 - Consequence(Self); 490 + //NextTurn(Self);
  491 + //NextCycle(Self);
  492 + //NextLineage(Self);
  493 + //NextCondition(Self);
  494 + //Interlocking(Self);
  495 + //Consequence(Self);
482 496
483 SendRequest(K_LOGIN); 497 SendRequest(K_LOGIN);
484 end; 498 end;
@@ -623,7 +637,7 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); @@ -623,7 +637,7 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList);
623 637
624 case FActor of 638 case FActor of
625 gaPlayer:begin 639 gaPlayer:begin
626 - if FExperiment.PlayersCount = P.Turn+1 then 640 + if P.Turn = FExperiment.PlayersCount-1 then
627 begin 641 begin
628 // update next turn 642 // update next turn
629 if Self.ID = P.ID then 643 if Self.ID = P.ID then
@@ -632,12 +646,12 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); @@ -632,12 +646,12 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList);
632 FExperiment.Player[Self.ID] := P; 646 FExperiment.Player[Self.ID] := P;
633 end; 647 end;
634 648
635 - // no wait turns  
636 - // EnablePlayerMatrix(Self.ID,0, True);  
637 -  
638 //CleanMatrix; 649 //CleanMatrix;
639 CleanMatrix(False); 650 CleanMatrix(False);
640 651
  652 + // no wait turns
  653 + EnablePlayerMatrix(Self.ID,0, True);
  654 +
641 // wait for server 655 // wait for server
642 Exit; 656 Exit;
643 end; 657 end;
@@ -673,14 +687,16 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); @@ -673,14 +687,16 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList);
673 end; 687 end;
674 688
675 procedure OnEndCycle; 689 procedure OnEndCycle;
  690 + var
  691 + LConsequence : TConsequence;
676 begin 692 begin
677 - // Updata turn  
678 -  
679 - //  
680 case FActor of 693 case FActor of
681 gaPlayer: 694 gaPlayer:
682 begin 695 begin
683 - 696 + LConsequence := TConsequence.Create(nil,AMessage[1]);
  697 + LConsequence.GenerateMessage(True);
  698 + LConsequence.PresentPoints;
  699 + LConsequence.PresentMessage;
684 end; 700 end;
685 end; 701 end;
686 end; 702 end;
@@ -781,7 +797,7 @@ begin @@ -781,7 +797,7 @@ begin
781 if MHas(K_KICK) then SayGoodBye; 797 if MHas(K_KICK) then SayGoodBye;
782 if MHas(K_START) then NotifyPlayers; 798 if MHas(K_START) then NotifyPlayers;
783 if MHas(K_CYCLES) then OnEndCycle; 799 if MHas(K_CYCLES) then OnEndCycle;
784 - if MHas(K_QUESTION) then ShowQuestion; 800 + //if MHas(K_QUESTION) then ShowQuestion;
785 //if MHas(K_QMESSAGE) then QuestionMessages; 801 //if MHas(K_QMESSAGE) then QuestionMessages;
786 end; 802 end;
787 803
@@ -800,9 +816,6 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); @@ -800,9 +816,6 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
800 begin 816 begin
801 if not FExperiment.PlayerIsPlaying[ARequest[0]] then 817 if not FExperiment.PlayerIsPlaying[ARequest[0]] then
802 begin 818 begin
803 - {$IFDEF DEBUG}  
804 - WriteLn(FExperiment.PlayersCount,'<',FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value);  
805 - {$ENDIF}  
806 if FExperiment.PlayersCount < FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value then 819 if FExperiment.PlayersCount < FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value then
807 begin 820 begin
808 // ok, let player login 821 // ok, let player login
@@ -860,7 +873,7 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); @@ -860,7 +873,7 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
860 FZMQActor.SendMessage([K_ARRIVED,PS]); 873 FZMQActor.SendMessage([K_ARRIVED,PS]);
861 874
862 // start Experiment 875 // start Experiment
863 - if ShouldStartCycle then 876 + if ShouldStartExperiment then
864 StartExperiment; 877 StartExperiment;
865 878
866 end 879 end
@@ -879,6 +892,9 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); @@ -879,6 +892,9 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
879 var P : TPlayer; 892 var P : TPlayer;
880 S : string; 893 S : string;
881 begin 894 begin
  895 + {$IFDEF DEBUG}
  896 + WriteLn('Count:>>>>>>>>>>>>>>>>>>>>>>>>>>>',FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count, '<', FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value);
  897 + {$ENDIF}
882 P := FExperiment.PlayerFromID[ARequest[0]]; 898 P := FExperiment.PlayerFromID[ARequest[0]];
883 P.Choice.Row:= GetRowFromString(ARequest[3]); // row 899 P.Choice.Row:= GetRowFromString(ARequest[3]); // row
884 P.Choice.Color:= GetGameColorFromString(ARequest[4]); // color 900 P.Choice.Color:= GetGameColorFromString(ARequest[4]); // color
@@ -901,16 +917,16 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); @@ -901,16 +917,16 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
901 // broadcast choice 917 // broadcast choice
902 FZMQActor.SendMessage([K_CHOICE,P.ID,ARequest[3],ARequest[4],IntToStr(P.Turn)]); 918 FZMQActor.SendMessage([K_CHOICE,P.ID,ARequest[3],ARequest[4],IntToStr(P.Turn)]);
903 919
904 - if ShouldStartCycle then 920 + if ShouldEndCycle then
905 begin 921 begin
906 while FormMatrixGame.PopupNotifier.Visible do 922 while FormMatrixGame.PopupNotifier.Visible do
907 Application.ProcessMessages; 923 Application.ProcessMessages;
908 924
909 - if ShouldAskQuestion then // TODO: prompt only when an odd row was selected  
910 - begin  
911 - P.Turn := 0;  
912 - FZMQActor.SendMessage([K_QUESTION,FExperiment.Condition[FExperiment.CurrentCondition].Prompt.Question]);  
913 - end; 925 + //if ShouldAskQuestion then // TODO: prompt only when an odd row was selected
  926 + // begin
  927 + // P.Turn := 0;
  928 + // FZMQActor.SendMessage([K_QUESTION,FExperiment.Condition[FExperiment.CurrentCondition].Prompt.Question]);
  929 + // end;
914 end; 930 end;
915 end; 931 end;
916 932
@@ -967,10 +983,6 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); @@ -967,10 +983,6 @@ procedure TGameControl.ReceiveReply(AReply: TStringList);
967 i: integer; 983 i: integer;
968 P : TPlayer; 984 P : TPlayer;
969 begin 985 begin
970 - {$IFDEF DEBUG}  
971 - WriteLn(Self.ID +' self');  
972 - WriteLn(AReply[0] +' reply');  
973 - {$ENDIF}  
974 if Self.ID = AReply[0] then 986 if Self.ID = AReply[0] then
975 begin 987 begin
976 for i:= 3 to AReply.Count -2 do 988 for i:= 3 to AReply.Count -2 do
@@ -997,6 +1009,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); @@ -997,6 +1009,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList);
997 LConsequence : TConsequence; 1009 LConsequence : TConsequence;
998 LCount, 1010 LCount,
999 i : integer; 1011 i : integer;
  1012 + M : string;
1000 //P : TPlayer; 1013 //P : TPlayer;
1001 begin 1014 begin
1002 if Self.ID = AReply[0] then 1015 if Self.ID = AReply[0] then
@@ -1009,11 +1022,13 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); @@ -1009,11 +1022,13 @@ procedure TGameControl.ReceiveReply(AReply: TStringList);
1009 if LCount > 0 then 1022 if LCount > 0 then
1010 for i := 1 to LCount do 1023 for i := 1 to LCount do
1011 begin 1024 begin
1012 - LConsequence := TConsequence.Create(FormMatrixGame,ExtractDelimited(i,AReply[5],['+']));  
1013 - //LConsequence.PlayerNicname := P.Nicname;  
1014 - LConsequence.Present(False); 1025 + LConsequence := TConsequence.Create(nil,ExtractDelimited(i,AReply[5],['+']));
  1026 + M := LConsequence.GenerateMessage(False);
1015 if LConsequence.ShouldPublishMessage then 1027 if LConsequence.ShouldPublishMessage then
1016 - FZMQActor.SendMessage([K_MESSAGE,LConsequence.LastPresentedMessage]); 1028 + FZMQActor.SendMessage([K_MESSAGE,M])
  1029 + else
  1030 + LConsequence.PresentMessage;
  1031 + LConsequence.PresentPoints;
1017 {$IFDEF DEBUG} 1032 {$IFDEF DEBUG}
1018 WriteLn('A consequence should have shown.'); 1033 WriteLn('A consequence should have shown.');
1019 {$ENDIF} 1034 {$ENDIF}
units/game_experiment.pas
@@ -2,7 +2,7 @@ unit game_experiment; @@ -2,7 +2,7 @@ unit game_experiment;
2 2
3 {$mode objfpc}{$H+} 3 {$mode objfpc}{$H+}
4 4
5 -{$DEFINE DEBUG} 5 +//{$DEFINE DEBUG}
6 6
7 interface 7 interface
8 8
@@ -21,6 +21,7 @@ type @@ -21,6 +21,7 @@ type
21 21
22 TExperiment = class(TComponent) 22 TExperiment = class(TComponent)
23 private 23 private
  24 + FExperimentStart : Boolean;
24 FExperimentAim, 25 FExperimentAim,
25 FExperimentName, 26 FExperimentName,
26 FFilename, 27 FFilename,
@@ -62,6 +63,7 @@ type @@ -62,6 +63,7 @@ type
62 function GetInterlockingsIn(ALastCycles : integer):integer; 63 function GetInterlockingsIn(ALastCycles : integer):integer;
63 function GetConsequenceStringFromChoice(P:TPlayer): Utf8string; 64 function GetConsequenceStringFromChoice(P:TPlayer): Utf8string;
64 function GetConsequenceStringFromChoices:UTF8String; 65 function GetConsequenceStringFromChoices:UTF8String;
  66 + procedure CheckNeedForRandomTurns;
65 procedure SetCondition(I : Integer; AValue: TCondition); 67 procedure SetCondition(I : Integer; AValue: TCondition);
66 procedure SetContingency(ACondition, I : integer; AValue: TContingency); 68 procedure SetContingency(ACondition, I : integer; AValue: TContingency);
67 procedure SetMatrixType(AValue: TGameMatrixType); 69 procedure SetMatrixType(AValue: TGameMatrixType);
@@ -142,7 +144,7 @@ resourcestring @@ -142,7 +144,7 @@ resourcestring
142 144
143 implementation 145 implementation
144 146
145 -uses game_file_methods, game_actors_point, game_resources, string_methods; 147 +uses game_file_methods, game_resources, string_methods;
146 148
147 { TExperiment } 149 { TExperiment }
148 150
@@ -172,9 +174,11 @@ begin @@ -172,9 +174,11 @@ begin
172 Result := StrToInt(FTurnsRandom.Names[FConditions[CurrentCondition].Turn.Count]) 174 Result := StrToInt(FTurnsRandom.Names[FConditions[CurrentCondition].Turn.Count])
173 else 175 else
174 Result := FConditions[CurrentCondition].Turn.Count; 176 Result := FConditions[CurrentCondition].Turn.Count;
  177 +
175 if Assigned(FOnEndTurn) then FOnEndTurn(Self); 178 if Assigned(FOnEndTurn) then FOnEndTurn(Self);
176 - if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then  
177 - Inc(FConditions[CurrentCondition].Turn.Count) 179 +
  180 + if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value-1 then
  181 + Inc(FConditions[CurrentCondition].Turn.Count)
178 else 182 else
179 begin 183 begin
180 FConditions[CurrentCondition].Turn.Count := 0; 184 FConditions[CurrentCondition].Turn.Count := 0;
@@ -188,20 +192,20 @@ end; @@ -188,20 +192,20 @@ end;
188 function TExperiment.GetNextTurnPlayerID: UTF8string; // used during cycles 192 function TExperiment.GetNextTurnPlayerID: UTF8string; // used during cycles
189 begin 193 begin
190 Result := Player[FConditions[CurrentCondition].Turn.Count].ID; 194 Result := Player[FConditions[CurrentCondition].Turn.Count].ID;
191 - GetNextTurn;  
192 end; 195 end;
193 196
194 function TExperiment.GetNextCycle: integer; 197 function TExperiment.GetNextCycle: integer;
195 begin 198 begin
196 Result := FConditions[CurrentCondition].Cycles.Count; 199 Result := FConditions[CurrentCondition].Cycles.Count;
197 if Assigned(FOnEndCycle) then FOnEndCycle(Self); 200 if Assigned(FOnEndCycle) then FOnEndCycle(Self);
198 - if FConditions[CurrentCondition].Cycles.Count < FConditions[CurrentCondition].Cycles.Value then 201 +
  202 + if FConditions[CurrentCondition].Cycles.Count < FConditions[CurrentCondition].Cycles.Value-1 then
199 Inc(FConditions[CurrentCondition].Cycles.Count) 203 Inc(FConditions[CurrentCondition].Cycles.Count)
200 else 204 else
201 begin 205 begin
202 FConditions[CurrentCondition].Cycles.Count := 0; 206 FConditions[CurrentCondition].Cycles.Count := 0;
203 - Inc(FConditions[CurrentCondition].Cycles.Generation);  
204 if Assigned(FOnEndGeneration) then FOnEndGeneration(Self); 207 if Assigned(FOnEndGeneration) then FOnEndGeneration(Self);
  208 + Inc(FConditions[CurrentCondition].Cycles.Generation);
205 NextCondition; 209 NextCondition;
206 end; 210 end;
207 {$IFDEF DEBUG} 211 {$IFDEF DEBUG}
@@ -216,8 +220,8 @@ var @@ -216,8 +220,8 @@ var
216 220
217 procedure EndCondition; 221 procedure EndCondition;
218 begin 222 begin
219 - Inc(FCurrentCondition);  
220 if Assigned(FOnEndCondition) then FOnEndCondition(Self); 223 if Assigned(FOnEndCondition) then FOnEndCondition(Self);
  224 + Inc(FCurrentCondition);
221 end; 225 end;
222 226
223 begin 227 begin
@@ -241,7 +245,7 @@ begin @@ -241,7 +245,7 @@ begin
241 245
242 gecInterlockingPorcentage: 246 gecInterlockingPorcentage:
243 if LInterlocks = FConditions[CurrentCondition].EndCriterium.InterlockingPorcentage then 247 if LInterlocks = FConditions[CurrentCondition].EndCriterium.InterlockingPorcentage then
244 - EndCondition 248 + EndCondition;
245 249
246 end; 250 end;
247 {$IFDEF DEBUG} 251 {$IFDEF DEBUG}
@@ -324,7 +328,7 @@ begin @@ -324,7 +328,7 @@ begin
324 for i :=0 to ContingenciesCount[c] -1 do 328 for i :=0 to ContingenciesCount[c] -1 do
325 if not Contingency[c,i].Meta then 329 if not Contingency[c,i].Meta then
326 if Contingency[c,i].ResponseMeetsCriteriaI(P.Choice.Row,P.Choice.Color) then 330 if Contingency[c,i].ResponseMeetsCriteriaI(P.Choice.Row,P.Choice.Color) then
327 - Result += Contingency[c,i].Consequence.AsString(P.ID) + '+'; 331 + Result += Contingency[c,i].Consequence.AsString(P.ID);
328 end; 332 end;
329 333
330 function TExperiment.GetConsequenceStringFromChoices: UTF8String; 334 function TExperiment.GetConsequenceStringFromChoices: UTF8String;
@@ -337,7 +341,28 @@ begin @@ -337,7 +341,28 @@ begin
337 for i :=0 to ContingenciesCount[c] -1 do 341 for i :=0 to ContingenciesCount[c] -1 do
338 if Contingency[c,i].Meta then 342 if Contingency[c,i].Meta then
339 if Contingency[c,i].ResponseMeetsCriteriaG(FPlayers) then 343 if Contingency[c,i].ResponseMeetsCriteriaG(FPlayers) then
340 - Result += Contingency[c,i].Consequence.AsString(IntToStr(i)) + '+'; 344 + Result += Contingency[c,i].Consequence.AsString(IntToStr(i));
  345 +end;
  346 +
  347 +procedure TExperiment.CheckNeedForRandomTurns;
  348 +var c ,
  349 + i,
  350 + r : integer;
  351 +begin
  352 + if Condition[CurrentCondition].Turn.Random then
  353 + begin
  354 + FTurnsRandom.Clear;
  355 + for i:= 0 to Condition[CurrentCondition].Turn.Value-1 do
  356 + FTurnsRandom.Add(IntToStr(i));
  357 +
  358 + c := FTurnsRandom.Count - 1;
  359 + for i := 0 to c do
  360 + begin
  361 + r := Random(c);
  362 + while r = i do r := Random(c);
  363 + FTurnsRandom.Exchange(r,i);
  364 + end;
  365 + end;
341 end; 366 end;
342 367
343 procedure TExperiment.SetCondition(I : Integer; AValue: TCondition); 368 procedure TExperiment.SetCondition(I : Integer; AValue: TCondition);
@@ -458,30 +483,17 @@ end; @@ -458,30 +483,17 @@ end;
458 constructor TExperiment.Create(AOwner: TComponent); 483 constructor TExperiment.Create(AOwner: TComponent);
459 begin 484 begin
460 inherited Create(AOwner); 485 inherited Create(AOwner);
  486 + FTurnsRandom := TStringList.Create;
461 LoadExperimentFromResource(Self); 487 LoadExperimentFromResource(Self);
  488 + CheckNeedForRandomTurns;
462 end; 489 end;
463 490
464 constructor TExperiment.Create(AFilename: string;AOwner:TComponent); 491 constructor TExperiment.Create(AFilename: string;AOwner:TComponent);
465 -var c ,  
466 - i,  
467 - r : integer;  
468 begin 492 begin
469 inherited Create(AOwner); 493 inherited Create(AOwner);
470 FTurnsRandom := TStringList.Create; 494 FTurnsRandom := TStringList.Create;
471 LoadExperimentFromFile(Self,AFilename); 495 LoadExperimentFromFile(Self,AFilename);
472 - if Condition[CurrentCondition].Turn.Random then  
473 - begin  
474 - for i:= 0 to Condition[CurrentCondition].Turn.Value-1 do  
475 - FTurnsRandom.Add(IntToStr(i));  
476 -  
477 - c := FTurnsRandom.Count - 1;  
478 - for i := 0 to c do  
479 - begin  
480 - r := Random(c);  
481 - while r = i do r := Random(c);  
482 - FTurnsRandom.Exchange(r,i);  
483 - end;  
484 - end; 496 + CheckNeedForRandomTurns;
485 end; 497 end;
486 498
487 destructor TExperiment.Destroy; 499 destructor TExperiment.Destroy;
@@ -495,6 +507,7 @@ begin @@ -495,6 +507,7 @@ begin
495 Result := LoadExperimentFromFile(Self, AFilename); 507 Result := LoadExperimentFromFile(Self, AFilename);
496 if Result then 508 if Result then
497 FFilename := AFilename; 509 FFilename := AFilename;
  510 + CheckNeedForRandomTurns;
498 end; 511 end;
499 512
500 function TExperiment.LoadFromGenerator: Boolean; 513 function TExperiment.LoadFromGenerator: Boolean;
@@ -502,6 +515,7 @@ begin @@ -502,6 +515,7 @@ begin
502 Result := LoadExperimentFromResource(Self); 515 Result := LoadExperimentFromResource(Self);
503 if Result then 516 if Result then
504 FFilename := GetCurrentDir + PathDelim + FResearcher + PathDelim; 517 FFilename := GetCurrentDir + PathDelim + FResearcher + PathDelim;
  518 + CheckNeedForRandomTurns;
505 end; 519 end;
506 520
507 function TExperiment.AppendCondition: integer; 521 function TExperiment.AppendCondition: integer;
units/game_file_methods.pas
@@ -30,7 +30,7 @@ resourcestring @@ -30,7 +30,7 @@ resourcestring
30 30
31 implementation 31 implementation
32 32
33 -uses LCLIntf, game_actors_point, game_resources, string_methods, regdata, zhelpers, strutils; 33 +uses LCLIntf, game_resources, string_methods, regdata, zhelpers, strutils;
34 34
35 function LoadExperimentFromResource(var AExperiment: TExperiment): Boolean; 35 function LoadExperimentFromResource(var AExperiment: TExperiment): Boolean;
36 var 36 var
@@ -91,9 +91,9 @@ begin @@ -91,9 +91,9 @@ begin
91 Contingencies[0] := TContingency.Create(AExperiment,LConcequence,LCriteria1,False); 91 Contingencies[0] := TContingency.Create(AExperiment,LConcequence,LCriteria1,False);
92 LConcequence := TConsequence.Create(AExperiment,3,[gscPoints, gscA, gscMessage,gscBroadcastMessage],['$NICNAME','pão','pães']); 92 LConcequence := TConsequence.Create(AExperiment,3,[gscPoints, gscA, gscMessage,gscBroadcastMessage],['$NICNAME','pão','pães']);
93 Contingencies[1] := TContingency.Create(AExperiment,LConcequence,LCriteria2,False); 93 Contingencies[1] := TContingency.Create(AExperiment,LConcequence,LCriteria2,False);
94 - LConcequence := TConsequence.Create(AExperiment,1,[gscPoints, gscG, gscMessage,gscBroadcastMessage],['','item escolar','itens escolares']); 94 + LConcequence := TConsequence.Create(AExperiment,1,[gscPoints, gscG, gscMessage],['','item escolar','itens escolares']);
95 Contingencies[2] := TContingency.Create(AExperiment,LConcequence,LCriteria3,True); 95 Contingencies[2] := TContingency.Create(AExperiment,LConcequence,LCriteria3,True);
96 - LConcequence := TConsequence.Create(AExperiment,-1,[gscPoints, gscG, gscMessage,gscBroadcastMessage],['','item escolar','itens escolares']); 96 + LConcequence := TConsequence.Create(AExperiment,-1,[gscPoints, gscG, gscMessage],['','item escolar','itens escolares']);
97 Contingencies[3] := TContingency.Create(AExperiment,LConcequence,LCriteria4,True); 97 Contingencies[3] := TContingency.Create(AExperiment,LConcequence,LCriteria4,True);
98 98
99 Prompt := TPrompt.Create( 99 Prompt := TPrompt.Create(
units/zmq_network.pas
@@ -11,7 +11,7 @@ unit zmq_network; @@ -11,7 +11,7 @@ unit zmq_network;
11 11
12 {$mode objfpc}{$H+} 12 {$mode objfpc}{$H+}
13 13
14 -{$DEFINE DEBUG} 14 +//{$DEFINE DEBUG}
15 15
16 interface 16 interface
17 17
@@ -130,7 +130,7 @@ begin @@ -130,7 +130,7 @@ begin
130 Synchronize(@MessageReceived); 130 Synchronize(@MessageReceived);
131 end; 131 end;
132 {$IFDEF DEBUG} 132 {$IFDEF DEBUG}
133 - WriteLn('Server4:FPoller:',FPoller.PollNumber); 133 + WriteLn('Client:Received:',LPollEvent,',',LMessagesCount);
134 {$ENDIF} 134 {$ENDIF}
135 end; 135 end;
136 end; 136 end;
@@ -236,24 +236,21 @@ begin @@ -236,24 +236,21 @@ begin
236 if pePollIn in FPoller.PollItem[0].revents then 236 if pePollIn in FPoller.PollItem[0].revents then
237 begin 237 begin
238 LMultipartMessage.Clear; 238 LMultipartMessage.Clear;
239 - {$IFDEF DEBUG}  
240 - WriteLn('pull':LPollCount);  
241 - {$ENDIF}  
242 LMessagesCount := FPuller_PUB.recv(LMultipartMessage); 239 LMessagesCount := FPuller_PUB.recv(LMultipartMessage);
243 if LMessagesCount > 0 then 240 if LMessagesCount > 0 then
244 begin 241 begin
245 FMessage := LMultipartMessage; 242 FMessage := LMultipartMessage;
246 Synchronize(@MessageReceived); 243 Synchronize(@MessageReceived);
247 FPublisher.send(LMultiPartMessage); 244 FPublisher.send(LMultiPartMessage);
  245 + {$IFDEF DEBUG}
  246 + WriteLn('Server:Published:',LPollCount,',',LMessagesCount);
  247 + {$ENDIF}
248 end; 248 end;
249 end; 249 end;
250 250
251 if pePollIn in FPoller.PollItem[1].revents then 251 if pePollIn in FPoller.PollItem[1].revents then
252 begin 252 begin
253 LMultipartMessage.Clear; 253 LMultipartMessage.Clear;
254 - {$IFDEF DEBUG}  
255 - WriteLn('rep:',LPollCount);  
256 - {$ENDIF}  
257 LMessagesCount := FPuller_REP.recv(LMultipartMessage); 254 LMessagesCount := FPuller_REP.recv(LMultipartMessage);
258 if LMessagesCount > 2 then 255 if LMessagesCount > 2 then
259 begin 256 begin
@@ -261,6 +258,9 @@ begin @@ -261,6 +258,9 @@ begin
261 Synchronize(@RequestReceived); LMultipartMessage := FMessage; S := TStringList.Create; 258 Synchronize(@RequestReceived); LMultipartMessage := FMessage; S := TStringList.Create;
262 FReplier.recv(S); S.Free; 259 FReplier.recv(S); S.Free;
263 FReplier.send(LMultipartMessage); 260 FReplier.send(LMultipartMessage);
  261 + {$IFDEF DEBUG}
  262 + WriteLn('Server:Replied:',LPollCount,',',LMessagesCount);
  263 + {$ENDIF}
264 end; 264 end;
265 end; 265 end;
266 end; 266 end;