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 KingdomPosts: 267 |
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: AustraliaPosts: 1094 |
@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. 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 KingdomPosts: 267 |
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 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 KingdomPosts: 267 |
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: CanadaPosts: 1082 |
Try this. Visit Vegipete's *Mite Library for cool programs. |
||||
Womble Senior Member Joined: 09/07/2020 Location: United KingdomPosts: 267 |
@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: BrazilPosts: 303 |
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: CanadaPosts: 1082 |
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 KingdomPosts: 267 |
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 KingdomPosts: 267 |
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 StatesPosts: 76 |
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 KingdomPosts: 267 |
Yes, that is correct, as stated at the beginning of the thread, this was an exercise based on a "Code Golf" challenge: 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 |