From eeff651b8083cc60a24eeec256a8092617549773 Mon Sep 17 00:00:00 2001 From: cpicanco Date: Wed, 23 Nov 2016 17:41:00 -0300 Subject: [PATCH] add prototype workflow --- units/game_control.pas | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- units/game_experiment.pas | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 118 insertions(+), 50 deletions(-) diff --git a/units/game_control.pas b/units/game_control.pas index 2ec4ad8..82134e3 100644 --- a/units/game_control.pas +++ b/units/game_control.pas @@ -45,16 +45,21 @@ type private function CanStartExperiment : Boolean; procedure KickPlayer(AID:string); - procedure StartCycle; - procedure StartCondition; - procedure StartExperiment; - procedure StartTurn; + procedure NextTurn(Sender: TObject); + procedure NextCycle(Sender: TObject); + procedure NextLineage(Sender: TObject); + procedure NextCondition(Sender: TObject); + procedure EndExperiment(Sender: TObject); public constructor Create(AOwner : TComponent);override; destructor Destroy; override; procedure SetMatrix; procedure SendRequest(ARequest : UTF8string); procedure SendMessage(AMessage : UTF8string); + procedure Cancel; + procedure Start; + procedure Pause; + procedure Resume; property Experiment : TExperiment read FExperiment write FExperiment; property ID : string read FID; property RowBase : integer read FRowBase write SetRowBase; @@ -76,6 +81,7 @@ const K_DATA_A = '.Data'; K_LOGIN = '.Login'; K_KICK = '.Kick'; + K_QUESTION = '.Question'; // K_STATUS = '.Status'; K_CYCLES = '.OnCycleStart'; @@ -119,6 +125,52 @@ begin FZMQActor.SendMessage([K_KICK, AID]); end; +procedure TGameControl.NextTurn(Sender: TObject); +begin + // inform players +end; + +procedure TGameControl.NextCycle(Sender: TObject); +begin + // prompt question to all players +end; + +procedure TGameControl.NextLineage(Sender: TObject); +begin + +end; + +procedure TGameControl.NextCondition(Sender: TObject); +begin + // append OnStart data + //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.A; + //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.B; + //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.G; + + // append which player +end; + +procedure TGameControl.EndExperiment(Sender: TObject); +begin + +end; + +procedure TGameControl.Start; +begin + // basic data/csv setup + // wait for players +end; + +procedure TGameControl.Pause; +begin + +end; + +procedure TGameControl.Resume; +begin + +end; + function TGameControl.GetPlayerBox(AID: string): TPlayerBox; var i : integer; begin @@ -251,26 +303,6 @@ begin FRowBase:=AValue; end; -procedure TGameControl.StartCycle; -begin - -end; - -procedure TGameControl.StartCondition; -begin - // append OnStart data - //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.A; - //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.B; - //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.G; - - // append which player -end; - -procedure TGameControl.StartExperiment; -begin - -end; - procedure TGameControl.StartTurn; begin FormMatrixGame.btnConfirmRow.Enabled:=True; @@ -301,6 +333,12 @@ begin MustDrawDotsClear:=False; FExperiment := TExperiment.Create(FZMQActor.Owner); + FExperiment.OnEndTurn := @NextTurn; + FExperiment.OnEndCycle := @NextCycle; + FExperiment.OnEndGeneration:=@NextLineage; + FExperiment.OnEndCondition:= @NextCondition; + FExperiment.OnEndExperiment:= @EndExperiment; + SendRequest(K_LOGIN); end; @@ -391,6 +429,11 @@ begin FZMQActor.SendMessage(M); end; +procedure TGameControl.Cancel; +begin + +end; + // Here FActor is garanted to be a TZMQPlayer procedure TGameControl.ReceiveMessage(AMessage: TStringList); function MHas(const C : string) : Boolean; @@ -439,8 +482,6 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); gaAdmin:begin // if last choice in cycle then end cycle FExperiment.NextTurn; - Inc(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count); - end; end; end; diff --git a/units/game_experiment.pas b/units/game_experiment.pas index b6c5bf6..4ddccda 100644 --- a/units/game_experiment.pas +++ b/units/game_experiment.pas @@ -24,6 +24,7 @@ type FExperimentName, FFilename, FResearcher : UTF8string; + FOnEndTurn: TNotifyEvent; FOnEndCondition: TNotifyEvent; FOnEndCycle: TNotifyEvent; FOnEndExperiment: TNotifyEvent; @@ -53,6 +54,7 @@ type function GetPlayerIndexFromID(AID : UTF8string): integer; function GetPlayerIsPlaying(AID : UTF8string): Boolean; function GetPlayersCount: integer; + function GetInterlockingsIn(ALastCycles : integer):integer; procedure SetCondition(I : Integer; AValue: TCondition); procedure SetContingency(ACondition, I : integer; AValue: TContingency); procedure SetMatrixType(AValue: TGameMatrixType); @@ -60,6 +62,7 @@ type procedure SetOnEndCycle(AValue: TNotifyEvent); procedure SetOnEndExperiment(AValue: TNotifyEvent); procedure SetOnEndGeneration(AValue: TNotifyEvent); + procedure SetOnEndTurn(AValue: TNotifyEvent); procedure SetPlayer(I : integer; AValue: TPlayer); overload; procedure SetPlayer(S : UTF8string ; AValue: TPlayer); overload; procedure SetResearcherCanChat(AValue: Boolean); @@ -92,6 +95,7 @@ type property ExperimentAim : UTF8string read FExperimentAim write FExperimentAim; property ExperimentName : UTF8string read FExperimentName write FExperimentName; property GenPlayersAsNeeded : Boolean read FGenPlayersAsNeeded write FGenPlayersAsNeeded; + property InterlockingsIn[i:integer]:integer read GetInterlockingsIn; property Player[I : integer] : TPlayer read GetPlayer write SetPlayer; property PlayerFromID[S : UTF8string ] : TPlayer read GetPlayer write SetPlayer; property PlayersCount : integer read GetPlayersCount; @@ -106,8 +110,10 @@ type property NextTurn : integer read GetNextTurn; property NextCycle : integer read GetNextCycle; property NextCondition : integer read GetNextCondition; + property State : TExperimentState read FState write SetState; public + property OnEndTurn : TNotifyEvent read FOnEndTurn write SetOnEndTurn; property OnEndCycle : TNotifyEvent read FOnEndCycle write SetOnEndCycle; property OnEndGeneration : TNotifyEvent read FOnEndGeneration write SetOnEndGeneration; property OnEndCondition : TNotifyEvent read FOnEndCondition write SetOnEndCondition; @@ -142,7 +148,10 @@ function TExperiment.GetNextTurn: integer; // used during player arriving begin Result := FConditions[CurrentCondition].Turn.Count; if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then - Inc(FConditions[CurrentCondition].Turn.Count) + begin + Inc(FConditions[CurrentCondition].Turn.Count); + if Assigned(FOnEndTurn) then FOnEndTurn(Self); + end else begin FConditions[CurrentCondition].Turn.Count := 0; @@ -171,35 +180,42 @@ begin end; function TExperiment.GetNextCondition: integer; -var LCycles : integer; +var + LAbsCycles : integer; + LInterlocks : integer; + + procedure EndCondition; + begin + Inc(CurrentCondition); + if Assigned(FOnEndCondition) then FOnEndCondition(Self); + end; + begin Inc(FConditions[CurrentCondition].Cycles.Generation); Result := CurrentCondition; - LCycles := (FConditions[CurrentCondition].Cycles.Value * + LAbsCycles := (FConditions[CurrentCondition].Cycles.Value * FConditions[CurrentCondition].Cycles.Generation) + FConditions[CurrentCondition].Cycles.Count; - if FConditions[CurrentCondition].EndCriterium.Value = gecAbsoluteCycles then - begin - if LCycles < FConditions[CurrentCondition].EndCriterium.AbsoluteCycles then - // do nothing - else - begin - Inc(CurrentCondition); - FConditions[CurrentCondition].Turn.Count := 0; - Inc(FConditions[CurrentCondition].Cycles.Count); - if Assigned(FOnEndCondition) then FOnEndCondition(Self); - end; - end; + // interlockings in last x cycles + LInterlocks := InterlockingsIn(FConditions[CurrentCondition].EndCriterium.LastCycles); + case FConditions[CurrentCondition].EndCriterium.Value of + gecWhichComeFirst: + begin + if (LAbsCycles = FConditions[CurrentCondition].EndCriterium.AbsoluteCycles) or + (LInterlocks = FConditions[CurrentCondition].EndCriterium.InterlockingPorcentage) then + EndCondition; + + end; + gecAbsoluteCycles: + if LAbsCycles = FConditions[CurrentCondition].EndCriterium.AbsoluteCycles then + EndCondition; + + gecInterlockingPorcentage: + if LInterlocks = FConditions[CurrentCondition].EndCriterium.InterlockingPorcentage then + EndCondition + + end; -// -// if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then -// Inc(FConditions[CurrentCondition].Turn.Count -// else -// begin -// FConditions[CurrentCondition].Turn.Count := 0; -// Inc(FConditions[CurrentCondition].Cycles.Count); -// if Assigned(FOnEndCycle) then FOnEndCycle(Self); -// end; end; function TExperiment.GetPlayer(I : integer): TPlayer; @@ -394,6 +410,11 @@ begin Result := Length(FPlayers); end; +function TExperiment.GetInterlockingsIn(ALastCycles: integer): integer; +begin + +end; + procedure TExperiment.SetCondition(I : Integer; AValue: TCondition); begin FConditions[I] := AValue; @@ -434,6 +455,12 @@ begin FOnEndGeneration:=AValue; end; +procedure TExperiment.SetOnEndTurn(AValue: TNotifyEvent); +begin + if FOnEndTurn=AValue then Exit; + FOnEndTurn:=AValue; +end; + procedure TExperiment.SetPlayer(I : integer; AValue: TPlayer); begin -- libgit2 0.21.2