Author Topic: Philippines in the maze  (Read 8133 times)

0 Members and 1 Guest are viewing this topic.

Offline lpy

  • Newbie
  • Posts: 6
    • View Profile
Re: Philippines in the maze
« Reply #15 on: August 02, 2020, 12:27:42 pm »
Hi. I tried compiling with 1.3 but still the same.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Philippines in the maze
« Reply #16 on: August 02, 2020, 01:43:30 pm »
I don't understand why. Try this last.

https://drive.google.com/file/d/1pkblbmBmmgsdPA1ZweaexACEDs5T9a93/view?usp=sharing

Is it ON ?
  [ You are not allowed to view this attachment ]  
« Last Edit: August 02, 2020, 01:45:53 pm by MasterGy »

Offline lpy

  • Newbie
  • Posts: 6
    • View Profile
Re: Philippines in the maze
« Reply #17 on: August 02, 2020, 01:58:51 pm »
Sorry still the same.

Yes, Output to EXE folder is ON.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Philippines in the maze
« Reply #18 on: August 02, 2020, 02:10:15 pm »
maybe someone knows the answer? I have no idea. :o

FellippeHeitor

  • Guest
Re: Philippines in the maze
« Reply #19 on: August 02, 2020, 02:11:13 pm »
Downloading to see.

FellippeHeitor

  • Guest
Re: Philippines in the maze
« Reply #20 on: August 02, 2020, 02:20:47 pm »
What is the main .bas to compile?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Philippines in the maze
« Reply #21 on: August 02, 2020, 02:33:13 pm »
Quote
What is the main .bas to compile?

First compile bas file in folder step1_track_creator7, this generate map after running [works right for me]
After compiling and running this first step, goto folder step2_game_with_ai_01 and compile and run file placed in this folder [works fine for me]

Very good work, MasterGY!
the plants in the game are made also really nice!
« Last Edit: August 02, 2020, 02:35:51 pm by Petr »

FellippeHeitor

  • Guest
Re: Philippines in the maze
« Reply #22 on: August 02, 2020, 02:47:44 pm »
I get the same error while trying to run br59_ki_19.bas in macOS (64bit):
  [ You are not allowed to view this attachment ]  

Something in your calculations for the REDIM ubt(bl_xs, bl_ys, bl_zs) AS _BIT array boundaries is getting weird results with 64bit calculation.

In Windows XP (32bit) it ran until the end. But then game_hum_23_ani10.bas won't run, because I don't have a D: drive:
Code: QB64: [Select]
  1. OPEN "d:\qqw.dat" FOR OUTPUT AS 33
« Last Edit: August 02, 2020, 02:50:42 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Philippines in the maze
« Reply #23 on: August 02, 2020, 02:53:57 pm »
I've uncommented the debug line right above line 1684, and these are the values being calculated for bl_xs, bl_ys, bl_zs when the program crashes using the 64bit compiler:

  [ You are not allowed to view this attachment ]  

Offline lpy

  • Newbie
  • Posts: 6
    • View Profile
Re: Philippines in the maze
« Reply #24 on: August 02, 2020, 03:41:24 pm »
Yep that was the solution for me too, running QB64 x32. It's working. The mouse sensitivity is way too high, but otherwise it's good.

Offline Galleon

  • QB64 Developer
  • Newbie
  • Posts: 25
    • View Profile
Re: Philippines in the maze
« Reply #25 on: August 02, 2020, 07:35:34 pm »
Quote
3d to go up the stairs, and so on…
The explanation I provided works just as well for 3D. The "grid" points can be in 3D space not 2D space and don't have to be in a grid-like fashion (you could hypothetically place a point in the middle of each step, but I would just make a 3D grid precise enough to cover all major step/platform/ramp heights [for a number of optimisation/simplicity reasons I don't care to explain], or use a combination of both). If you have point A around the bottom of some stairs and point B on the 3rd stair, by simulating/testing walking from A in the direction of B (using the same code logic which would apply to the player) the enemy will naturally walk up the stairs and reach point B even though it is at a different height, making that connection valid. If they don't reach point B then that connection is invalid. Take a look at the screenshot I posted previously, the grey lines are all the results of connections I tested which were recorded as valid. I'm not going to bother you with any further explanation/details unless you feel this is of use, but I did have fun writing the prototype. I've attached the proof of basic concept code but you would need to study/review/adapt it to make it suit your purpose.

Code: QB64: [Select]
  1. 'TODO: BUGS
  2. '  (no known bugs but this is just a prototype)
  3. 'TODO: OPTIMISATIONS
  4. '* Bi-directional search
  5. '* Cancel all rays on route to a just met ray
  6. '* optimize rayMovementDistance value (base this on previous results)
  7. '* do not init rays to already reached points
  8. '* do not init rays to points 2 or more away in a direct up/down/left/right direction
  9. '* Use activeRayIdList (WIP)
  10. 'TODO: FEATURES
  11. '* 3D layers
  12.  
  13. DEFLNG A-Z
  14. SCREEN _NEWIMAGE(1024, 768, 32)
  15.  
  16. mapImage = _LOADIMAGE("map.png")
  17.  
  18. mapWidth = _WIDTH(mapImage)
  19. mapHeight = _HEIGHT(mapImage)
  20.  
  21. REDIM SHARED map(-1 TO mapWidth + 1, -1 TO mapHeight + 1) AS _BYTE
  22. _SOURCE mapImage
  23. wall = 1
  24. FOR y = 0 TO _HEIGHT(mapImage) - 1
  25.     FOR x = 0 TO _WIDTH(mapImage) - 1
  26.         IF POINT(x, y) <> _RGBA(0, 0, 0, 255) THEN
  27.             map(x, y) = wall
  28.         END IF
  29.     NEXT
  30.  
  31. _PUTIMAGE (0, 0), mapImage
  32.  
  33. TYPE location
  34.     x AS SINGLE
  35.     y AS SINGLE
  36.     firstConnectionId AS LONG
  37.     'Used during path finding
  38.     reached AS LONG
  39.  
  40. granularity = 6
  41. locationsWidth = mapWidth / granularity
  42. locationsHeight = mapHeight / granularity
  43. REDIM SHARED locations(locationsWidth, locationsHeight) AS location
  44. FOR x = 0 TO locationsWidth
  45.     FOR y = 0 TO locationsHeight
  46.         locations(x, y).x = x * (mapWidth / locationsWidth)
  47.         locations(x, y).y = y * (mapHeight / locationsHeight)
  48.         PSET (locations(x, y).x, locations(x, y).y), _RGB(255, 255, 255)
  49.     NEXT
  50.  
  51. TYPE connection
  52.     destLocationX AS LONG
  53.     destLocationY AS LONG
  54.     distanceCost AS LONG
  55.     nextConnectionId AS LONG
  56.  
  57. REDIM SHARED connections(1000000) AS connection
  58. DIM SHARED finalConnectionId
  59. finalConnectionId = -1
  60.  
  61.  
  62.  
  63. maxConnectionDistance = 4
  64. 'build connections
  65. FOR y = 0 TO locationsHeight
  66.     FOR x = 0 TO locationsWidth
  67.         lastConnection = -1
  68.         FOR y2 = y - maxConnectionDistance TO y + maxConnectionDistance
  69.             FOR x2 = x - maxConnectionDistance TO x + maxConnectionDistance
  70.  
  71.  
  72.                 'Test: an entity walking from point1 in the direction of point 2 will arrive at point 2 without encountering any obstructions
  73.                 'Note: this part of the code is a mess because I coded it in the quickest way I could think of, it would be replaced with real code for walking the character and detecting if point 2 is actually reached
  74.                 IF y2 >= 0 AND y2 <= locationsHeight THEN
  75.                     IF x2 >= 0 AND x2 <= locationsWidth THEN
  76.                         IF x <> x2 OR y <> y2 THEN
  77.                             DIM xx1 AS SINGLE, yy1 AS SINGLE
  78.                             DIM xx2 AS SINGLE, yy2 AS SINGLE
  79.                             DIM dx AS SINGLE, dy AS SINGLE
  80.                             xx1 = locations(x, y).x
  81.                             yy1 = locations(x, y).y
  82.                             xx2 = locations(x2, y2).x
  83.                             yy2 = locations(x2, y2).y
  84.                             steps = granularity * 2
  85.                             dx = (xx2 - xx1) / steps
  86.                             dy = (yy2 - yy1) / steps
  87.                             blocked = 0
  88.                             FOR i = 0 TO steps
  89.                                 xx1i = xx1
  90.                                 yy1i = yy1
  91.                                 IF map(xx1i, yy1i) = 1 THEN blocked = 1: EXIT FOR
  92.                                 IF map(xx1i + 1, yy1i) = 1 THEN blocked = 1: EXIT FOR
  93.                                 IF map(xx1i - 1, yy1i) = 1 THEN blocked = 1: EXIT FOR
  94.                                 IF map(xx1i, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  95.                                 IF map(xx1i, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  96.                                 IF map(xx1i - 1, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  97.                                 IF map(xx1i - 1, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  98.                                 IF map(xx1i + 1, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  99.                                 IF map(xx1i + 1, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  100.                                 xx1 = xx1 + dx
  101.                                 yy1 = yy1 + dy
  102.                                 IF map(xx1i, yy1i) = 1 THEN blocked = 1: EXIT FOR
  103.                                 IF map(xx1i + 1, yy1i) = 1 THEN blocked = 1: EXIT FOR
  104.                                 IF map(xx1i - 1, yy1i) = 1 THEN blocked = 1: EXIT FOR
  105.                                 IF map(xx1i, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  106.                                 IF map(xx1i, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  107.                                 IF map(xx1i - 1, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  108.                                 IF map(xx1i - 1, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  109.                                 IF map(xx1i + 1, yy1i + 1) = 1 THEN blocked = 1: EXIT FOR
  110.                                 IF map(xx1i + 1, yy1i - 1) = 1 THEN blocked = 1: EXIT FOR
  111.                             NEXT
  112.  
  113.  
  114.                             IF blocked THEN
  115.  
  116.                             ELSE
  117.                                 LINE (locations(x, y).x, locations(x, y).y)-(xx2, yy2), _RGBA(128, 128, 128, 32)
  118.                                 finalConnectionId = finalConnectionId + 1
  119.                                 c = finalConnectionId
  120.  
  121.                                 IF lastConnection = -1 THEN
  122.                                     locations(x, y).firstConnectionId = c
  123.                                 ELSE
  124.                                     connections(lastConnection).nextConnectionId = c
  125.                                 END IF
  126.                                 lastConnection = c
  127.  
  128.                                 connections(c).destLocationX = x2
  129.                                 connections(c).destLocationY = y2
  130.                                 connections(c).distanceCost = CLNG(SQR((xx2 - xx1) * (xx2 - xx1) + (yy2 - yy1) * (yy2 - yy1)) * 10) 'distance cost should be calculated by movement test above
  131.  
  132.                             END IF
  133.                         END IF
  134.                     END IF
  135.                 END IF
  136.                 'test walkability
  137.             NEXT
  138.         NEXT
  139.     NEXT
  140.  
  141. TYPE ray
  142.     parentRayId AS LONG
  143.     connectionId AS LONG
  144.     distanceRemaining AS LONG
  145.     'destLocationX AS LONG
  146.     'destLocationY AS LONG
  147.  
  148. REDIM SHARED rays(1000000) AS ray
  149. lastRayId = -1
  150.  
  151. REDIM SHARED activeRayIdList(1000000) AS LONG
  152. lastActiveRayIdListId = -1
  153. REDIM SHARED activeRayIdListFreeIds(1000000) AS LONG
  154. lastActiveRayIdListFreeId = -1
  155.  
  156.  
  157. startX = 5
  158. startY = 20
  159. endX = 76
  160. endY = 55
  161.  
  162. 'add rays
  163. x = startX
  164. y = startY
  165. parentRayId = 0
  166. c = locations(x, y).firstConnectionId
  167.     lastRayId = lastRayId + 1
  168.     r = lastRayId
  169.     lastActiveRayIdListId = lastActiveRayIdListId + 1
  170.     activeRayIdList(lastActiveRayIdListId) = r
  171.     rays(r).parentRayId = parentRayId
  172.     rays(r).connectionId = c
  173.     rays(r).distanceRemaining = connections(c).distanceCost
  174.     c = connections(c).nextConnectionId
  175. PRINT lastRayId
  176.  
  177. finished = 0
  178. DO UNTIL finished
  179.     finished = 1
  180.     rayAdvancementDistance = 1
  181.     lastRayIdCached = lastRayId
  182.     FOR r = 0 TO lastRayIdCached
  183.         IF rays(r).distanceRemaining > 0 THEN
  184.             finished = 0
  185.             rays(r).distanceRemaining = rays(r).distanceRemaining - rayAdvancementDistance
  186.             ' PRINT rays(r).distanceRemaining
  187.             IF rays(r).distanceRemaining <= 0 THEN
  188.                 '      END
  189.  
  190.                 'a ray reached a destination
  191.                 c = rays(r).connectionId
  192.                 x = connections(c).destLocationX
  193.                 y = connections(c).destLocationY
  194.  
  195.                 IF locations(x, y).reached = 0 THEN
  196.                     PSET (locations(x, y).x, locations(x, y).y), _RGB(255, 255, 0)
  197.                     locations(x, y).reached = 1
  198.  
  199.                     IF x = endX AND y = endY THEN
  200.                         CIRCLE (locations(x, y).x, locations(x, y).y), 10, _RGB(255, 255, 0)
  201.                         'perform trace-back to build path
  202.                         DO WHILE r
  203.  
  204.  
  205.                             'a ray reached a destination
  206.                             c = rays(r).connectionId
  207.                             x = connections(c).destLocationX
  208.                             y = connections(c).destLocationY
  209.                             CIRCLE (locations(x, y).x, locations(x, y).y), 10, _RGB(255, 255, 0)
  210.  
  211.                             r = rays(r).parentRayId
  212.                         LOOP
  213.                         EXIT DO
  214.                     END IF
  215.  
  216.                     'add new rays
  217.                     parentRayId = r
  218.                     c2 = locations(x, y).firstConnectionId
  219.                     DO WHILE c2
  220.                         lastRayId = lastRayId + 1
  221.                         r2 = lastRayId
  222.                         lastActiveRayIdListId = lastActiveRayIdListId + 1
  223.                         activeRayIdList(lastActiveRayIdListId) = r
  224.                         rays(r2).parentRayId = parentRayId
  225.                         rays(r2).connectionId = c2
  226.                         rays(r2).distanceRemaining = connections(c2).distanceCost
  227.                         c2 = connections(c2).nextConnectionId
  228.                     LOOP
  229.                 END IF
  230.  
  231.             END IF
  232.         END IF
  233.     NEXT
  234.  
  235.  
« Last Edit: August 02, 2020, 07:46:49 pm by Galleon »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Philippines in the maze
« Reply #26 on: August 10, 2020, 01:13:42 pm »
Galleon! I finally managed to understand what you mean by AI. it wasn't entirely clear because of the translation, I didn't understand what you were thinking. I understand by now. This is a universal idea. You are absolutely right, this is a very walkable path! The idea is good! No matter what the surface is, 2d, or 3d, or even how many “ds,” the point is that points are connected, and if it is calculated in advance what is the shortest path from one to another, then the puppet is immediately the shortest, “smartest” will choose a path. Thanks, I’m going to think about it a lot on what principle I could use to score points on the playing field. And then there are a lot of calculations, and there will be a universal optimal direction! thanks for the idea, very useful thought!

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Philippines in the maze
« Reply #27 on: August 18, 2020, 03:55:58 pm »
Hi !
I develop. In the previous one, he was just throwing away the 2d elements and it was just decoration and the elements were just being thrown apart. They are now organized and animated and have an extent to stumble upon. Now it also perceives 2d elements as spatial extensions. Of course, I had to solve it so I could go through a forest if there were a lot of trees. For each element, you can specify a percentage of how much imaginary space the displayed image should be, large elements should not be 100 because you cannot go through the forest. There are forests, cornfields, sunflower fields, flower gardens. All random. I randomized what I could. I searched for gifs and solved them to animate the 2d elements. I still have a lot of ideas, I won’t test them for a try until you don’t get bored. :)



Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Philippines in the maze
« Reply #28 on: August 18, 2020, 04:23:54 pm »
WOW!

That is amazing!

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Philippines in the maze
« Reply #29 on: August 23, 2020, 06:15:36 am »
Hi !

The thing is going, my only problem is that it gives an “out of memory” 1 minute after starting the game and stops.
Is there something I didn't think of? Which escapes my attention? The game at the beginning loads everything you need. After that, it only uses what is in the memory. True, it loads a lot, but if it were too much, it would stop at the beginning of the program. no ?

What could be the problem ?

  [ You are not allowed to view this attachment ]  

I left only the starting bas in the package and a random track.
In the game, use the "F" key for flying mode.

https://drive.google.com/file/d/1qXWyoQLC2KkBwQ6BDOhLN8L80doAX24i/view?usp=sharing
« Last Edit: August 23, 2020, 06:24:21 am by MasterGy »