Changeset 86 for trunk/Forms/FormComputer.pas
- Timestamp:
- Jun 7, 2024, 12:47:11 PM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormComputer.pas
r85 r86 1 unit UFormComputer; 2 3 {$mode delphi} 1 unit FormComputer; 4 2 5 3 interface … … 7 5 uses 8 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls, 9 UGame, fgl;7 Game, Generics.Collections, Generics.Defaults, FormEx; 10 8 11 9 type … … 23 21 end; 24 22 25 TGameTries = class(TFPGObjectList<TGameTry>) 23 TGameTries = class(TObjectList<TGameTry>) 24 end; 25 26 { TGameTryComparer } 27 28 TGameTryComparer = class(TInterfacedObject, IComparer<TGameTry>) 29 function Compare(constref Left, Right: TGameTry): Integer; overload; 26 30 end; 27 31 28 32 { TFormComputer } 29 33 30 TFormComputer = class(TForm )34 TFormComputer = class(TFormEx) 31 35 ButtonStart: TButton; 32 36 ButtonStop: TButton; … … 38 42 procedure FormCreate(Sender: TObject); 39 43 procedure FormDestroy(Sender: TObject); 40 procedure FormShow(Sender: TObject);41 44 private 42 45 Stop: Boolean; … … 46 49 GameTries4: TGameTries; 47 50 procedure TryAllDirections(GameTries: TGameTries; GameTry: TGameTry); 48 public 49 50 end; 51 52 var 53 FormComputer: TFormComputer; 51 end; 52 54 53 55 54 implementation … … 58 57 59 58 uses 60 UCore;59 Core; 61 60 62 61 { TGameTry } … … 133 132 end; 134 133 134 { TGameTryComparer } 135 136 function TGameTryComparer.Compare(constref Left, Right: TGameTry): Integer; 137 var 138 ScoreLeft: Double; 139 ScoreRight: Double; 140 begin 141 ScoreLeft := Left.GetFitness; 142 ScoreRight := Right.GetFitness; 143 if ScoreLeft > ScoreRight then Result := -1 144 else if ScoreLeft < ScoreRight then Result := 1 145 else Result := 0; 146 end; 147 135 148 { TFormComputer } 136 149 … … 139 152 begin 140 153 ButtonStopClick(Self); 141 Core.PersistentForm1.Save(Self);142 154 end; 143 155 … … 161 173 J: Integer; 162 174 GameTries: TGameTries; 175 GameTryComparer: TGameTryComparer; 163 176 Delay: Integer; 164 177 begin … … 166 179 ButtonStop.Enabled := True; 167 180 Stop := False; 168 with Core. Game do begin181 with Core.Core.Game do begin 169 182 while CanMove and not Stop do begin 170 183 NewTry := TGameTry.Create; 171 NewTry.Game.Assign(Core. Game);184 NewTry.Game.Assign(Core.Core.Game); 172 185 GameTries1.Clear; 173 186 TryAllDirections(GameTries1, NewTry); … … 184 197 185 198 GameTries := GameTries4; 186 GameTries.Sort(GameCompareScore); 199 GameTryComparer := TGameTryComparer.Create; 200 GameTries.Sort(GameTryComparer); 187 201 S := ''; 188 202 for I := 0 to GameTries.Count - 1 do begin … … 221 235 procedure TFormComputer.FormCreate(Sender: TObject); 222 236 begin 223 Core.Translator1.TranslateComponentRecursive(Self);224 Core.ThemeManager1.UseTheme(Self);225 237 GameTries1 := TGameTries.Create; 226 238 GameTries2 := TGameTries.Create; … … 235 247 FreeAndNil(GameTries3); 236 248 FreeAndNil(GameTries4); 237 end;238 239 procedure TFormComputer.FormShow(Sender: TObject);240 begin241 Core.PersistentForm1.Load(Self);242 249 end; 243 250
Note:
See TracChangeset
for help on using the changeset viewer.