From eac0a6c9848d4f7968c89cf0f66c7963fded2956 Mon Sep 17 00:00:00 2001 From: cpicanco Date: Sun, 27 Nov 2016 22:41:28 -0300 Subject: [PATCH] implement group, A and B messages,also fix turn, cycle count conditionals --- units/game_actors.pas | 82 ++++++++++++++++++++++++++++++++++++++++++++++------------------------------------ units/game_control.pas | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- units/game_experiment.pas | 68 +++++++++++++++++++++++++++++++++++++++++--------------------------- units/game_file_methods.pas | 6 +++--- units/zmq_network.pas | 16 ++++++++-------- 5 files changed, 160 insertions(+), 121 deletions(-) diff --git a/units/game_actors.pas b/units/game_actors.pas index ec5a2d0..4f60a25 100644 --- a/units/game_actors.pas +++ b/units/game_actors.pas @@ -5,7 +5,7 @@ unit game_actors; interface uses - Classes, SysUtils, Forms,PopupNotifier + Classes, SysUtils, Forms,PopupNotifier, ExtCtrls , game_actors_point ; type @@ -80,26 +80,26 @@ type private FAppendicePlural: string; FAppendiceSingular: string; - FLastPresentedMessage: string; FNicname: string; FStyle : TConsequenceStyle; FP : TGamePoint; + FTimer : TTimer; FMessage : TPopupNotifier; function GetShouldPublishMessage: Boolean; protected FConsequenceByPlayerID : TStringList; procedure StopTimer(Sender:TObject;var ACloseAction:TCloseAction); - procedure TimerTimer(Sender:TOBject);virtual; + procedure SelfDestroy(Sender:TOBject);virtual; public constructor Create(AOwner:TComponent; AP:TGamePoint; AStyle:TConsequenceStyle; AAppendiceSingular,AAppendicePlural:string);overload; constructor Create(AOwner:TComponent; AP:integer; AStyle: TConsequenceStyle; AMessage:array of string);overload; constructor Create(AOwner:TComponent; AConsequenceString: string);virtual;overload; destructor Destroy;override; function AsString(AID :string): string; - function PointMessage(ForGroup: Boolean):string; - procedure Present(ForGroup: Boolean); + function GenerateMessage(ForGroup: Boolean):string; + procedure PresentMessage; + procedure PresentPoints; property ShouldPublishMessage : Boolean read GetShouldPublishMessage; - property LastPresentedMessage : string read FLastPresentedMessage; property PlayerNicname : string read FNicname write FNicname; property AppendiceSingular : string read FAppendiceSingular; property AppendicePlural : string read FAppendicePlural; @@ -248,7 +248,7 @@ begin Result += '|'; end; -function TContingency.ResponseMeetsCriteriaI(R : TGameRow; C : TGameColor): Boolean; +function TContingency.ResponseMeetsCriteriaI(R : TGameRow; C : TGameColor): Boolean; // should be for admin only var LMod : TGameRow; LRow, LColor:Boolean; @@ -270,7 +270,7 @@ begin CriteriaEvent; end; -function TContingency.ResponseMeetsCriteriaG(Players: TPlayers): Boolean; +function TContingency.ResponseMeetsCriteriaG(Players: TPlayers): Boolean; // must be for admin only var i : integer; Cs : array of TGameColor; Rs : array of TGameRow; @@ -509,11 +509,12 @@ constructor TConsequence.Create(AOwner: TComponent; AP: integer; AStyle:TConsequenceStyle; AMessage: array of string); begin inherited Create(AOwner); + FP := TGamePoint.Create(AOwner,AP); FStyle:=AStyle; FNicname:=AMessage[0]; FAppendiceSingular:=AMessage[1]; FAppendicePlural:=AMessage[2]; - FP := TGamePoint.Create(AOwner,AP); + FMessage := TPopupNotifier.Create(AOwner); FConsequenceByPlayerID := TStringList.Create; end; @@ -527,7 +528,12 @@ begin FNicname:=ExtractDelimited(3,AConsequenceString,['|']); FAppendiceSingular:=ExtractDelimited(4,AConsequenceString,['|']); FAppendicePlural:=ExtractDelimited(5,AConsequenceString,['|']); - FMessage := TPopupNotifier.Create(AOwner); + + FMessage := TPopupNotifier.Create(Self); + FTimer := TTimer.Create(Self); + FTimer.Enabled:=False; + FTimer.Interval:=6000; + FTimer.OnTimer:=@SelfDestroy; FConsequenceByPlayerID := TStringList.Create; end; @@ -543,40 +549,47 @@ begin Result += GetConsequenceStylesString(FStyle)+'|'; Result += FNicname +'|'; Result += FAppendiceSingular + '|'; - Result += FAppendicePlural + '|'; + Result += FAppendicePlural + '|+'; FConsequenceByPlayerID.Values[AID]:=Result; end; -function TConsequence.PointMessage(ForGroup: Boolean): string; +function TConsequence.GenerateMessage(ForGroup: Boolean): string; begin Result := FP.PointMessage(FNicname,FAppendicePlural, FAppendiceSingular,ForGroup); + FMessage.Text := Result; +end; +procedure TConsequence.PresentMessage; +var + PopUpPos : TPoint; +begin if gscA in FStyle then - FormMatrixGame.LabelIndACount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndACount.Caption) + FP.ResultAsInteger); + begin + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110; + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; + end; if gscB in FStyle then - FormMatrixGame.LabelIndBCount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndBCount.Caption) + FP.ResultAsInteger); + begin + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left+110; + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; + end; if gscG in FStyle then - FormMatrixGame.LabelGroupCount.Caption:= IntToStr(StrToInt(FormMatrixGame.LabelGroupCount.Caption) + FP.ResultAsInteger); -end; - - -procedure TConsequence.Present(ForGroup: Boolean); -var - PopUpPos : TPoint; -begin - PopUpPos.X := FormMatrixGame.GBIndividualAB.Left; - PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; + begin + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110; + PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height+100; + end; PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos); - FMessage.Color:=clTeal; FMessage.Title:=''; - FMessage.Text := FP.PointMessage(FNicname,FAppendicePlural, FAppendiceSingular,ForGroup); - FLastPresentedMessage := FMessage.Text; - FMessage.OnClose:=@StopTimer; - FormMatrixGame.Timer.OnTimer := @TimerTimer; + FMessage.ShowAtPos(PopUpPos.X, PopUpPos.Y); + FTimer.Enabled:=True; +end; +procedure TConsequence.PresentPoints; +begin + //is gscPoints in FStyle then just in case... if gscA in FStyle then FormMatrixGame.LabelIndACount.Caption := IntToStr(StrToInt(FormMatrixGame.LabelIndACount.Caption) + FP.ResultAsInteger); @@ -585,13 +598,9 @@ begin if gscG in FStyle then FormMatrixGame.LabelGroupCount.Caption:= IntToStr(StrToInt(FormMatrixGame.LabelGroupCount.Caption) + FP.ResultAsInteger); - - if gscBroadcastMessage in FStyle then Exit; - FMessage.ShowAtPos(PopUpPos.X, PopUpPos.Y); - FormMatrixGame.Timer.Enabled:=True; end; -function TConsequence.GetShouldPublishMessage: Boolean; +function TConsequence.GetShouldPublishMessage: Boolean; // for players only begin Result := gscBroadcastMessage in FStyle; end; @@ -599,12 +608,13 @@ end; procedure TConsequence.StopTimer(Sender: TObject; var ACloseAction: TCloseAction ); begin - FormMatrixGame.Timer.Enabled:=False; + //FormMatrixGame.Timer.Enabled:=False; end; -procedure TConsequence.TimerTimer(Sender: TOBject); +procedure TConsequence.SelfDestroy(Sender: TOBject); begin FMessage.Visible:=False; + Free; end; diff --git a/units/game_control.pas b/units/game_control.pas index 4230cb6..e91e53c 100644 --- a/units/game_control.pas +++ b/units/game_control.pas @@ -2,7 +2,7 @@ unit game_control; {$mode objfpc}{$H+} -{$DEFINE DEBUG} +//{$DEFINE DEBUG} interface @@ -49,7 +49,8 @@ type procedure CleanMatrix(AEnabled : Boolean); procedure EnablePlayerMatrix(AID:UTF8string; ATurn:integer; AEnabled:Boolean); private - function ShouldStartCycle : Boolean; + function ShouldStartExperiment: Boolean; + function ShouldEndCycle : Boolean; function ShouldAskQuestion : Boolean; procedure KickPlayer(AID:string); procedure NextTurn(Sender: TObject); @@ -130,15 +131,20 @@ end; { TGameControl } -function TGameControl.ShouldStartCycle: Boolean; // starts experiment too +function TGameControl.ShouldStartExperiment: Boolean; begin Result := FExperiment.PlayersCount = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value; end; +function TGameControl.ShouldEndCycle: Boolean; +begin + Result := FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value-1; +end; + function TGameControl.ShouldAskQuestion: Boolean; // end cycle, restart alias begin // TODO: prompt only when an odd row was selected - Result := ShouldStartCycle and FExperiment.Condition[FExperiment.CurrentCondition].Contingencies[3].Fired; + Result := ShouldEndCycle and FExperiment.Condition[FExperiment.CurrentCondition].Contingencies[3].Fired; end; procedure TGameControl.KickPlayer(AID: string); @@ -149,27 +155,35 @@ end; procedure TGameControl.NextTurn(Sender: TObject); begin // update admin view - FormMatrixGame.LabelExpCountTurn.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count); - - // inform players - + FormMatrixGame.LabelExpCountTurn.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count+1); end; procedure TGameControl.NextCycle(Sender: TObject); +var + i, + LCount : integer; + LConsequences : string; begin // prompt question to all players - FormMatrixGame.LabelExpCountCycle.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Count); + FormMatrixGame.LabelExpCountCycle.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Count+1); {$IFDEF DEBUG} - WriteLn('cycle:',FExperiment.ConsequenceStringFromChoices); + WriteLn('cycle:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); {$ENDIF} - //FZMQActor.SendMessage([K_CYCLES]) + + + //P := FExperiment.PlayerFromID[Self.ID]; + LConsequences := FExperiment.ConsequenceStringFromChoices; + LCount := WordCount(LConsequences,['+']); + if LCount > 0 then + for i := 1 to LCount do + FZMQActor.SendMessage([K_CYCLES,ExtractDelimited(i,LConsequences,['+'])]); // as string generates the pts result end; procedure TGameControl.NextLineage(Sender: TObject); begin // pause, kick older player, wait for new player, resume - FormMatrixGame.LabelExpCountGeneration.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Generation); + FormMatrixGame.LabelExpCountGeneration.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Generation+1); end; procedure TGameControl.NextCondition(Sender: TObject); @@ -186,7 +200,7 @@ end; procedure TGameControl.Interlocking(Sender: TObject); begin - FormMatrixGame.LabelExpCountInterlocks.Caption:= IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Interlocks.Count); + FormMatrixGame.LabelExpCountInterlocks.Caption:= IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Interlocks.Count+1); end; @@ -410,7 +424,7 @@ end; procedure TGameControl.ShowPopUp(AText: string); var PopUpPos : TPoint; begin - PopUpPos.X := FormMatrixGame.GBIndividualAB.Left; + PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110; PopUpPos.Y := FormMatrixGame.GBIndividualAB.Top+FormMatrixGame.GBIndividual.Height-10; PopUpPos := FormMatrixGame.ClientToScreen(PopUpPos); FormMatrixGame.PopupNotifier.Title:=''; @@ -473,12 +487,12 @@ begin FExperiment.OnInterlocking:=@Interlocking; FExperiment.OnConsequence:=@Consequence; - NextTurn(Self); - NextCycle(Self); - NextLineage(Self); - NextCondition(Self); - Interlocking(Self); - Consequence(Self); + //NextTurn(Self); + //NextCycle(Self); + //NextLineage(Self); + //NextCondition(Self); + //Interlocking(Self); + //Consequence(Self); SendRequest(K_LOGIN); end; @@ -623,7 +637,7 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); case FActor of gaPlayer:begin - if FExperiment.PlayersCount = P.Turn+1 then + if P.Turn = FExperiment.PlayersCount-1 then begin // update next turn if Self.ID = P.ID then @@ -632,12 +646,12 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); FExperiment.Player[Self.ID] := P; end; - // no wait turns - // EnablePlayerMatrix(Self.ID,0, True); - //CleanMatrix; CleanMatrix(False); + // no wait turns + EnablePlayerMatrix(Self.ID,0, True); + // wait for server Exit; end; @@ -673,14 +687,16 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); end; procedure OnEndCycle; + var + LConsequence : TConsequence; begin - // Updata turn - - // case FActor of gaPlayer: begin - + LConsequence := TConsequence.Create(nil,AMessage[1]); + LConsequence.GenerateMessage(True); + LConsequence.PresentPoints; + LConsequence.PresentMessage; end; end; end; @@ -781,7 +797,7 @@ begin if MHas(K_KICK) then SayGoodBye; if MHas(K_START) then NotifyPlayers; if MHas(K_CYCLES) then OnEndCycle; - if MHas(K_QUESTION) then ShowQuestion; + //if MHas(K_QUESTION) then ShowQuestion; //if MHas(K_QMESSAGE) then QuestionMessages; end; @@ -800,9 +816,6 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); begin if not FExperiment.PlayerIsPlaying[ARequest[0]] then begin - {$IFDEF DEBUG} - WriteLn(FExperiment.PlayersCount,'<',FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value); - {$ENDIF} if FExperiment.PlayersCount < FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value then begin // ok, let player login @@ -860,7 +873,7 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); FZMQActor.SendMessage([K_ARRIVED,PS]); // start Experiment - if ShouldStartCycle then + if ShouldStartExperiment then StartExperiment; end @@ -879,6 +892,9 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); var P : TPlayer; S : string; begin + {$IFDEF DEBUG} + WriteLn('Count:>>>>>>>>>>>>>>>>>>>>>>>>>>>',FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count, '<', FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value); + {$ENDIF} P := FExperiment.PlayerFromID[ARequest[0]]; P.Choice.Row:= GetRowFromString(ARequest[3]); // row P.Choice.Color:= GetGameColorFromString(ARequest[4]); // color @@ -901,16 +917,16 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); // broadcast choice FZMQActor.SendMessage([K_CHOICE,P.ID,ARequest[3],ARequest[4],IntToStr(P.Turn)]); - if ShouldStartCycle then + if ShouldEndCycle then begin while FormMatrixGame.PopupNotifier.Visible do Application.ProcessMessages; - if ShouldAskQuestion then // TODO: prompt only when an odd row was selected - begin - P.Turn := 0; - FZMQActor.SendMessage([K_QUESTION,FExperiment.Condition[FExperiment.CurrentCondition].Prompt.Question]); - end; + //if ShouldAskQuestion then // TODO: prompt only when an odd row was selected + // begin + // P.Turn := 0; + // FZMQActor.SendMessage([K_QUESTION,FExperiment.Condition[FExperiment.CurrentCondition].Prompt.Question]); + // end; end; end; @@ -967,10 +983,6 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); i: integer; P : TPlayer; begin - {$IFDEF DEBUG} - WriteLn(Self.ID +' self'); - WriteLn(AReply[0] +' reply'); - {$ENDIF} if Self.ID = AReply[0] then begin for i:= 3 to AReply.Count -2 do @@ -997,6 +1009,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); LConsequence : TConsequence; LCount, i : integer; + M : string; //P : TPlayer; begin if Self.ID = AReply[0] then @@ -1009,11 +1022,13 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); if LCount > 0 then for i := 1 to LCount do begin - LConsequence := TConsequence.Create(FormMatrixGame,ExtractDelimited(i,AReply[5],['+'])); - //LConsequence.PlayerNicname := P.Nicname; - LConsequence.Present(False); + LConsequence := TConsequence.Create(nil,ExtractDelimited(i,AReply[5],['+'])); + M := LConsequence.GenerateMessage(False); if LConsequence.ShouldPublishMessage then - FZMQActor.SendMessage([K_MESSAGE,LConsequence.LastPresentedMessage]); + FZMQActor.SendMessage([K_MESSAGE,M]) + else + LConsequence.PresentMessage; + LConsequence.PresentPoints; {$IFDEF DEBUG} WriteLn('A consequence should have shown.'); {$ENDIF} diff --git a/units/game_experiment.pas b/units/game_experiment.pas index 3c426eb..ee08744 100644 --- a/units/game_experiment.pas +++ b/units/game_experiment.pas @@ -2,7 +2,7 @@ unit game_experiment; {$mode objfpc}{$H+} -{$DEFINE DEBUG} +//{$DEFINE DEBUG} interface @@ -21,6 +21,7 @@ type TExperiment = class(TComponent) private + FExperimentStart : Boolean; FExperimentAim, FExperimentName, FFilename, @@ -62,6 +63,7 @@ type function GetInterlockingsIn(ALastCycles : integer):integer; function GetConsequenceStringFromChoice(P:TPlayer): Utf8string; function GetConsequenceStringFromChoices:UTF8String; + procedure CheckNeedForRandomTurns; procedure SetCondition(I : Integer; AValue: TCondition); procedure SetContingency(ACondition, I : integer; AValue: TContingency); procedure SetMatrixType(AValue: TGameMatrixType); @@ -142,7 +144,7 @@ resourcestring implementation -uses game_file_methods, game_actors_point, game_resources, string_methods; +uses game_file_methods, game_resources, string_methods; { TExperiment } @@ -172,9 +174,11 @@ begin Result := StrToInt(FTurnsRandom.Names[FConditions[CurrentCondition].Turn.Count]) else Result := FConditions[CurrentCondition].Turn.Count; + if Assigned(FOnEndTurn) then FOnEndTurn(Self); - if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then - Inc(FConditions[CurrentCondition].Turn.Count) + + if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value-1 then + Inc(FConditions[CurrentCondition].Turn.Count) else begin FConditions[CurrentCondition].Turn.Count := 0; @@ -188,20 +192,20 @@ end; function TExperiment.GetNextTurnPlayerID: UTF8string; // used during cycles begin Result := Player[FConditions[CurrentCondition].Turn.Count].ID; - GetNextTurn; end; function TExperiment.GetNextCycle: integer; begin Result := FConditions[CurrentCondition].Cycles.Count; if Assigned(FOnEndCycle) then FOnEndCycle(Self); - if FConditions[CurrentCondition].Cycles.Count < FConditions[CurrentCondition].Cycles.Value then + + if FConditions[CurrentCondition].Cycles.Count < FConditions[CurrentCondition].Cycles.Value-1 then Inc(FConditions[CurrentCondition].Cycles.Count) else begin FConditions[CurrentCondition].Cycles.Count := 0; - Inc(FConditions[CurrentCondition].Cycles.Generation); if Assigned(FOnEndGeneration) then FOnEndGeneration(Self); + Inc(FConditions[CurrentCondition].Cycles.Generation); NextCondition; end; {$IFDEF DEBUG} @@ -216,8 +220,8 @@ var procedure EndCondition; begin - Inc(FCurrentCondition); if Assigned(FOnEndCondition) then FOnEndCondition(Self); + Inc(FCurrentCondition); end; begin @@ -241,7 +245,7 @@ begin gecInterlockingPorcentage: if LInterlocks = FConditions[CurrentCondition].EndCriterium.InterlockingPorcentage then - EndCondition + EndCondition; end; {$IFDEF DEBUG} @@ -324,7 +328,7 @@ begin for i :=0 to ContingenciesCount[c] -1 do if not Contingency[c,i].Meta then if Contingency[c,i].ResponseMeetsCriteriaI(P.Choice.Row,P.Choice.Color) then - Result += Contingency[c,i].Consequence.AsString(P.ID) + '+'; + Result += Contingency[c,i].Consequence.AsString(P.ID); end; function TExperiment.GetConsequenceStringFromChoices: UTF8String; @@ -337,7 +341,28 @@ begin for i :=0 to ContingenciesCount[c] -1 do if Contingency[c,i].Meta then if Contingency[c,i].ResponseMeetsCriteriaG(FPlayers) then - Result += Contingency[c,i].Consequence.AsString(IntToStr(i)) + '+'; + Result += Contingency[c,i].Consequence.AsString(IntToStr(i)); +end; + +procedure TExperiment.CheckNeedForRandomTurns; +var c , + i, + r : integer; +begin + if Condition[CurrentCondition].Turn.Random then + begin + FTurnsRandom.Clear; + for i:= 0 to Condition[CurrentCondition].Turn.Value-1 do + FTurnsRandom.Add(IntToStr(i)); + + c := FTurnsRandom.Count - 1; + for i := 0 to c do + begin + r := Random(c); + while r = i do r := Random(c); + FTurnsRandom.Exchange(r,i); + end; + end; end; procedure TExperiment.SetCondition(I : Integer; AValue: TCondition); @@ -458,30 +483,17 @@ end; constructor TExperiment.Create(AOwner: TComponent); begin inherited Create(AOwner); + FTurnsRandom := TStringList.Create; LoadExperimentFromResource(Self); + CheckNeedForRandomTurns; end; constructor TExperiment.Create(AFilename: string;AOwner:TComponent); -var c , - i, - r : integer; begin inherited Create(AOwner); FTurnsRandom := TStringList.Create; LoadExperimentFromFile(Self,AFilename); - if Condition[CurrentCondition].Turn.Random then - begin - for i:= 0 to Condition[CurrentCondition].Turn.Value-1 do - FTurnsRandom.Add(IntToStr(i)); - - c := FTurnsRandom.Count - 1; - for i := 0 to c do - begin - r := Random(c); - while r = i do r := Random(c); - FTurnsRandom.Exchange(r,i); - end; - end; + CheckNeedForRandomTurns; end; destructor TExperiment.Destroy; @@ -495,6 +507,7 @@ begin Result := LoadExperimentFromFile(Self, AFilename); if Result then FFilename := AFilename; + CheckNeedForRandomTurns; end; function TExperiment.LoadFromGenerator: Boolean; @@ -502,6 +515,7 @@ begin Result := LoadExperimentFromResource(Self); if Result then FFilename := GetCurrentDir + PathDelim + FResearcher + PathDelim; + CheckNeedForRandomTurns; end; function TExperiment.AppendCondition: integer; diff --git a/units/game_file_methods.pas b/units/game_file_methods.pas index 4b64b9d..268b058 100644 --- a/units/game_file_methods.pas +++ b/units/game_file_methods.pas @@ -30,7 +30,7 @@ resourcestring implementation -uses LCLIntf, game_actors_point, game_resources, string_methods, regdata, zhelpers, strutils; +uses LCLIntf, game_resources, string_methods, regdata, zhelpers, strutils; function LoadExperimentFromResource(var AExperiment: TExperiment): Boolean; var @@ -91,9 +91,9 @@ begin Contingencies[0] := TContingency.Create(AExperiment,LConcequence,LCriteria1,False); LConcequence := TConsequence.Create(AExperiment,3,[gscPoints, gscA, gscMessage,gscBroadcastMessage],['$NICNAME','pão','pães']); Contingencies[1] := TContingency.Create(AExperiment,LConcequence,LCriteria2,False); - LConcequence := TConsequence.Create(AExperiment,1,[gscPoints, gscG, gscMessage,gscBroadcastMessage],['','item escolar','itens escolares']); + LConcequence := TConsequence.Create(AExperiment,1,[gscPoints, gscG, gscMessage],['','item escolar','itens escolares']); Contingencies[2] := TContingency.Create(AExperiment,LConcequence,LCriteria3,True); - LConcequence := TConsequence.Create(AExperiment,-1,[gscPoints, gscG, gscMessage,gscBroadcastMessage],['','item escolar','itens escolares']); + LConcequence := TConsequence.Create(AExperiment,-1,[gscPoints, gscG, gscMessage],['','item escolar','itens escolares']); Contingencies[3] := TContingency.Create(AExperiment,LConcequence,LCriteria4,True); Prompt := TPrompt.Create( diff --git a/units/zmq_network.pas b/units/zmq_network.pas index ca12043..6ad4959 100644 --- a/units/zmq_network.pas +++ b/units/zmq_network.pas @@ -11,7 +11,7 @@ unit zmq_network; {$mode objfpc}{$H+} -{$DEFINE DEBUG} +//{$DEFINE DEBUG} interface @@ -130,7 +130,7 @@ begin Synchronize(@MessageReceived); end; {$IFDEF DEBUG} - WriteLn('Server4:FPoller:',FPoller.PollNumber); + WriteLn('Client:Received:',LPollEvent,',',LMessagesCount); {$ENDIF} end; end; @@ -236,24 +236,21 @@ begin if pePollIn in FPoller.PollItem[0].revents then begin LMultipartMessage.Clear; - {$IFDEF DEBUG} - WriteLn('pull':LPollCount); - {$ENDIF} LMessagesCount := FPuller_PUB.recv(LMultipartMessage); if LMessagesCount > 0 then begin FMessage := LMultipartMessage; Synchronize(@MessageReceived); FPublisher.send(LMultiPartMessage); + {$IFDEF DEBUG} + WriteLn('Server:Published:',LPollCount,',',LMessagesCount); + {$ENDIF} end; end; if pePollIn in FPoller.PollItem[1].revents then begin LMultipartMessage.Clear; - {$IFDEF DEBUG} - WriteLn('rep:',LPollCount); - {$ENDIF} LMessagesCount := FPuller_REP.recv(LMultipartMessage); if LMessagesCount > 2 then begin @@ -261,6 +258,9 @@ begin Synchronize(@RequestReceived); LMultipartMessage := FMessage; S := TStringList.Create; FReplier.recv(S); S.Free; FReplier.send(LMultipartMessage); + {$IFDEF DEBUG} + WriteLn('Server:Replied:',LPollCount,',',LMessagesCount); + {$ENDIF} end; end; end; -- libgit2 0.21.2