SyntaxBomb - Indie Coders

General Category => Worklogs => Topic started by: TomToad on October 30, 2019, 20:44:40

Title: The Amazing Project
Post by: TomToad on October 30, 2019, 20:44:40
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 (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.
Title: Re: The Amazing Project
Post by: Xerra on October 30, 2019, 21:20:01
Interesting stuff, this. How many languages do you plan to do this in?

Title: Re: The Amazing Project
Post by: grindalf on October 30, 2019, 21:44:19
Could you add Blitz3D?
Title: Re: The Amazing Project
Post by: blinkok on October 30, 2019, 22:08:01
AGK Basic too please
Title: Re: The Amazing Project
Post by: RemiD on October 31, 2019, 07:11:37
and Blitzmax ?
Title: Re: The Amazing Project
Post by: Pakz on October 31, 2019, 08:37:19
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.
Title: Re: The Amazing Project
Post by: Steve Elliott on October 31, 2019, 08:40:42
Thanks for sharing.   :)
Title: Re: The Amazing Project
Post by: iWasAdam on October 31, 2019, 08:59:20
Here's a slightly different approach, but gives nice mazes with lots of dead ends :)
It's for mx2/monkey2
Code: [Select]

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

(https://vjointeractive.files.wordpress.com/2019/10/screenshot-2019-10-31-at-08.56.37.png)
Title: Re: The Amazing Project
Post by: 3DzForMe on October 31, 2019, 23:24:05
@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.
Title: Re: The Amazing Project
Post by: GaborD on November 01, 2019, 19:29:08
Very cool! Really useful to have a code collection like this.
Now I want to make a maze based oldschool dungeon crawler. :)
SimplePortal 2.3.6 © 2008-2014, SimplePortal