Forum > Games

Leap Frogs Logic Game now with Variable Size

<< < (2/5) > >>

Bart:
Nice one!
Took me a while to solve for > 2 frogs.


--- Quote from: dbannon on January 28, 2024, 10:56:18 am ---The spacing between 'frogs' messes up first time through. Press the reset button and its fine after that.

--- End quote ---

Move the code in OnCreate to OnShow then it works properly on Windows.
On other WS possibly not, in that case use Application.QueueAsyncCall(@SomeFormMethod,0) in OnShow, so the SomeFormMethod will be called after the window is actually created and shown.

I did not really investigate why the coördinates are off though.

Suggestion:
There must be some general algorithm to solve this game?
Would be nice to implement it and replay/animate the computated solution (especially for large amount of frogs).

Some more remarks: the succes_image for me only shows "Winner" then a newline and some pixels of the text below that.
The width/height of the TImage do not match the width/height of the TImage.Picture (should be easy fix).
Notice, when you do that the image is wider and it now is partly covered by the TMemo.
(An image might also be a bit of an overkill, a TLabel could also do the job...)

The TMemo with the instructions should be read-only.

Bart

Boleeman:
Not sure why others are getting errors. I compiled on Lazarus 32bit, and ran the program on Windows 10 probably 60 times and did not get any errors. Included is an animated gif of it working.


For those who did not pick up the pattern, have Red,Blue,Red,Blue,Red, etc. always alternating in that exact order.

I was going to do KodeZwerg's autosizing type coding, but wanted to get the game working for different sizes using a dynamic array. Actually there are 2 arrays one for the frogs shapes and the other for the positions. Perhaps the positions array needs to be freed, as I only freed the frogs shape array. I have only tested this on Windows 10, compiling with Lazarus 32bit compiler. I am kinda interested to find out why others are getting errors. Also maybe got to do with different operating systems?

Attached is an animated gif showing it working. Because I knew the pattern to the solution Red,Blue,Red,Blue,Red, etc., it was not that hard for me to swap the red and blue shapes to opposite sides.

The total number of moves is (numREDShapes + 1) squared  - 1

There is also a pattern to the types of moves: slide jump slide jump jump slide jump jump jump slide etc

The jumps increase by one separated by one slide each time.

dbannon:

--- Quote from: Boleeman on January 28, 2024, 01:26:04 pm ---Not sure why others are getting errors. I compiled on Lazarus 32bit, and ran the program on Windows 10 probably 60 times and did not get any errors. Included is an animated gif of it working.

--- End quote ---
Only the first run is broken. And not every time. Some uninitialized var ?



--- Quote from: Boleeman on January 28, 2024, 01:26:04 pm ---For those who did not pick up the pattern, have Red,Blue,Red,Blue,Red, etc. always alternating in that exact order.

--- End quote ---

No, its not red blue red blue etc at all ! For a 4 frog model, its B r r B B B r r r r B B B B r r r r B B B r r B
With the underlined ones being a slide, B=blue and r=red. Note the size of the groups go up, then down.  The secret, IHMO, is to work towards getting them alternating, in the middle of the game, then its obvious what to do.


--- Quote from: Boleeman on January 28, 2024, 01:26:04 pm ---Attached is an animated gif showing it working. Because I knew the pattern to the solution Red,Blue,Red,Blue,Red, etc., it was not that hard for me to swap the red and blue shapes to opposite sides.

--- End quote ---

Yes, very clever that animated gif, it allows you to demonstrate its possible and you can do it but too fast for us to see how its done !  Thaddy would be proud of you !

A great little puzzle, thanks !

Davo

KodeZwerg:
I've read my name so here's my contribution  :D
Just written in an extra hurry way, should be bulletproof anyway.
Extreme simplified gamelogic.
Enjoy!

// mini updated the autosizing, on a few values it is still a little buggy with the width but it not exceed the window range.

here is my game logic:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain.PanelClick(Sender: TObject);var  i: Integer;  Current,  Empty: Integer;begin  if (not (Sender is TPanel)) then    Exit;  // we increase tries no matter what clicked  Inc(FMoves);  lblMoves.Caption := 'Moves: ' + IntToStr(FMoves);  // find clicked element in array  for i := 0 to Pred(Length(FPanels)) do    if FPanels[i].Name = (Sender as TPanel).Name then      begin        Current := i;        Break;      end;  // find "white" element in array  for i := 0 to Pred(Length(FPanels)) do    if FPanels[i].Tag = 0 then      begin        Empty := i;        Break;      end;  // bad move blue  if (((Sender as TPanel).Tag = 1) and (Current > Empty)) then    Exit;  // bad move red  if (((Sender as TPanel).Tag = 2) and (Current < Empty)) then    Exit;  // bad move white  if (Sender as TPanel).Tag = 0 then    Exit;  // switch Tags  FPanels[Empty].Tag := (Sender as TPanel).Tag;  FPanels[Current].Tag := 0;  UpdateColors;  if CheckWon then    begin      lblMoves.Caption := lblMoves.Caption + ' You Won!';      RemoveClickEvent;    end;end;

Boleeman:
KodeZwerg, smart use of panels. The win logic is what I wanted to do but was struggling with when I was doing my version. Yours seems to have randomize in onCreate, but cannot work out why?


Davo (dbannon), you should see me on the large sizes after a cup of triple blended real coffee and dark chocolate.
Lucky I am not driving a sports car, other wise I'd be booked for speeding.



There is a Delphi Version at Davdata website at https://davdata.nl/math/goats.html where David has created the game where goats actually jump (but the game has only 3 levels). I tried to convert his Delphi code to Lazarus but it had some code and functions that I could not convert (actually got black parts of the screen instead of correct graphics showing as David does his own BMP format, WP would probably be able to do it as he is really good at Delphi conversions)

Would love to know how to do a jumping frogs version with frog noises. I have seen some JavaScript code that produces jumping frogs which I may try to convert when I remember where the site was. There are also various Scratch Block programming sources as well.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version