Changeset 88


Ignore:
Timestamp:
Jun 7, 2024, 2:36:34 PM (7 months ago)
Author:
chronos
Message:
  • Fixed: Fullscreen mode was not working on start.
  • Added: Step button in AI form to do single step.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormComputer.lfm

    r86 r88  
    11object FormComputer: TFormComputer
    2   Left = 747
     2  Left = 1040
    33  Height = 360
    4   Top = 561
     4  Top = 540
    55  Width = 480
    66  Caption = 'AI'
     
    2121    OnClick = ButtonStartClick
    2222  end
    23   object ButtonStop: TButton
    24     Left = 208
     23  object ButtonEnd: TButton
     24    Left = 296
    2525    Height = 38
    2626    Top = 24
    2727    Width = 113
    28     Caption = 'Stop'
     28    Caption = 'End'
    2929    Enabled = False
    3030    TabOrder = 1
    31     OnClick = ButtonStopClick
     31    OnClick = ButtonEndClick
    3232  end
    3333  object TrackBar1: TTrackBar
     
    4949    ParentColor = False
    5050  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
    5161end
  • trunk/Forms/FormComputer.lrj

    r86 r88  
    22{"hash":1113,"name":"tformcomputer.caption","sourcebytes":[65,73],"value":"AI"},
    33{"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"}
    67]}
  • trunk/Forms/FormComputer.pas

    r86 r88  
    3434  TFormComputer = class(TFormEx)
    3535    ButtonStart: TButton;
    36     ButtonStop: TButton;
     36    ButtonEnd: TButton;
     37    ButtonStep: TButton;
    3738    Label1: TLabel;
    3839    TrackBar1: TTrackBar;
    3940    procedure ButtonStartClick(Sender: TObject);
    40     procedure ButtonStopClick(Sender: TObject);
     41    procedure ButtonEndClick(Sender: TObject);
     42    procedure ButtonStepClick(Sender: TObject);
    4143    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    4244    procedure FormCreate(Sender: TObject);
    4345    procedure FormDestroy(Sender: TObject);
    4446  private
    45     Stop: Boolean;
     47    Running: Boolean;
    4648    GameTries1: TGameTries;
    4749    GameTries2: TGameTries;
    4850    GameTries3: TGameTries;
    4951    GameTries4: TGameTries;
     52    procedure Step;
    5053    procedure TryAllDirections(GameTries: TGameTries; GameTry: TGameTry);
     54    procedure UpdateInterface;
    5155  end;
    5256
     
    151155  );
    152156begin
    153   ButtonStopClick(Self);
     157  Running := False;
    154158end;
    155159
     
    167171
    168172procedure TFormComputer.ButtonStartClick(Sender: TObject);
     173begin
     174  Running := True;
     175  while Core.Core.Game.CanMove and Running do begin
     176    Step;
     177  end;
     178  Running := False;
     179end;
     180
     181procedure TFormComputer.ButtonEndClick(Sender: TObject);
     182begin
     183  Running := False;
     184end;
     185
     186procedure TFormComputer.ButtonStepClick(Sender: TObject);
     187begin
     188  Step;
     189end;
     190
     191procedure TFormComputer.FormCreate(Sender: TObject);
     192begin
     193  GameTries1 := TGameTries.Create;
     194  GameTries2 := TGameTries.Create;
     195  GameTries3 := TGameTries.Create;
     196  GameTries4 := TGameTries.Create;
     197  UpdateInterface;
     198end;
     199
     200procedure TFormComputer.FormDestroy(Sender: TObject);
     201begin
     202  FreeAndNil(GameTries1);
     203  FreeAndNil(GameTries2);
     204  FreeAndNil(GameTries3);
     205  FreeAndNil(GameTries4);
     206end;
     207
     208procedure TFormComputer.Step;
    169209var
    170210  NewTry: TGameTry;
     
    176216  Delay: Integer;
    177217begin
    178   ButtonStart.Enabled := False;
    179   ButtonStop.Enabled := True;
    180   Stop := False;
    181218  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;
    249262end;
    250263
     
    268281end;
    269282
     283procedure TFormComputer.UpdateInterface;
     284begin
     285  ButtonStart.Enabled := not Running;
     286  ButtonStep.Enabled := not Running;
     287  ButtonEnd.Enabled := Running;
     288end;
     289
    270290end.
    271291
  • trunk/Forms/FormMain.lfm

    r87 r88  
    11object FormMain: TFormMain
    22  Left = 534
    3   Height = 993
     3  Height = 1061
    44  Top = 223
    55  Width = 1491
     
    77  DesignTimePPI = 144
    88  Menu = MainMenu1
    9   OnClose = FormClose
     9  OnActivate = FormActivate
    1010  OnCreate = FormCreate
    1111  OnDestroy = FormDestroy
  • trunk/Forms/FormMain.pas

    r87 r88  
    3636    MenuItemGame: TMenuItem;
    3737    TimerDraw: TTimer;
    38     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     38    procedure FormActivate(Sender: TObject);
    3939    procedure FormCreate(Sender: TObject);
    4040    procedure FormDestroy(Sender: TObject);
     
    171171end;
    172172
    173 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    174 begin
    175   Core.Core.PersistentForm1.Save(Self);
     173procedure TFormMain.FormActivate(Sender: TObject);
     174begin
     175  FullScreen := Core.Core.PersistentForm1.FormFullScreen;
    176176end;
    177177
     
    194194procedure TFormMain.FormShow(Sender: TObject);
    195195begin
    196   FullScreen := Core.Core.PersistentForm1.FormFullScreen;
    197 
    198196  UpdateInterface;
    199   if Core.Core.Game.Board.GetEmptyTilesCount > Core.Core.Game.Board.Size.X * Core.Core.Game.Board.Size.Y -
    200     InitialTileCount then
     197  if Core.Core.Game.Board.GetEmptyTilesCount > Core.Core.Game.Board.Size.X *
     198    Core.Core.Game.Board.Size.Y - InitialTileCount then
    201199    Core.Core.Game.New;
    202200end;
  • trunk/Languages/Game2048.cs.po

    r87 r88  
    151151msgstr "Vrátit zpět"
    152152
     153#: tformcomputer.buttonend.caption
     154msgid "End"
     155msgstr "Konec"
     156
    153157#: tformcomputer.buttonstart.caption
    154158msgid "Start"
    155159msgstr "Spustit"
    156160
    157 #: tformcomputer.buttonstop.caption
    158 msgid "Stop"
    159 msgstr "Zastavit"
     161#: tformcomputer.buttonstep.caption
     162msgid "Step"
     163msgstr "Krok"
    160164
    161165#: tformcomputer.caption
  • trunk/Packages/Common/FormEx.pas

    r85 r88  
    6868  end;
    6969
    70   PersistentForm.Load(Self);
    7170  Translator.TranslateComponentRecursive(Self);
    7271  ThemeManager.UseTheme(Self);
Note: See TracChangeset for help on using the changeset viewer.