Recent

Author Topic: Mazemaker (efg)  (Read 3461 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Mazemaker (efg)
« on: September 19, 2023, 09:12:29 am »
Just converted the old Delphi efg Mazemaker to Lazarus. Added a few bits (blank out the solution path) and fixed a few printer.handle and black screen inconsistencies between Delphi and Lazarus.

Just one bug (probably to do with modal print window), where after printing to pdf the window message saying "The maze was successfully printed" does not come up until modal window is closed. Need to work out how to close the modal print window just after the OK Tick button is clicked.


I also added 2 extra buttons (one to blank out the solution path to make just a Black and White Maze and one button to show the solution path in blue).
I wondered how to add blank puzzle and solution path both to one print job).

Anyhow, enjoy and play around making the mazes.

 
« Last Edit: September 19, 2023, 10:13:05 am by Boleeman »

fred

  • Full Member
  • ***
  • Posts: 201
Re: Mazemaker (efg)
« Reply #1 on: September 19, 2023, 01:28:42 pm »
Thank you, it's fun to see the maze :)

Some notes:
CheckBoxShowPath was too far on the right so not visible, I moved so it was visible (perhaps Blank Maze is not noeeded then).

For a two page print you can use in TFormPrintMaze.BitBtnOKClick:
Add    Printer.NewPage;
Add    DrawMaze(Printer.Canvas, etc.
Replace FormMazeMaker.CheckBoxShowPath.Checked with False

To close the print windows at the end add   ModalResult := mrOK;

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #2 on: September 20, 2023, 12:24:33 am »
Thanks Fred for the reply.

I was unaware of that checkbox to toggle between the maze and it's solution (that is why I made the extra 2 command button procedures). I could not see the checkbox on the form so I ended up deleting it in the Object Inspector and then created a new checkbox and renamed it and added the onchange event. I also learnt something new about adding multiple print pages. Lastly, the "ModalResult := mrOK;" fixed that open window. I had mine in the wrong procedure. Earlier on I managed to work out how to make the window close by canceling  by adding the click procedure TFormPrintMaze.BitBtnCancelClick but I was stumped for the OK button modal closure.

I wanted to learn about "Each cell being represented by a 2-bit quantity in a two-dimensional Cells array" (=array of array of 0..3;   // 2-bits:  $00, $01, $10, $11).

Also not really fully understanding the rainbow brush color code either (sort of like fractional position of wavelength of color)

Brush.Color := WavelengthToColor(WavelengthMinimum + PathPos / PathLength * (WavelengthMaximum - WavelengthMinimum))

but I guess it was related to the another "Color wavelength" webpage from the old efg web site (more reading to do).


Many thanks Fred for your fixes and the 2 page print update. I really like this fun maze program.
« Last Edit: September 20, 2023, 12:39:28 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #3 on: September 20, 2023, 03:02:57 am »
The program compiles well in Win32.

I also tried compiling for Win64 bit but got the following push pop error messages.

MazeLibrary.pas(219,11) Error: Asm: [push mem32] invalid combination of opcode and operands

Push PosX;

MazeLibrary.pas(220,11) Error: Asm: [push mem32] invalid combination of opcode and operands

Push PosY;

MazeLibrary.pas(288,13) Error: Asm: [pop mem32] invalid combination of opcode and operands

Pop PosY;

MazeLibrary.pas(289,13) Error: Asm: [pop mem32] invalid combination of opcode and operands

Pop PosX;

Is there a simple asm replacement for these for 64 bit amd?

I don't know much about asm.



Thanks.

Lulu

  • Sr. Member
  • ****
  • Posts: 265
Re: Mazemaker (efg)
« Reply #4 on: September 20, 2023, 09:05:49 pm »
Hi, tahks to share!.
A work around is to eliminate the asm lines in the code using a software stack to emulate the Push and Pop asm calls.
A dirty quick solution is:
Code: Pascal  [Select][+][-]
  1.   USES
  2.     Windows,        // MulDiv
  3.     Classes,        // Rect
  4.     Dialogs,        // ShowMessage
  5.     SpectraLibrary, // WavelengthToColor
  6.     Math,           // Math
  7.     Contnrs; // <<< ADD THIS unit for TStack
  8. ...
  9.   begin // << the begin of the function DrawMaze
  10.     Stack := TStack.Create; // << ADD THIS  creation of a stack instance
  11. ...
  12. //        asm                      //  Comment the asm lines
  13. //          Push PosX;
  14. //          Push PosY;
  15. //        end;
  16.         Stack.Push(Pointer(PosX)); // ADD THIS to push the values in our software stack
  17.         Stack.Push(Pointer(PosY));
  18. ...
  19. //          asm             //  Comment the asm lines
  20. //            Pop PosY;
  21. //            Pop PosX;
  22. //          end;
  23.           PosY := Integer(Stack.Pop);  // ADD THIS to pop the values from our software stack
  24.           PosX := Integer(Stack.Pop);
  25. ...
  26.     Stack.Free;  // << ADD THIS at the end of the function to free the stack
  27.     RESULT := 1 + PathLength   // 0-origin
  28.  
  29.   end {DrawMaze};
  30.  
  31.  
Tested on Windows 10 (64b), it work.
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #5 on: September 23, 2023, 05:19:39 am »
Thanks for the reply Lulu.

I initially got these error messages

MazeLibrary.pas(141,5) Error: Identifier not found "Stack"
MazeLibrary.pas(215,9) Error: Identifier not found "Stack"
MazeLibrary.pas(225,10) Error: Identifier not found "Stack"
MazeLibrary.pas(225,21) Warning: Conversion between ordinals and pointers is not portable
MazeLibrary.pas(226,10) Error: Identifier not found "Stack"
MazeLibrary.pas(226,21) Warning: Conversion between ordinals and pointers is not portable
MazeLibrary.pas(231,7) Fatal: Syntax error, "UNTIL" expected but "END" found


And then I found the problem Stack did not have a data type declared in the Variables
Var      Stack: TStack;

Now everything compiles OK under 64bits. Thanks Lulu for the converted bits. Fantastic.
« Last Edit: September 23, 2023, 06:11:15 am by Boleeman »

TRon

  • Hero Member
  • *****
  • Posts: 3647
Re: Mazemaker (efg)
« Reply #6 on: September 23, 2023, 05:42:44 am »
Perhaps I missed something out or do I need to try this on a computer with an Intel CPU?

The following small free pascal test compiles for me on linux-x86_64:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. uses
  4.   Contnrs;
  5.  
  6. var
  7.   Stack: TStack;
  8. begin
  9.   Stack := TStack.Create;
  10.   Stack.Free;
  11. end.
  12.  

Are you sure you rebuild your project so that the mazelibrary unit actually gets re-compiled ? Can you show the output messages from lazarus (make sure to copy them all, not only the visible ones).
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #7 on: September 23, 2023, 06:12:49 am »
Thanks TRon. Found the problem by redoing the steps a number of times. It was that Stack was not defined in the variables.

Lulu

  • Sr. Member
  • ****
  • Posts: 265
Re: Mazemaker (efg)
« Reply #8 on: September 23, 2023, 09:57:03 am »
And then I found the problem Stack did not have a data type declared in the Variables
Var      Stack: TStack;
Hi, sorry to forget that line!
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #9 on: September 24, 2023, 06:41:18 am »
Ah Lulu can't thank you enough for that conversion. I played with ASM many years ago and lost knowledge of most of it.
The maze program draws much faster for the bigger sizes under 64Bits.

fred

  • Full Member
  • ***
  • Posts: 201
Re: Mazemaker (efg)
« Reply #10 on: September 24, 2023, 10:23:41 am »
I had made some small changes for saving the image:
For SavePictureDialogMaze I have set ofOverwriteprompt to True

In Filter I added:
PNG (*.png)

Set PNG as Default and first in the list of filters.

Replaced:
ImageMaze.Picture.Bitmap.SaveToFile(SavePictureDialogMaze.Filename);
with:
ImageMaze.Picture.SaveToFile(SavePictureDialogMaze.Filename);

The PNG files are much smaller then the bitmaps.
Of course you can always print as PDF :)


Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #11 on: September 25, 2023, 12:13:21 am »
Thank you Fred.

Those steps worked well and certainly made the image file size much smaller (with only a few targeted changes).

Much appreciated.

Boleeman

  • Hero Member
  • *****
  • Posts: 722
Re: Mazemaker (efg)
« Reply #12 on: September 25, 2023, 07:32:11 am »
Been playing around with another maze maker based on Prim's Algo and Depth First Transversal solutions.
When you resize the window of the program the scrollbar max value changes.
Solution path is also not as complex as the Efg version and no rainbow path.
« Last Edit: September 26, 2023, 01:29:31 am by Boleeman »

 

TinyPortal © 2005-2018