diff --git a/lazarus/pathfinder/project1.ico b/lazarus/pathfinder/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/pathfinder/project1.ico differ diff --git a/lazarus/pathfinder/project1.lpi b/lazarus/pathfinder/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/pathfinder/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/pathfinder/project1.lpr b/lazarus/pathfinder/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/pathfinder/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/pathfinder/project1.res b/lazarus/pathfinder/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/pathfinder/project1.res differ diff --git a/lazarus/pathfinder/unit1.lfm b/lazarus/pathfinder/unit1.lfm new file mode 100644 index 0000000..92423d4 --- /dev/null +++ b/lazarus/pathfinder/unit1.lfm @@ -0,0 +1,21 @@ +object Form1: TForm1 + Left = 217 + Height = 543 + Top = 219 + Width = 642 + Caption = 'Form1' + ClientHeight = 543 + ClientWidth = 642 + OnCreate = FormCreate + OnMouseDown = FormMouseDown + OnPaint = FormPaint + LCLVersion = '1.6.2.0' + object Label1: TLabel + Left = 16 + Height = 42 + Top = 464 + Width = 299 + Caption = 'Modify maze by left mouse button,'#10'and sent bot to selected point by right button' + ParentColor = False + end +end diff --git a/lazarus/pathfinder/unit1.pas b/lazarus/pathfinder/unit1.pas new file mode 100644 index 0000000..c4587ff --- /dev/null +++ b/lazarus/pathfinder/unit1.pas @@ -0,0 +1,132 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; + +type + + { TForm1 } + + TForm1 = class(TForm) + Label1: TLabel; + procedure FormCreate(Sender: TObject); + procedure FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); + procedure FormPaint(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +const + cols = 10; + rows = 10; + size = 40; + +var + Form1: TForm1; + walls: array [0..cols, 0..rows] of boolean; + vizited: array [0..cols, 0..rows] of boolean; + px, py: integer; + +implementation + +{$R *.lfm} + +function Go(x, y, dx, dy: integer): boolean; +begin + Result := false; + if (x>=0) and (y>=0) and (x<rows) and (y<cols) and (not walls[x, y]) and (not vizited[x, y]) then begin + vizited[x, y] := true; + + px := x; py := y; + Form1.Refresh; + Application.ProcessMessages; + Sleep(100); + + if (x=dx) and (y=dy) then begin + Result := true; + end else begin + if Go(x-1, y, dx, dy) then Result := true else + if Go(x, y-1, dx, dy) then Result := true else + if Go(x+1, y, dx, dy) then Result := true else + if Go(x, y+1, dx, dy) then Result := true; + end; + + if not Result then begin + px := x; py := y; + Form1.Refresh; + Application.ProcessMessages; + Sleep(100); + end; + end; +end; + +procedure TForm1.FormCreate(Sender: TObject); +var + x, y: integer; +begin + Randomize; + for x := 0 to cols-1 do begin + for y := 0 to rows-1 do begin + if Random > 0.5 then begin + walls[x, y] := true; + end else begin + walls[x, y] := false; + px := x; + py := y; + end; + end; + end; +end; + +procedure TForm1.FormPaint(Sender: TObject); +var + x, y: integer; +begin + for x := 0 to cols-1 do begin + for y := 0 to rows-1 do begin + if walls[x, y] then begin + Canvas.Brush.Color := clBlack; + end else begin + Canvas.Brush.Color := clWhite; + end; + Canvas.FillRect(Rect(x*size, y*size, (x+1)*size, (y+1)*size)); + end; + end; + + Canvas.Brush.Color := clRed; + Canvas.Ellipse(px*size, py*size, (px+1)*size, (py+1)*size); +end; + +procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +var + dx, dy, vx, vy: integer; +begin + dx := x div size; + dy := y div size; + if (dx>=0) and (dy>=0) and (dx<rows) and (dy<cols) then begin + if Button = mbLeft then begin + walls[dx, dy] := not walls[dx, dy]; + Refresh; + end; + if Button = mbRight then begin + for vx := 0 to cols-1 do begin + for vy := 0 to rows-1 do begin + vizited[vx, vy] := false; + end; + end; + if not Go(px, py, dx, dy) then ShowMessage('Path not found'); + Refresh; + end; + end; +end; + +end. +