Changeset 88 for trunk/Forms
- Timestamp:
- Jun 7, 2024, 2:36:34 PM (5 months ago)
- Location:
- trunk/Forms
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormComputer.lfm
r86 r88 1 1 object FormComputer: TFormComputer 2 Left = 7472 Left = 1040 3 3 Height = 360 4 Top = 5 614 Top = 540 5 5 Width = 480 6 6 Caption = 'AI' … … 21 21 OnClick = ButtonStartClick 22 22 end 23 object Button Stop: TButton24 Left = 2 0823 object ButtonEnd: TButton 24 Left = 296 25 25 Height = 38 26 26 Top = 24 27 27 Width = 113 28 Caption = ' Stop'28 Caption = 'End' 29 29 Enabled = False 30 30 TabOrder = 1 31 OnClick = Button StopClick31 OnClick = ButtonEndClick 32 32 end 33 33 object TrackBar1: TTrackBar … … 49 49 ParentColor = False 50 50 end 51 object ButtonStep: TButton 52 Left = 168 53 Height = 38 54 Top = 24 55 Width = 113 56 Caption = 'Step' 57 Enabled = False 58 TabOrder = 3 59 OnClick = ButtonStepClick 60 end 51 61 end -
trunk/Forms/FormComputer.lrj
r86 r88 2 2 {"hash":1113,"name":"tformcomputer.caption","sourcebytes":[65,73],"value":"AI"}, 3 3 {"hash":5941396,"name":"tformcomputer.buttonstart.caption","sourcebytes":[83,116,97,114,116],"value":"Start"}, 4 {"hash":371552,"name":"tformcomputer.buttonstop.caption","sourcebytes":[83,116,111,112],"value":"Stop"}, 5 {"hash":116494394,"name":"tformcomputer.label1.caption","sourcebytes":[68,101,108,97,121,32,112,101,114,32,115,116,101,112,58],"value":"Delay per step:"} 4 {"hash":19524,"name":"tformcomputer.buttonend.caption","sourcebytes":[69,110,100],"value":"End"}, 5 {"hash":116494394,"name":"tformcomputer.label1.caption","sourcebytes":[68,101,108,97,121,32,112,101,114,32,115,116,101,112,58],"value":"Delay per step:"}, 6 {"hash":371392,"name":"tformcomputer.buttonstep.caption","sourcebytes":[83,116,101,112],"value":"Step"} 6 7 ]} -
trunk/Forms/FormComputer.pas
r86 r88 34 34 TFormComputer = class(TFormEx) 35 35 ButtonStart: TButton; 36 ButtonStop: TButton; 36 ButtonEnd: TButton; 37 ButtonStep: TButton; 37 38 Label1: TLabel; 38 39 TrackBar1: TTrackBar; 39 40 procedure ButtonStartClick(Sender: TObject); 40 procedure ButtonStopClick(Sender: TObject); 41 procedure ButtonEndClick(Sender: TObject); 42 procedure ButtonStepClick(Sender: TObject); 41 43 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 42 44 procedure FormCreate(Sender: TObject); 43 45 procedure FormDestroy(Sender: TObject); 44 46 private 45 Stop: Boolean;47 Running: Boolean; 46 48 GameTries1: TGameTries; 47 49 GameTries2: TGameTries; 48 50 GameTries3: TGameTries; 49 51 GameTries4: TGameTries; 52 procedure Step; 50 53 procedure TryAllDirections(GameTries: TGameTries; GameTry: TGameTry); 54 procedure UpdateInterface; 51 55 end; 52 56 … … 151 155 ); 152 156 begin 153 ButtonStopClick(Self);157 Running := False; 154 158 end; 155 159 … … 167 171 168 172 procedure TFormComputer.ButtonStartClick(Sender: TObject); 173 begin 174 Running := True; 175 while Core.Core.Game.CanMove and Running do begin 176 Step; 177 end; 178 Running := False; 179 end; 180 181 procedure TFormComputer.ButtonEndClick(Sender: TObject); 182 begin 183 Running := False; 184 end; 185 186 procedure TFormComputer.ButtonStepClick(Sender: TObject); 187 begin 188 Step; 189 end; 190 191 procedure TFormComputer.FormCreate(Sender: TObject); 192 begin 193 GameTries1 := TGameTries.Create; 194 GameTries2 := TGameTries.Create; 195 GameTries3 := TGameTries.Create; 196 GameTries4 := TGameTries.Create; 197 UpdateInterface; 198 end; 199 200 procedure TFormComputer.FormDestroy(Sender: TObject); 201 begin 202 FreeAndNil(GameTries1); 203 FreeAndNil(GameTries2); 204 FreeAndNil(GameTries3); 205 FreeAndNil(GameTries4); 206 end; 207 208 procedure TFormComputer.Step; 169 209 var 170 210 NewTry: TGameTry; … … 176 216 Delay: Integer; 177 217 begin 178 ButtonStart.Enabled := False;179 ButtonStop.Enabled := True;180 Stop := False;181 218 with Core.Core.Game do begin 182 while CanMove and not Stop do begin 183 NewTry := TGameTry.Create; 184 NewTry.Game.Assign(Core.Core.Game); 185 GameTries1.Clear; 186 TryAllDirections(GameTries1, NewTry); 187 FreeAndNil(NewTry); 188 GameTries2.Clear; 189 for I := 0 to GameTries1.Count - 1 do 190 TryAllDirections(GameTries2, GameTries1[I]); 191 GameTries3.Clear; 192 for I := 0 to GameTries2.Count - 1 do 193 TryAllDirections(GameTries3, GameTries2[I]); 194 GameTries4.Clear; 195 for I := 0 to GameTries3.Count - 1 do 196 TryAllDirections(GameTries4, GameTries3[I]); 197 198 GameTries := GameTries4; 199 GameTryComparer := TGameTryComparer.Create; 200 GameTries.Sort(GameTryComparer); 201 S := ''; 202 for I := 0 to GameTries.Count - 1 do begin 203 S := S + FormatFloat('0.000', GameTries[I].GetFitness) + '('; 204 for J := 0 to Length(GameTries[I].Moves) - 1 do 205 S := S + DirectionText[GameTries[I].Moves[J]] + ' '; 206 S := S + '), '; 207 end; 208 MoveAllAndUpdate(GameTries[0].Moves[0], False); 209 { if CanMergeDirection(drDown) then MoveAllAnimate(drDown) 210 else if CanMergeDirection(drRight) then MoveAllAnimate(drRight) 211 else if CanMergeDirection(drLeft) then MoveAllAnimate(drLeft) 212 else if CanMoveDirection(drDown) then MoveAllAnimate(drDown) 213 else if CanMoveDirection(drRight) then MoveAllAnimate(drRight) 214 else if CanMoveDirection(drLeft) then MoveAllAnimate(drLeft) 215 else if CanMoveDirection(drUp) then MoveAllAnimate(drUp) 216 else Break; 217 } 218 Delay := TrackBar1.Position; 219 while Delay > 0 do begin 220 Application.ProcessMessages; 221 Sleep(10); 222 Delay := Delay - 10; 223 end; 224 end; 225 end; 226 ButtonStart.Enabled := True; 227 ButtonStop.Enabled := False; 228 end; 229 230 procedure TFormComputer.ButtonStopClick(Sender: TObject); 231 begin 232 Stop := True; 233 end; 234 235 procedure TFormComputer.FormCreate(Sender: TObject); 236 begin 237 GameTries1 := TGameTries.Create; 238 GameTries2 := TGameTries.Create; 239 GameTries3 := TGameTries.Create; 240 GameTries4 := TGameTries.Create; 241 end; 242 243 procedure TFormComputer.FormDestroy(Sender: TObject); 244 begin 245 FreeAndNil(GameTries1); 246 FreeAndNil(GameTries2); 247 FreeAndNil(GameTries3); 248 FreeAndNil(GameTries4); 219 NewTry := TGameTry.Create; 220 NewTry.Game.Assign(Core.Core.Game); 221 GameTries1.Clear; 222 TryAllDirections(GameTries1, NewTry); 223 FreeAndNil(NewTry); 224 GameTries2.Clear; 225 for I := 0 to GameTries1.Count - 1 do 226 TryAllDirections(GameTries2, GameTries1[I]); 227 GameTries3.Clear; 228 for I := 0 to GameTries2.Count - 1 do 229 TryAllDirections(GameTries3, GameTries2[I]); 230 GameTries4.Clear; 231 for I := 0 to GameTries3.Count - 1 do 232 TryAllDirections(GameTries4, GameTries3[I]); 233 234 GameTries := GameTries4; 235 GameTryComparer := TGameTryComparer.Create; 236 GameTries.Sort(GameTryComparer); 237 S := ''; 238 for I := 0 to GameTries.Count - 1 do begin 239 S := S + FormatFloat('0.000', GameTries[I].GetFitness) + '('; 240 for J := 0 to Length(GameTries[I].Moves) - 1 do 241 S := S + DirectionText[GameTries[I].Moves[J]] + ' '; 242 S := S + '), '; 243 end; 244 MoveAllAndUpdate(GameTries[0].Moves[0], False); 245 { if CanMergeDirection(drDown) then MoveAllAnimate(drDown) 246 else if CanMergeDirection(drRight) then MoveAllAnimate(drRight) 247 else if CanMergeDirection(drLeft) then MoveAllAnimate(drLeft) 248 else if CanMoveDirection(drDown) then MoveAllAnimate(drDown) 249 else if CanMoveDirection(drRight) then MoveAllAnimate(drRight) 250 else if CanMoveDirection(drLeft) then MoveAllAnimate(drLeft) 251 else if CanMoveDirection(drUp) then MoveAllAnimate(drUp) 252 else Break; 253 } 254 Delay := TrackBar1.Position; 255 while Delay > 0 do begin 256 Application.ProcessMessages; 257 Sleep(10); 258 Delay := Delay - 10; 259 end; 260 end; 261 UpdateInterface; 249 262 end; 250 263 … … 268 281 end; 269 282 283 procedure TFormComputer.UpdateInterface; 284 begin 285 ButtonStart.Enabled := not Running; 286 ButtonStep.Enabled := not Running; 287 ButtonEnd.Enabled := Running; 288 end; 289 270 290 end. 271 291 -
trunk/Forms/FormMain.lfm
r87 r88 1 1 object FormMain: TFormMain 2 2 Left = 534 3 Height = 9933 Height = 1061 4 4 Top = 223 5 5 Width = 1491 … … 7 7 DesignTimePPI = 144 8 8 Menu = MainMenu1 9 On Close = FormClose9 OnActivate = FormActivate 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy -
trunk/Forms/FormMain.pas
r87 r88 36 36 MenuItemGame: TMenuItem; 37 37 TimerDraw: TTimer; 38 procedure Form Close(Sender: TObject; var CloseAction: TCloseAction);38 procedure FormActivate(Sender: TObject); 39 39 procedure FormCreate(Sender: TObject); 40 40 procedure FormDestroy(Sender: TObject); … … 171 171 end; 172 172 173 procedure TFormMain.Form Close(Sender: TObject; var CloseAction: TCloseAction);174 begin 175 Core.Core.PersistentForm1.Save(Self);173 procedure TFormMain.FormActivate(Sender: TObject); 174 begin 175 FullScreen := Core.Core.PersistentForm1.FormFullScreen; 176 176 end; 177 177 … … 194 194 procedure TFormMain.FormShow(Sender: TObject); 195 195 begin 196 FullScreen := Core.Core.PersistentForm1.FormFullScreen;197 198 196 UpdateInterface; 199 if Core.Core.Game.Board.GetEmptyTilesCount > Core.Core.Game.Board.Size.X * Core.Core.Game.Board.Size.Y -200 InitialTileCount then197 if Core.Core.Game.Board.GetEmptyTilesCount > Core.Core.Game.Board.Size.X * 198 Core.Core.Game.Board.Size.Y - InitialTileCount then 201 199 Core.Core.Game.New; 202 200 end;
Note:
See TracChangeset
for help on using the changeset viewer.