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

Offline lpy

  • Newbie
  • Posts: 6
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

  • Newbie
  • Posts: 70
  • people lie, math never lies
Re: Philippines in the maze
« Reply #16 on: August 02, 2020, 01:43:30 PM »
« Last Edit: August 02, 2020, 01:45:53 PM by MasterGy »

Offline lpy

  • Newbie
  • Posts: 6
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

  • Newbie
  • Posts: 70
  • people lie, math never lies
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

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2209
  • LET IT = BE
    • QB64.org
Re: Philippines in the maze
« Reply #19 on: August 02, 2020, 02:11:13 PM »
Downloading to see.

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2209
  • LET IT = BE
    • QB64.org
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: 1349
  • The best code is the DNA of the hops.
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 »

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2209
  • LET IT = BE
    • QB64.org
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):
 


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 »

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2209
  • LET IT = BE
    • QB64.org
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:

 

Offline lpy

  • Newbie
  • Posts: 6
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: 6
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 »