Maze generator
Today, no business topic but it’s play time 🙂 A couple of days ago, I stumbled upon the free book “10 PRINT CHR$(205.5+RND(1)); : GOTO 10“. No joke, that’s the title of the book. It’s about an one-line Commodore 64 BASIC program that prints a maze to the screen. Because I’m a big fan of Retrocomputing, I browsed the book a little bit.
Afterwards I asked myself what ABAP report I could write in one line of 40 characters with a nice output. The answer was sobering: Nothing interesting. Even with 80 characters I just printed vertical lines to the screen 🙂 Here is my approach.
REPORT z.DO 10 TIMES.DO 80 TIMES.WRITE AT sy-index(1) '|'.ENDDO.NEW-LINE.ENDDO.
Finally I decided to give up the length restriction and wrote my own random maze generator as a homage to the original BASIC program. It uses the WRITE instruction and the characters “-” and “|” to build frames. You will find it on GitHub, too.
REPORT z_random_maze.
DATA: lr_random_int TYPE REF TO cl_abap_random_int,
lv_random_int TYPE i,
lv_position_x TYPE i,
lv_position_y TYPE i,
lv_maze_part TYPE char2.
lr_random_int = cl_abap_random_int=>create( seed = CONV i( sy-uzeit ) min = 1 max = 9 ).
DO 20 TIMES.
lv_position_y = sy-index.
lv_position_x = 1.
DO 30 TIMES.
CLEAR lv_maze_part.
IF lv_position_y = 20.
lv_maze_part = '--'.
ELSE.
lv_random_int = lr_random_int->get_next( ).
IF lv_random_int < 5.
lv_maze_part = '|'.
ELSEIF lv_random_int > 7.
lv_maze_part = '--'.
ENDIF.
ENDIF.
WRITE AT lv_position_x(2) lv_maze_part.
lv_position_x = lv_position_x + 2.
ENDDO.
NEW-LINE.
ENDDO.
Relax your eyes, try to find your way through the maze and have fun 🙂 Here is a little example of the report output. And if you have a good idea for an interesting one-liner in ABAP, let me know.
VERY cool!!!!
Pretty cool! Nice to know ABAP is still good for something. 🙂
Thanks for sharing!
Challenge accepted
nice combination of WRITE and SWITCH statement 🙂
Should I put it as an example into the documentation 😉
🙂
Hi Michael,
nice one 🙂
Btw. sharing your code with abapGit would make it easier to install
I'm very interested in. Next week I have more free time to look at abapGit. There is a lot of unreleased stuff lying here around. A good chance to start with abapGit :-))
make full use of ABAP's strengths 🙂
JNN
nice mix of modern ABAP (inline declaration) and old dinosaurs like ENDSELECT and WRITE 😉
I doubt that my Apfelmännchen can be squezzed into one line, but it can be shorten quite a lot.
fits to retro programming (at least the graphics...)
http://www.tricktresor.de/blog/apfelmaennchen/
Here is a very interesting website that collects 140-character-javascripts:Â https://www.dwitter.net/
What a fun post!!!!  Thank you for the nice break.
Michelle
You're welcome! I was really surprised of the interest. But perhaps we need more fun blogs to have more nice breaks 😉
Thats what we need - more ABAP computer games!
I support your request. Between all the business stuff we should have the chance to relax a minute without log out from our favorite erp 🙂 By the way: Enno has a nice collection of ABAP games under "http://www.tricktresor.de/blog/keywords/spiele/".
https://blogs.sap.com/2016/01/18/three-abap-games/
Great stuff, I shall do some reading up!
Have a look at http://www.richard-harper.me.uk/Kb/default.html Topic 'Downtime'.
Nice one. Well it depends on what you define as one-liner. Do we want to differentiate between number of statements or lines? The C64 example is two statements.
I think the king of one-liners is Horst Keller , with gems like
https://blogs.sap.com/2015/12/21/merry-happy-etc/Â and
https://blogs.sap.com/2015/04/10/abap-obfuscation-riddle/
Nice example!
In the system you find:
DEMO_JAWBREAKER_HTML_740,
DEMO_MINESWEEPER_740,
DEMO_GAME_2048_740
https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenexpressions_abexas.htm
Thanks for sharing. Home is getting better.
Awesome post. Did you see what Christian Drumm can do with mazes?
~Florian
Hmmm....
Retro computing.... You've set me going again.
I started a project to collect emulators or simulators of all the systems I have used during my programming career from a UK101 right upto an IBM System 370 running MVS and JES2 which I have managed to do (I(ncluding DGC Novas, PDP 11/70's, Vaxes etc etc....)
One thing I want to do is to get an 'IDES' version of R/2 and host it on the web so the newbies amongst us can see what they are missing....
I keep on bugging Horst Keller occasionally to see if he can help but I think he thinks I'm mad.....
Regards
Rich
I think that's a good idea. Every hardware and software is a little piece of computer history. In my office I have a printout of the Applesoft BASIC sourcecode of Breakout. Every time someone complains about modern development environments and programming languages, I ask if he would prefer to develop again in Applesoft BASIC 🙂 Unfortunately, for many people, there is no comparison of how great our technologies are today.