Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:10 18 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: Golfed Rogue (Youtube Video)

Author Message
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 02:20am 25 Oct 2020
Copy link to clipboard 
Print this post

Wombling around with my CMM2 today.  I found a snippet of QBASIC code, and a Dartford Basic solution to an old Code Golf Challenge to code a very small RogueLike Game.

I made a video of my running pogram and posted it on YouTube

I did a bit of research and cannot determine what licence the original code snippets were published under and if converting and commenting the code is allowed.  I included this header giving credit:
'---------------------------------------------------------------------------------
' Golfed Rogue
' https://codegolf.stackexchange.com/questions/7074/build-a-simple-roguelike
' also https://github.com/nrkn/SimpleRLGolf
' from a rec.games.roguelike.development post
' DLosc QBASIC solution modified and commented for CMM2 by Womble 24OCT2020
' v1.0 Tested under Firmware v5.05.06B15
'---------------------------------------------------------------------------------


I did use my own gLOCATE subroutine to help with the convertion:
'---------------------------------------------------------------------------------

SUB gLOCATE row%, col%
 LOCAL x% = col% -1                                           'Columns start at 1
 LOCAL y% = row% -1                                           'Rows start at 1
 IF x% < 0 OR x% > ( MM.HRES \ MM.INFO(FONTWIDTH) ) THEN      'max character in row
   x% = MM.HRES \ MM.INFO(FONTWIDTH)                          'set to max characters
 ENDIF
 IF y% < 0 OR y% > ( MM.VRES \ MM.INFO(FONTHEIGHT) ) THEN     'max rows onscreen
   y% = MM.VRES \ MM.INFO(FONTHEIGHT)                         'set to max rows
 ENDIF
 PRINT @((MM.INFO(FONTWIDTH)*x%),(MM.INFO(FONTHEIGHT)*y%))""; 'position cursor
 'where x is the character column, and y is the character row
 'https://www.thebackshed.com/forum/ViewTopic.phpPRINT TID=12778&PID=155313#155313#155313
END SUB

'---------------------------------------------------------------------------------

I used "MODE 2" because the font dimentions played nicely when mixing "PRINT" with "gLOCATE" some of the other screen modes did not line the cursor positions correctly under v5.05.06B15 and I have not tested on other firmware versions.

You could always figure it out and roll your own

What do you guys think ... am I OK posting the code here ???
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 03:15am 25 Oct 2020
Copy link to clipboard 
Print this post

@Womble,

The text below is in their legal section - one nasty/cheeky bit I saw was that by posting code on their site, in their words, you assign it as perpetually and irrevocably licensed to Stack Overflow on a worldwide, royalty-free, non-exclusive basis pursuant to Creative Commons licensing terms (CC BY-SA 4.0), and they go on to say that you can NOT revoke this license!

Based on the Creative Commons clause, I think you would be OK reposting with appropriate accreditation ( a private opinion, not legal advice).

In any event, nice work.

Doug.


  Quote  Subscriber Content

You agree that any and all content, including without limitation any and all text, graphics, logos, tools, photographs, images, illustrations, software or source code, audio and video, animations, and product feedback (collectively, “Content”) that you provide to the public Network (collectively, “Subscriber Content”), is perpetually and irrevocably licensed to Stack Overflow on a worldwide, royalty-free, non-exclusive basis pursuant to Creative Commons licensing terms (CC BY-SA 4.0), and you grant Stack Overflow the perpetual and irrevocable right and license to access, use, process, copy, distribute, export, display and to commercially exploit such Subscriber Content, even if such Subscriber Content has been contributed and subsequently removed by you as reasonably necessary to, for example (without limitation):

   Provide, maintain, and update the public Network
   Process lawful requests from law enforcement agencies and government agencies
   Prevent and address security incidents and data security features, support features, and to provide technical assistance as it may be required
   Aggregate data to provide product optimization

This means that you cannot revoke permission for Stack Overflow to publish, distribute, store and use such content and to allow others to have derivative rights to publish, distribute, store and use such content. The CC BY-SA 4.0 license terms are explained in further detail by Creative Commons, and the license terms applicable to content are explained in further detail here. You should be aware that all Public Content you contribute is available for public copy and redistribution, and all such Public Content must have appropriate attribution.

As stated above, by agreeing to these Public Network Terms you also agree to be bound by the terms and conditions of the Acceptable Use Policy incorporated herein, and hereby acknowledge and agree that any and all Public Content you provide to the public Network is governed by the Acceptable Use Policy.

Edited 2020-10-25 13:20 by panky
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 12:28pm 25 Oct 2020
Copy link to clipboard 
Print this post

  panky said  @Womble,

The text below is in their legal section - one nasty/cheeky bit I saw was that by posting code on their site, in their words, you assign it as perpetually and irrevocably licensed to Stack Overflow on a worldwide, royalty-free, non-exclusive basis pursuant to Creative Commons licensing terms (CC BY-SA 4.0), and they go on to say that you can NOT revoke this license!

Based on the Creative Commons clause, I think you would be OK reposting with appropriate accreditation ( a private opinion, not legal advice).

In any event, nice work.

Doug.

Thanks for your comments Doug.

I had noticed the terms on posting on Stack Exchange and agree they are being cheeky with that.
I even registered on their site to see if it was possible to message the author ... not as a new user, as far as I can work out.

I did a bit more digging, and the Stack Exchange Post is covered by Creative Commons licensing terms (CC BY-SA 3.0) because it was initially posted on 21 April 2015.  The link to that licence clearly states that
  Quote  You are free to:

   Share — copy and redistribute the material in any medium or format
   Adapt — remix, transform, and build upon the material
   for any purpose, even commercially.

This license is acceptable for Free Cultural Works.

   The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:

   Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

   ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

   No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.


Based on this here is my program, with appropriate attribution as per the above licence:
'---------------------------------------------------------------------------------
' Golfed Rogue
' https://codegolf.stackexchange.com/questions/7074/build-a-simple-roguelike
' also https://github.com/nrkn/SimpleRLGolf
' from a rec.games.roguelike.development post
' DLosc QBASIC solution posted on StackExchange on 21APL2015
' licenced under https://creativecommons.org/licenses/by-sa/3.0/
' modified and commented for CMM2 by Womble 26OCT2020
' v1.1 Tested under Firmware v5.05.06B15
'---------------------------------------------------------------------------------

'Set array option base to index from 0
OPTION BASE 0

MODE 2                             '640x400 resolution, this plays nice with gLOCATE

'clear the screen to avoid unwanted scrolling from the CMM2 user interace
CLS

DIM w(12,10)                       'Binary Wall Map Array, initially everything is 0 a wall

'Print the Map
COLOUR RGB(BROWN)
FOR r=1 TO 12                      'map row r
  READ d                          'Read map row data
  FOR c=1 TO 10                   'map column c  
     w(r,c) = (d*2 AND 2^c) > 0   'Decode into binary array 1 is a space, 0 is a wall
     PRINT CHR$(35-3*w(r,c));     'Print map with char35 # for walls and char32 for spaces
  NEXT c
  'PRINT d;                       'Debug dislay of decimal Map Data for that row
  PRINT                           'This prints a carriage return
NEXT r

'Print the user instructions
COLOUR RGB(WHITE)
gLOCATE 18,1 : PRINT "Arrow Keys to Move, TAB or ESC to exit"

i=2                                'Start row for @ character
j=2                                'Start column for @ character

MainLoop:
DO
  gLOCATE i,j
  COLOUR RGB(RED) : PRINT "@"     'Draw the @ character
  a$=""                 'Clear keyboard input string
  do while a$ = ""
     a$ = INKEY$        'Wait for keyboard input
  loop

  k=ASC(RIGHT$(a$,1))   'Keypress up 128, down 239, left 130, right 131 or TAB 9 ESC 27


  x=i+(k=129)-(k=128)   'Where are we trying to move to?
  y=j+(k=131)-(k=130)   'current location +1 +0 depending on k=left? + k=right? truth test

  COLOUR RGB(WHITE)
  gLOCATE 18,1 : PRINT "Arrow Keys to Move, TAB or ESC to exit"
  gLOCATE 20,1 : PRINT "                                         "       'Clear Debug Info
  gLOCATE 20,1 : PRINT "a$="a$, "keycode="k, "dest="x" x"y, "map="w(x,y) 'Print Debug Info

  gLOCATE i,j           'locate cursor to old @ location
  PRINT " "             'erase the old @ character

  IF w(x,y) THEN        'if new location is 1 a Space (ie. TRUE)
     i=x                'update the location for the @ character
     j=y                'otherwise location remains the same
  END IF

LOOP UNTIL k=9 OR k=27   'TAB or ESC key was pressed so exit


END                      'Exit the program gracefully


'---------------------------------------------------------------------------------

'Map Data (a binary string per row, 1 is space, 0 is wall)
DATA 48,438,390,510,252,765,765,252,510,390,438,48
'
'Map
'
'    ####  ####  =   48
'    #  #  #  #  =  438
'    #  ####  #  =  390
'    #        #  =  510
'    ##      ##  =  252
'     #      #   =  765
'     #      #   =  765
'    ##      ##  =  252
'    #        #  =  510
'    #  ####  #  =  390
'    #  #  #  #  =  438
'    ####  ####  =   48
'
'
'---------------------------------------------------------------------------------

SUB gLOCATE row%, col%
 LOCAL x% = col% -1                                           'Columns start at 1
 LOCAL y% = row% -1                                           'Rows start at 1
 IF x% < 0 OR x% > ( MM.HRES \ MM.INFO(FONTWIDTH) ) THEN      'max character in row
   x% = MM.HRES \ MM.INFO(FONTWIDTH)                          'set to max characters
 ENDIF
 IF y% < 0 OR y% > ( MM.VRES \ MM.INFO(FONTHEIGHT) ) THEN     'max rows onscreen
   y% = MM.VRES \ MM.INFO(FONTHEIGHT)                         'set to max rows
 ENDIF
 PRINT @((MM.INFO(FONTWIDTH)*x%),(MM.INFO(FONTHEIGHT)*y%))""; 'position cursor
 'where x is the character column, and y is the character row
 'https://www.thebackshed.com/forum/ViewTopic.phpPRINT TID=12778&PID=155313#155313#155313
END SUB

'---------------------------------------------------------------------------------

I have pretted it up, expanding on the terse original code, converted to run on the CMM2, restructured to remove the GOTO statements, and heavily commented the code to clarify how it works.

CMM2_golfed_rogue.zip

Hope it proves useful to someone.
Many thanks to the original poster Dlosc.
Obviously if anybody objects to this I will contact the forum admins to get it removed.

Womble
Edited 2020-10-27 01:13 by Womble
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 12:23am 27 Oct 2020
Copy link to clipboard 
Print this post

v1.3 showing Debug Info for the "Binary Wall Map Array"
CMM2_golfed_rogue_v1.3.zip
Wall = 0
Space = 1
map size defined by constants mapR and mapC

I'm currently working on a random map generator to expand the usefulness of this program.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 01:11am 27 Oct 2020
Copy link to clipboard 
Print this post

  Womble said  I'm currently working on a random map generator to expand the usefulness of this program.


Try this.
Visit Vegipete's *Mite Library for cool programs.
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 01:22am 27 Oct 2020
Copy link to clipboard 
Print this post

@Vegipete, Thanks for the suggestion.  

Yes I had looked at your program as a possible solution.

Also considering porting this to the CMM2.  I already have it generating maps using QBasic in DosBox.

Not decided which way to go.  May experiment with both.
Edited 2020-10-27 11:23 by Womble
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 10:58am 27 Oct 2020
Copy link to clipboard 
Print this post

I'm thinking in use some type of random map generator in Gauntlet too, maybe not in the "Arcade Mode", but something like "Survival Mode"... This would increase the game replay factor.

Even in "Into The Darkness" can benefit from it, as the game is something like a roguelike dungeon but with real-time action. A "Survival Mode" with a procedural death labyrinth I believe will be welcome to some players.

I will see the codes on this topic too. It's a good opportunity to make something that I'm procrastinating  [LOL

As my games don't adapt well to claustrophobic mazes, I will use some algorithms to create caverns, rooms, etc.
Edited 2020-10-27 21:25 by MauroXavier
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 06:14pm 27 Oct 2020
Copy link to clipboard 
Print this post

  Womble said  Also considering porting this to the CMM2.  I already have it generating maps using QBasic in DosBox.

Cool! It generates some neat maps!
CONST width = 200
CONST height = 150
boxize = MIN(MM.HRES/width,MM.VRES/height)
DIM Dungeon(width, height)
MODE 1,8
CLS
RH = 8
RV = 8

DO
 CLS
 MATH SET 0,Dungeon()
 StartX = INT(RND * (width - 2)) + 2
 StartY = INT(RND * (height - 2)) + 2
 X = StartX
 Y = StartY
 Direction = INT(RND * 4)

 FOR Steps = 1 TO width*height/4 '1000
   IF INT(RND * 16) = 1 THEN direction = INT(RND * 4)
   Dungeon(X, Y) = 1
   'PRINT @(x*8,y*12) "."
   BOX (x-1)*boxize,(y-1)*boxize,boxize,boxize,1,&h808080,&h404040  ' floor

   SELECT CASE direction
     CASE 0
       IF X > 2 THEN X = X - 1 ELSE direction = INT(RND * 4)
     CASE 1
       IF Y > 2 THEN Y = Y - 1 ELSE direction = INT(RND * 4)
     CASE 2
       IF X < (width - 1) THEN X = X + 1 ELSE direction = INT(RND * 4)
     CASE 3
       IF Y < (height - 1) THEN Y = Y + 1 ELSE direction = INT(RND * 4)
   END SELECT

   ' create random floor space
   IF INT(RND * 60) = 1 THEN
     RH2 = INT(RND * (RH \ 2)) + RH \ 2
     RV2 = INT(RND * (RV \ 2)) + RV \ 2
     FOR YY = Y - (RV2 \ 2) TO Y + (RV2 \ 2)
       FOR XX = X - (RH2 \ 2) TO X + (RH2 \ 2)
         IF YY > 2 AND YY < (height-1) AND XX > 2 AND XX < (width-1) THEN
           Dungeon(XX, YY) = 1
           'PRINT @(xx*8,yy*12) "."
           BOX (xx-1)*boxize,(yy-1)*boxize,boxize,boxize,1,&h808080,&h404040  ' floor
         END IF
       NEXT
     NEXT
   END IF

 NEXT

 ' put wall around perimeter of floors
 FOR Y = 2 TO height-1
   FOR X = 2 TO width-1
     IF Dungeon(X, Y) = 1 THEN  ' floor?
       FOR YY = Y - 1 TO Y + 1
         FOR XX = X - 1 TO X + 1
           IF Dungeon(XX, YY) = 0 THEN
             Dungeon(XX, YY) = 2
             'PRINT @(x*8,y*12) CHR$(177) '"X"
             BOX (xx-1)*boxize,(yy-1)*boxize,boxize,boxize,1,&hA04000,&h802000  ' wall
           END IF
         NEXT
       NEXT
     END IF
   NEXT
 NEXT

 'PRINT @(startx*8,starty*12) CHR$(255)
 BOX (startx-1)*boxize,(starty-1)*boxize,boxize,boxize,1,&h00F000,&h00F000  ' exit

 DO
   k$ = INKEY$
 LOOP UNTIL k$ <> ""
LOOP UNTIL k$ = "q"

END

Edited 2020-10-28 05:35 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 01:12am 28 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  Try this.

VegiPete ...

Many thanks for that

Your suggestion inspired me so I knocked this up today
'-------------------------------------------------------------------------------------------
' RogueLike using Random Maze Generator Subroutine
' v1.0 by Womble 27 October 2020
' https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=12987#157644
'
' Implementation of Eller's Algorithm:
'   Written by Vegipete (vegipete@gmail.com)
'   June 2020
' Subroutined and Modified by Womble 27 October 2020
' https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=12209
'
' Eller's algorithm generates pure simply connected mazes
' of arbitrary length.
' Horizontal/Vertical bias:
' .5 = even, lower = more horizontal,  higher = more vertical
' By introducing a deliberate 'bug', mazes with loops can
' be generated.
'
' RogueLike Elements of this program based on:
' Golfed Rogue
' https://codegolf.stackexchange.com/questions/7074/build-a-simple-roguelike
' also https://github.com/nrkn/SimpleRLGolf
' from a rec.games.roguelike.development post
' DLosc QBASIC solution posted on StackExchange on 21APL2015
' licenced under https://creativecommons.org/licenses/by-sa/3.0/
' modified and commented for CMM2 by Womble 26OCT2020
'
'-------------------------------------------------------------------------------------------


I realised that the credits were not clear enough, so tweaked it:


Here is the sourcecode: Ellers_MazeGenRogue.zip

Its a quick hack on my part, as a learning exercise.
Feel free to use or modify as you see fit.
My coding skills are very Rusty but I hope you like it

Many thanks to VegiPete for his Implementation of Eller's Algorithm.
CMM2: Maze Generating Program
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 01:26am 28 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  
  Womble said  Also considering porting this to the CMM2.  I already have it generating maps using QBasic in DosBox.

Cool! It generates some neat maps!
VegiPete_Rooms.zip

Cool

I like that one Pete  

Hope you dont mind, I tested it, added credits referencing your post and zipped it up before posting here rather than quoting the code again.
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 01:57am 25 Nov 2020
Copy link to clipboard 
Print this post

this seems to be just a stub? you can walk around but nothing else happens. i guess its a exercise for the read to add more?
 
Womble

Senior Member

Joined: 09/07/2020
Location: United Kingdom
Posts: 267
Posted: 11:12am 25 Nov 2020
Copy link to clipboard 
Print this post

  markboston36 said  this seems to be just a stub? you can walk around but nothing else happens. i guess its a exercise for the read to add more?

Yes, that is correct, as stated at the beginning of the thread, this was an exercise based on a "Code Golf" challenge:
  Womble said  Wombling around with my CMM2 today.  I found a snippet of QBASIC code, and a Dartford Basic solution to an old Code Golf Challenge to code a very small RogueLike Game.

I later modified it to use Eller's Algorithm (provided by VegiPete) to generate random mazes and allow you to trace a path through the maze.
You could use it as a basis for evaluating Dijkstra's Shortest Path First Algorithm (or similar), perhaps to control monsters to chase the player, but I have not gone down that path (pun intended).

Feel free to use or modify the code, enjoy.
Edited 2020-11-25 21:26 by Womble
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024