darkfrei wrote: ↑Sat Apr 01, 2023 9:55 am
glitchapp wrote: ↑Sat Apr 01, 2023 7:14 am
Hi, I'm still looking for problems to be solved with this project and I decided to try to find out a method to create proceduraly generated levels on the game.

To try to find an example I tested chatGPT for the first time to try to accomplish this and here is the answer I received:

It's not a sokoban, but sokoban with gravity, blocks (not just squares) and two agents, one of them is bigger and has property to move "heavy" blocks.

Hi darkfrei, I know, it is my first promt to chatGPT to try to solve a problem in lua and I was not sure if it would understand such a big question... it turns out it does, this is my second promt:

**<my_promt>** I need a function in lua to generate procedurally generated maps for a sokoban game with gravity, blocks (not just squares) and two agents, one of them is bigger and has property to move "heavy" blocks.

**<chatGPT>** One way to achieve this would be by using the `math` library in LuaJIT 2.0+ or a similar package for procedural generation functions (e.g., `generate_map`). Here's an example function that generates a map with two agents, one of them being bigger and able to move heavy blocks:

Code: Select all

```
```luvit
function generateMap(numAgents) -- numAgents is the number of agents in your game
local x = math.random() * (1024 - 512 + 1):floor():tointeger() // generates a random X coordinate for each agent on the map
local y = math.random()*(1024-512+1)//:floor():tointger() // generates a random Y coordinate for each agent on the map
if (numAgents == 2 and x > floor(x/3)) then -- bigger agents can move heavy blocks, so we need to check that they're not too close together in space. Otherwise it might be difficult or impossible to generate maps with two players of different sizes moving around each other without colliding
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they're not too close together)
elseif numAgents == 3 then // if there are three agents, we need to check that none of them have already moved into each other's space. Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding (either because they can move heavy blocks too)
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding
elseif numAgents == 5 then // if there are five agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of empty spaces and/or collision issues (either because none or only one player has moved into each other's space)
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 7 then // if there are seven agents, we need to check that none of them have already moved into each other's space. If not, the map will have a lot of empty spaces (either because they can move heavy blocks too) or collision issues (because all players might be moving around without colliding).
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space)
elseif numAgents == 9 then // if there are nine agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of empty spaces and/or collision issues because all players might be moving around without colliding (either because none or only one player has moved into each other's space)
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 10 then // if there are ten agents, we need to check that none of them have already moved into each other's space. If not, the map will have a lot of collision issues (either because they can move heavy blocks too) or empty spaces (because all players might be moving around without colliding).
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space)
elseif numAgents == 15 then // if there are fifteen agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of empty spaces and/or collision issues (either because none or only one player has moved into each other's space)
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 16 then // if there are sixteen agents, we need to check that none of them have already moved into each other's space. If not, the map will have a lot of collision issues (either because they can move heavy blocks too) or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 20 then // if there are twenty agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of collision issues (either because none or only one player has moved into each other's space) and/or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 30 then // if there are thirty agents, we need to check that none of them have already moved into each other's space. If not, the map will have a lot of collision issues (either because they can move heavy blocks too) or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 40 then // if there are forty agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of collision issues (either because none or only one player has moved into each other's space) and/or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 50 then // if there are fifty agents, we need to check that none of them have already moved into each other's space. If not, the map will have a lot of collision issues (either because they can move heavy blocks too) or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming none of them have already moved into each other's space). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 60 then // if there are sixty agents, we need to check that they can move heavy blocks too. If not, the map will have a lot of collision issues (either because none or only one player has moved into each other's space) and/or empty spaces
local bigAgentX = math.random()*1024:floor():tointeger() -- generates a random X coordinate for the bigger agent on the map (assuming they can move heavy blocks too). Otherwise it might be difficult or impossible to generate maps with all players moving around without colliding and/or having empty spaces
elseif numAgents == 70 then // if there are seventy agents, we need to check that none of them have already moved into each other's
```

It seems that it did not really understand that there are only 2 agents and created rules for up to 70 ... this was not intendeded but it could eventually be a cool new mechanics for multiplayer or more complicated puzzles...

I did a third promt and this time seems the function is better:

**Promt: **write a function in lua to generate procedurally generated maps for a sokoban game with gravity, blocks (not just squares) and two agents, one of them is bigger and has property to move "heavy" blocks.

Code: Select all

```
function createMap() {
local x = math.random(1024); // random starting position for the agent with heavy block moving ability (x coordinate)
local y = math.floor((math.pow(5, 3)) / 8 + math.mod(-y - 769, 8)); // randomly generate a new map by dividing an existing one into eight equal parts and then picking the first part to start with (x coordinate)
local z = x; // set starting position for agent moving heavy blocks at y-coordinate
while true do -- loop until all of the space is filled up or there are no more moves left in this direction.
if math.abs(y - floor((math.pow(5,3))/8 + x) > (x * z / 2016)^2 then break; // check to see whether agent can move any further downwards without hitting the bottom of a level or running into another block with heavy moving ability
if math.abs(-y - floor((math.pow(5,3))/8 + x) > (x * z / 1024)^2 then break; // check to see whether agent can move any further upwards without hitting the top of a level or running into another block with heavy moving ability
```

Unfortunately the I.A. get stuck in a loop and keep repeating the last line... I still think it can serve as a starting point and as a way to aproach the problem...

If anyone has access to the API of the full instance of chatGPT it may be interesting to compare results and see if they are better...