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