Willsy Posted August 19, 2015 Share Posted August 19, 2015 Here's a very very old game: Hunt the Wumpus. I think this game was originally developed in the early 70's and ran on most mini-computers of the day. Here's a version for TurboForth, ported from ANS Forth. Attribution for the original is contained in the source. Just paste it into Classic99 and type GAME. I think it works. I've never played it before, so dunno! Seems okay though! ( Hunt the Wumpus - JCB 16:42 01/15/11) ( Converted for Forth-83 - Mark Wills August 2015 ) ( from ANS code written by James Bowman. ) ( Original program here: ) ( http://excamera.com/sphinx/article-wumpus.html#wumpus ) ( Changes: ) ( definition RANDOM removed. Not needed for Turboforth ) ( defintion @+ removed - TurboForth has @++ ) ( definition 2VARIABLE added ) ( definition 2@ added ) ( definition 2! added ) decimal : 2variable ( execution: a-addr ) \ MRW 5th August 2015 create 0 , 0 , ; : 2@ ( a-addr -- x1 x2 ) \ MRW 5th August 2015 dup 2+ @ swap @ ; : 2! ( x1 x2 a-addr -- ) \ MRW 5th August 2015 swap over ! 2+ ! ; : m 1- , ; \ original map was 1-based, we are 0-based : triples create does> swap 3 * cells + ; triples map ( r -- addr ) \ address of room r 2 m 5 m 8 m 1 m 3 m 10 m 2 m 4 m 12 m 3 m 5 m 14 m 1 m 4 m 6 m 5 m 7 m 15 m 6 m 8 m 17 m 1 m 7 m 9 m 8 m 10 m 18 m 2 m 9 m 11 m 10 m 12 m 19 m 3 m 11 m 13 m 12 m 14 m 20 m 4 m 13 m 15 m 6 m 14 m 16 m 15 m 17 m 20 m 7 m 16 m 18 m 9 m 17 m 19 m 11 m 18 m 20 m 13 m 16 m 19 m 20 m 20 m 20 m \ impossible room for lost arrow : randroom ( -- n ) 20 rnd ; variable you variable wumpus 2variable pits 2variable bats : bounds ( a n -- a+n a ) over + swap ; : exits ( u -- u0 u1 u2 ) \ exits for room u map @++ swap @++ swap @ ; : isexit ( e r -- f) \ is e an exit for room r map 2dup @ = >r cell+ 2dup @ = >r cell+ @ = r> or r> or ; : nearyou ( r -- f ) \ is room r next to player you @ isexit ; : 2nearyou ( r0 r1 -- f ) \ is either room next to player >r nearyou r> nearyou or ; : atyou ( r -- f ) \ is player at room r you @ = ; : 2atyou ( r0 r1 -- f ) \ is player at room >r atyou r> atyou or ; : getroom ( -- n ) \ input room number from console tib @ 5 expect bl word number drop ; : warn ( addr u f -- ) \ if f, type line addr,u if cr type else 2drop then ; variable gameover : endgame ( addr u -- ) cr type true gameover ! ; : losegame ( addr u -- ) endgame cr ." HA HA HA - YOU LOSE!" ; : wingame ( addr u -- ) endgame cr ." HEE HEE HEE - THE WUMPUS'LL GETCHA NEXT TIME!!" ; : wakewumpus ( -- ) 4 rnd dup 3 = if drop \ wumpus stays else \ wumpus moves cells wumpus @ map + @ wumpus ! then wumpus @ atyou if s" TSK TSK TSK- WUMPUS GOT YOU!" losegame then ; : moveplayer ( r -- c ) \ move player to room r, check for hazards you ! wumpus @ atyou if cr ." OOPS! BUMPED A WUMPUS" wakewumpus then pits 2@ 2atyou if s" YYYIIIIEEEE . . . FELL IN PIT" losegame then bats 2@ 2atyou if cr ." ZAP--SUPER BAT SNATCH! ELSEWHEREVILLE FOR YOU!" randroom recurse then ; : domove begin cr ." Where to? " getroom dup nearyou 0= while cr ." -Not possible" repeat moveplayer ; : doshoot begin cr ." No. of rooms (1-5) " getroom dup 1 6 within until you @ swap \ arrow position on stack 0 do cr ." ROOM #" i . ." ? " getroom 2dup isexit if nip else 2drop 20 then wumpus @ over = if s" AHA! YOU GOT THE WUMPUS!" wingame then loop gameover @ 0= if cr ." Missed" then drop ; : upper ( a -- a|a-32) \ convert a character to upper case dup 96 > if 32 - then ; : pick1 ( k0 k1 -- k ) \ wait for key k0 or k1 begin key upper >r over r@ = over r@ = or until ; : gameloop cr s" I smell a Wumpus!" wumpus @ nearyou warn s" I feel a draft!" pits 2@ 2nearyou warn s" Bats nearby!" bats 2@ 2nearyou warn cr ." You are in room " you @ . cr ." Tunnels lead to " you @ exits . . . cr ." Shoot or move (S-M)? " begin key upper dup ascii M = over ascii S = or until dup emit ascii M = if domove else doshoot wakewumpus then ; : cheat cr ." you " you @ . ." wumpus " wumpus @ . ." bats " bats 2@ . . ." pits " pits 2@ . . ; : setup 20 0 do i loop 50 0 do randroom roll loop you ! wumpus ! bats 2! pits 2! 14 0 do drop loop ; : wait ( -- ) \ wait for key and clear screen 0 23 gotoxy ." Press any key..." begin key? -1 > until page ; : instructions 0 gmode cr ." WELCOME TO 'HUNT THE WUMPUS'" cr cr ." The wumpus lives in a cave of 20 rooms. " ." Each room has 3 tunnels leading to other" ." rooms. (look at a dodecahedron to see " ." how this works - if you don't know what " ." a dodecahedron is, ask someone!)" cr cr ." HAZARDS:" cr ." *BOTTOMLESS PITS: two rooms have bottom-" ." less pits in them. If you go there, you " ." fall into the pit (& lose!)" cr cr ." * SUPER BATS: two other rooms have super" ." bats. if you go there, a bat grabs you " ." and takes you to some other room at " ." random. (which might be troublesome!)" cr wait ." * WUMPUS: the wumpus is not bothered by " ." the hazards (he has sucker feet and is " ." too big for a bat to lift). Usually he " ." is asleep. Two things wake him up: your " ." entering his room or your shooting an " ." arrow. If the wumpus wakes, he moves one" ." room or stays still. After that, if he " ." is where you are, he eats you up and you" ." lose!" cr wait ." ABOUT YOU:" cr ." Each turn you may move or shoot an arrow" ." MOVING: you can go one room [thru one " ." tunnel)." cr ." ARROWS: you have 5 arrows. You lose when" ." you run out. Each arrow can go from 1 to" ." 5 rooms. You aim by telling the computer" ." the number of rooms you want the arrow " ." to go to. If the arrow can't go that way" ." [ie no tunnel) it moves at ramdom to the" ." next room. If the arrow hits the wumpus," ." you win. If the arrow hits you...." wait ." WARNINGS:" cr ." When you are one room away from wumpus " ." or hazard, the computer says:" cr ." Wumpus: 'i smell a wumpus'" cr ." Bat: 'bats nearby'" cr ." Pit: 'i feel a draft'" wait ; : yesno ( addr u -- f ) cr type begin key upper dup ascii Y = over ascii N = or until dup emit ascii Y = ; : game s" INSTRUCTIONS (Y-N) ? " yesno if instructions then begin setup 0 gameover ! begin gameloop gameover @ until s" Play again (Y-N) ? " yesno 0= until ; 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/ Share on other sites More sharing options...
+Schmitzi Posted August 19, 2015 Share Posted August 19, 2015 Hi Willsy, that sounds cool By using Classic99 v382 he tells me "GAME not found".... As I am oblivious to Forth, do you have any idea ? Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303483 Share on other sites More sharing options...
+Schmitzi Posted August 19, 2015 Share Posted August 19, 2015 ah, one more hint, maybe my my forth is somehow "broken", or not complete ? Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303484 Share on other sites More sharing options...
+Lee Stewart Posted August 19, 2015 Share Posted August 19, 2015 Hi Willsy, that sounds cool By using Classic99 v382 he tells me "GAME not found".... As I am oblivious to Forth, do you have any idea ? turbo-wump.JPG You did not get the “ok:n” after pasting the code and before executing it because you did not tap <enter>. Just entering a space before typing GAME would have worked, as well. Because there is no space or <enter> between ; (which would have completed the definition of game ), and your typing of GAME to start the game, you inadvertently asked the interpreter to look up the word ;GAME , which, of course, it didn't find, because that word was never defined. When you paste code like this, you often need to finish the process by tapping <enter> to get the last line interpreted. In this case, ; was not interpreted before you typed GAME . ...lee 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303553 Share on other sites More sharing options...
+Schmitzi Posted August 19, 2015 Share Posted August 19, 2015 ah-maze-ing - it works now thanks Lee. I have to do more on your lessons, really but time is my enemy these days.... Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303570 Share on other sites More sharing options...
Willsy Posted August 19, 2015 Author Share Posted August 19, 2015 (edited) ah, one more hint, maybe my my forth is somehow "broken", or not complete ? TurboForth-Block-1-error.JPG It's web browsers screwing up copy and paste again, I think. Open up this text file in your text editor. wumpus.txt Press CTRL and A then press CTRL C to copy it, then click on Edit then Paste in the Classic99 window. That should do it. And yes, it looks like you have a missing file. There should be a file called BLOCKS in your DSK1 folder (Look in your Classic99 folder, then look for the DSK1 folder, and check in there). Here is the file BLOCKS.zip Have fun! Edited August 19, 2015 by Willsy 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303575 Share on other sites More sharing options...
Omega-TI Posted August 19, 2015 Share Posted August 19, 2015 ah-maze-ing - it works now thanks Lee. I have to do more on your lessons, really but time is my enemy these days.... Truer words were never spoken. It sucks. I bought a cartridge and had a book printed up, and cannot find time to get to them. Hopefully this winter... .... and since I don't have time to check for myself, I'll just ask... will this work in fbForth? 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303576 Share on other sites More sharing options...
Willsy Posted August 19, 2015 Author Share Posted August 19, 2015 .... and since I don't have time to check for myself, I'll just ask... will this work in fbForth? Not without some (very minor) changes. Lee is the man for that! 2 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303579 Share on other sites More sharing options...
+Lee Stewart Posted August 19, 2015 Share Posted August 19, 2015 Truer words were never spoken. It sucks. I bought a cartridge and had a book printed up, and cannot find time to get to them. Hopefully this winter... .... and since I don't have time to check for myself, I'll just ask... will this work in fbForth? Not without some (very minor) changes. Lee is the man for that! I was waiting for the prompting, especially from you, @Willsy, because I hate co-opting your code all the time. ...lee 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303588 Share on other sites More sharing options...
Willsy Posted August 19, 2015 Author Share Posted August 19, 2015 No worries - it's all good - have at it - and please detail the changes so that I can get a better feel for fbForth. Probably better to do it in it's own (new) thread. 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303589 Share on other sites More sharing options...
+Vorticon Posted August 19, 2015 Share Posted August 19, 2015 The Wumpus ate me on the first try Now if I had a shotgun... 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303632 Share on other sites More sharing options...
+Schmitzi Posted August 19, 2015 Share Posted August 19, 2015 yep, and I ate the Wumpus The BLOCKS-file existed, but was from 2013. So I´ve overwritten it. But the solution was to set DSK1 back to FIAD, and to the referring folder Once I make it all right, it all works also have to check my brandnew fbForth-cart now thanks Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3303643 Share on other sites More sharing options...
+Lee Stewart Posted August 20, 2015 Share Posted August 20, 2015 Here's a very very old game: Hunt the Wumpus. I think this game was originally developed in the early 70's and ran on most mini-computers of the day. Here's a version for TurboForth, ported from ANS Forth. Attribution for the original is contained in the source. Just paste it into Classic99 and type GAME. I think it works. I've never played it before, so dunno! Seems okay though! \ . \ . \ . : doshoot begin cr ." No. of rooms (1-5) " getroom dup 1 6 within until you @ swap \ arrow position on stack 0 do cr ." ROOM #" i . ." ? " getroom 2dup isexit if nip else 2drop 20 then wumpus @ over = if s" AHA! YOU GOT THE WUMPUS!" wingame LEAVE then loop gameover @ 0= if cr ." Missed" then drop ; \ . \ . \ . There should be a LEAVE after wingame in doshoot to leave the loop. Getting more “Room #i ? ” prompts after you win is confusing. ...lee 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3304329 Share on other sites More sharing options...
Willsy Posted August 20, 2015 Author Share Posted August 20, 2015 Thanks, Lee. I'll update the source. Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3304569 Share on other sites More sharing options...
+Lee Stewart Posted August 22, 2015 Share Posted August 22, 2015 I found stack-pollution issues in the game that require mods of domove and doshoot . And, gameloop needs to check that the game is not over before executing wakewumpus . I will post those changes later. Right now I gotta get some yard work done! ...lee Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3305862 Share on other sites More sharing options...
Willsy Posted August 22, 2015 Author Share Posted August 22, 2015 Cool - I ported it as is, so I assumed it was working okay... Perhaps it's bugged. I can't imagine that my changes would introduce any bugs - but thanks for sticking with it - I wasn't expecting all this extra bug-hunting! Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3305865 Share on other sites More sharing options...
+Lee Stewart Posted August 22, 2015 Share Posted August 22, 2015 Cool - I ported it as is, so I assumed it was working okay... Perhaps it's bugged. I can't imagine that my changes would introduce any bugs - but thanks for sticking with it - I wasn't expecting all this extra bug-hunting! Well, I just noticed at the end of various games that the stack was getting polluted and I just needed to run the culprit(s) to ground. ...lee Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3305870 Share on other sites More sharing options...
+Lee Stewart Posted August 23, 2015 Share Posted August 23, 2015 Here are the changes for domove and doshoot and gameloop : : domove begin cr ." Where to? " getroom dup nearyou 0= while drop ( drop bad room) cr ." -Not possible" repeat moveplayer ; : doshoot 1 ( put something on stack for next DROP) begin drop ( remove last entry) cr ." No. of rooms (1-5) " getroom dup 1 6 within until you @ swap \ arrow position on stack 0 do cr ." ROOM #" i . ." ? " getroom 2dup isexit if nip else 2drop 20 then wumpus @ over = if s" AHA! YOU GOT THE WUMPUS!" wingame leave ( we're done with the loop) then loop gameover @ 0= if cr ." Missed" then drop ; : gameloop cr s" I smell a Wumpus!" wumpus @ nearyou warn s" I feel a draft!" pits 2@ 2nearyou warn s" Bats nearby!" bats 2@ 2nearyou warn cr ." You are in room " you @ . cr ." Tunnels lead to " you @ exits . . . cr ." Shoot or move (S-M)? " begin key upper dup ascii M = over ascii S = or until dup emit ascii M = if domove else doshoot gameover @ 0= if wakewumpus then ( only if game not over) then ; ...lee 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3306123 Share on other sites More sharing options...
Willsy Posted August 25, 2015 Author Share Posted August 25, 2015 Lee Thanks for the corrections - that's the source code on the website now updated, complete with a shout-out to yourself! 1 Quote Link to comment https://forums.atariage.com/topic/241822-turboforth-hunt-the-wumpus/#findComment-3307475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.