The Amazing Project

Started by TomToad, October 30, 2019, 20:44:40

Previous topic - Next topic

TomToad

Started a project called "The Amazing Project."  Basically I am writing programs that randomly generates mazes in different programming languages.  Here is what I have so far.http://www.tomtoad.com/amazingproject/index.html
Over time, I will add new languages as I learn more.  Feel free to use any of the code from the project if you have a need for generating mazes in your own game.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Xerra

Interesting stuff, this. How many languages do you plan to do this in?

M2 Pro Mac mini - 16GB 512 SSD
ACER Nitro 5 15.6" Gaming Laptop - Intel® Core™ i7, RTX 3050, 1 TB SSD
Vic 20 - 3.5k 1mhz 6502

Latest game - https://xerra.itch.io/Gridrunner
Blog: http://xerra.co.uk
Itch.IO: https://xerra.itch.io/

GrindalfGames


blinkok


RemiD


Pakz

There is this book called "mazes for programmers" Maybe every maze algorithm is in there. The language used was not that difficult to convert to monkey.

Steve Elliott

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

iWasAdam

Here's a slightly different approach, but gives nice mazes with lots of dead ends :)
It's for mx2/monkey2


Namespace myMojoApp

#Import "<std>"
#Import "<mojo>"
Using std..
Using mojo..

Const Size := New Vec2i( 950, 720 )
const Name:string = "FontSprite"
const Ver:string = "V1.17"

Function Main()
New AppInstance
New MyWindow
App.Run()
End


Class MyWindow Extends Window

Method New()
Super.New( "FontSprite Editor "+Ver, Size.X, Size.Y, WindowFlags.Resizable|WindowFlags.HighDPI )
SetMinSize( Size.X, Size.Y )

Layout = "fill"

ClearColor = Color.Black
End method

protected
'MUST be an odd number
const _mWidth:int = 17
const _mHeight:int = 13
field _maze:bool[, ] = New bool[_mWidth, _mHeight]
field _startX:ubyte = 0
field _startY:ubyte = 0
field _posX:ubyte
field _posY:ubyte
field _mMax:int = ((_mWidth-1) * 0.5) * ((_mHeight-1)*0.5)
field _mCount:int = 0

Method OnRender( canvas:Canvas ) Override
' canvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 )
local size:int = 25
local x:int
local y:int
local xp:int
local yp:int
canvas.Color = Color.Brick * 0.9
For y = 0 To _mHeight-1
xp = 0
For x = 0 To _mWidth-1
If _maze[x, y] Then
Else
canvas.DrawRect( xp, yp, size, size )
canvas.DrawFrame( xp, yp, size, size )
End if
xp += size
Next
yp += size
Next

If _startX = 0 Then return

canvas.Color = Color.Green
canvas.DrawRect( _posX*size+2, _posY*size+2, size-4, size-4 )
End

'x and y MUST be odd and within borders
method GetPosition()
_posX = (int(Rnd((_mWidth-1) * 0.5))*2)+1
_posY = (int(Rnd((_mHeight-1) * 0.5))*2)+1
End method

method ZeroMaze()
local x:int
local y:int
For y = 0 To _mHeight-1
For x = 0 To _mWidth-1
_maze[x, y] = False
Next
Next
_startX = 0
_startY = 0
_mCount = 0
End method

method CreateMaze()
'first pick a start both MUST be odd and within borders
Repeat
If _startX = 0 And _startY = 0 Then
GetPosition()
_startX = _posX
_startY = _posY
Else
'pick a direction
local dir:int = int(Rnd(4))
local newx:int = _posX
local newy:int = _posY
local newPos:bool = False
' Print dir+" "+_mCount
Select dir
Case 0 'left
newx = _posX-2
If newx > 0 And not _maze[ newx, _posY ] Then
_maze[ _posX-1, _posY ] = true
Else
newPos = True
End If
Case 1 'right
newx = _posX+2
If newx < _mWidth-1 And not _maze[ newx, _posY ] Then
_maze[ _posX+1, _posY ] = True
Else
newPos = True
End If
Case 2 'up
newy = _posY-2
If newy > 0 And not _maze[ _posX, newy ] Then
_maze[ _posX, _posY-1 ] = True
Else
newPos = True
End If
Case 3 'down
newy = _posY+2
If newy < _mHeight-1 And not _maze[ _posX, newy ] Then
_maze[ _posX, _posY+1 ] = true
Else
newPos = True
End If
End Select

'check and repeat if not valid
If newPos Then
Repeat
Repeat
GetPosition()
Until _maze[ _posX, _posY ] = True
until Not (_maze[ _posX-1, _posY ] and _maze[ _posX+1, _posY ] and _maze[ _posX, _posY-1 ] and _maze[ _posX, _posY+1 ])
Else
_posX = newx
_posY = newy
End If

End If
If Not _maze[ _posX, _posY ] Then _mCount += 1
_maze[ _posX, _posY ] = True
Until _mCount = _mMax
end method

Method OnKeyEvent( event:KeyEvent ) Override
Select event.Type
case EventType.KeyDown
ZeroMaze()
CreateMaze()

RequestRender()
End select
End method

End




3DzForMe

#8
@iWasAdam, nice work, I dabbled a little with Monkey2, although I was a pretty strong MonkeyX advocate, mainly the HTML5 variant. The forums being culled was a bit rubbish though. You've inspired me to revisit MonkeyX2 - a little.

You've inspired me to download CerburusX - I always had 32-bit OS until recently, yeah I know.
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

GaborD

Very cool! Really useful to have a code collection like this.
Now I want to make a maze based oldschool dungeon crawler. :)