Ignore:
Timestamp:
Oct 12, 2019, 11:01:10 PM (5 years ago)
Author:
chronos
Message:
  • Modified: In computer form allow to stop AI play.
  • Modified: Optimized moves history computation using MoveAll without animation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormComputer.pas

    r31 r32  
    2828
    2929  TFormComputer = class(TForm)
    30     ButtonSolve: TButton;
    31     procedure ButtonSolveClick(Sender: TObject);
     30    ButtonStart: TButton;
     31    ButtonStop: TButton;
     32    procedure ButtonStartClick(Sender: TObject);
     33    procedure ButtonStopClick(Sender: TObject);
    3234    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3335    procedure FormCreate(Sender: TObject);
     
    3537    procedure FormShow(Sender: TObject);
    3638  private
     39    Stop: Boolean;
    3740    GameTries1: TGameTries;
    3841    GameTries2: TGameTries;
     
    147150end;
    148151
    149 procedure TFormComputer.ButtonSolveClick(Sender: TObject);
     152procedure TFormComputer.ButtonStartClick(Sender: TObject);
    150153var
    151154  NewTry: TGameTry;
     
    155158  GameTries: TGameTries;
    156159begin
     160  ButtonStart.Enabled := False;
     161  ButtonStop.Enabled := True;
     162  Stop := False;
    157163  with Core.Game do begin
    158     while CanMove do begin
     164    while CanMove and not Stop do begin
    159165      NewTry := TGameTry.Create;
    160166      NewTry.Game.Assign(Core.Game);
     
    182188      end;
    183189      MoveAllAndUpdate(GameTries[0].Moves[0]);
    184 {      if CanMergeDirection(drDown) then MoveAll(drDown)
    185       else if CanMergeDirection(drRight) then MoveAll(drRight)
    186       else if CanMergeDirection(drLeft) then MoveAll(drLeft)
    187       else if CanMoveDirection(drDown) then MoveAll(drDown)
    188       else if CanMoveDirection(drRight) then MoveAll(drRight)
    189       else if CanMoveDirection(drLeft) then MoveAll(drLeft)
    190       else if CanMoveDirection(drUp) then MoveAll(drUp)
     190{      if CanMergeDirection(drDown) then MoveAllAnimate(drDown)
     191      else if CanMergeDirection(drRight) then MoveAllAnimate(drRight)
     192      else if CanMergeDirection(drLeft) then MoveAllAnimate(drLeft)
     193      else if CanMoveDirection(drDown) then MoveAllAnimate(drDown)
     194      else if CanMoveDirection(drRight) then MoveAllAnimate(drRight)
     195      else if CanMoveDirection(drLeft) then MoveAllAnimate(drLeft)
     196      else if CanMoveDirection(drUp) then MoveAllAnimate(drUp)
    191197      else Break;
    192198      }
     
    195201    end;
    196202  end;
     203  ButtonStart.Enabled := True;
     204  ButtonStop.Enabled := False;
     205end;
     206
     207procedure TFormComputer.ButtonStopClick(Sender: TObject);
     208begin
     209  Stop := True;
    197210end;
    198211
     
    224237  NewTry: TGameTry;
    225238begin
    226   for Direction := Low(TMoveDirection) to High(TMoveDirection) do begin
     239  for Direction := drLeft to drDown do begin
    227240    if GameTry.Game.CanMoveDirection(Direction) then begin
    228241      NewTry := TGameTry.Create;
     
    230243      NewTry.Game.UndoEnabled := False;
    231244      NewTry.Game.AnimationDuration := 0;
    232       NewTry.Game.MoveAll(Direction);
     245      NewTry.Game.MoveAllAnimate(Direction);
    233246      SetLength(NewTry.Moves, Length(NewTry.Moves) + 1);
    234247      NewTry.Moves[Length(NewTry.Moves) - 1] := Direction;
Note: See TracChangeset for help on using the changeset viewer.