1. I need a simple hangman program
- Posted by Alfredo Brand <abrand at ALUMINA.COM.CO> Oct 03, 1998
- 473 views
------=_NextPart_000_000C_01BDEEC6.2C6CB920 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable can anybody give me a copy or tell where can I get it? Thanks folks!=20 ------=_NextPart_000_000C_01BDEEC6.2C6CB920 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>can anybody give me a copy or tell where can I get=20 it?</FONT></DIV> ------=_NextPart_000_000C_01BDEEC6.2C6CB920--
2. Re: I need a simple hangman program
- Posted by Nate Brooman <nateb at LOG.ON.CA> Oct 03, 1998
- 469 views
--------------4FF44107E5131DFCA686C2CC Easy. MAKE IT YOURSELF! - Nate Alfredo Brand wrote: > can anybody give me a copy or tell where can I get it?Thanks folks! --------------4FF44107E5131DFCA686C2CC <HTML> <BODY BGCOLOR="#FFFFFF"> Easy. MAKE IT YOURSELF! <P>- Nate <P>Alfredo Brand wrote: <BLOCKQUOTE TYPE=CITE> <FONT SIZE=-1>can anybody give me a copy or tell where can I get it?</FONT><FONT SIZE=-1>Thanks folks!</FONT></BLOCKQUOTE> </HTML> --------------4FF44107E5131DFCA686C2CC--
3. Re: I need a simple hangman program
- Posted by Alfredo Brand <abrand at ALUMINA.COM.CO> Oct 03, 1998
- 483 views
------=_NextPart_000_001F_01BDEF06.5E841A80 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable as a matter of fact I was thinking first to write it, but I don't have = much time and also I'm pretty new in Euphoria. Thanks anyway for your advice, the idea comes from a homework, but I'm = going to do the I best I can. -----Mensaje original----- De: Nate Brooman <nateb at LOG.ON.CA> Para: EUPHORIA at LISTSERV.MUOHIO.EDU <> Fecha: s=E1bado 3 de octubre de 1998 13:13 Asunto: Re: I need a simple hangman program Easy. MAKE IT YOURSELF!=20 - Nate=20 Alfredo Brand wrote:=20 can anybody give me a copy or tell where can I get it?Thanks = folks! =20 ------=_NextPart_000_001F_01BDEF06.5E841A80 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT color=3D#000000 size=3D2>as a matter of fact I was thinking = first to=20 write it, but I don't have much time and also I'm pretty new in=20 Euphoria.</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT><FONT size=3D2>Thanks anyway = for your=20 advice, the idea comes from a homework, but I'm going to do the I = best I=20 can.</FONT></DIV> <DIV><FONT size=3D2></FONT><FONT face=3DArial = size=3D2><B></B></FONT> </DIV> <DIV><FONT face=3DArial size=3D2><B>-----Mensaje = original-----</B><BR><B>De:=20 </B>Nate Brooman <<A=20 href=3D"mailto:nateb at LOG.ON.CA">nateb at LOG.ON.CA</A>><BR><B>Para: = </B><A=20 </A>=20 <><BR><B>Fecha: </B>sábado 3 de octubre de 1998 = 13:13<BR><B>Asunto:=20 </B>Re: I need a simple hangman program<BR><BR></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: = 5px"></FONT>Easy.=20 MAKE IT YOURSELF!=20 <P>- Nate=20 <P>Alfredo Brand wrote:=20 <BLOCKQUOTE TYPE =3D CITE> <FONT size=3D-1>can anybody give me = a copy=20 or tell where can I get it?</FONT><FONT size=3D-1>Thanks=20 ------=_NextPart_000_001F_01BDEF06.5E841A80--
4. Re: I need a simple hangman program
- Posted by Hawke <mdeland at NWINFO.NET> Oct 03, 1998
- 470 views
Alfredo wrote: >>Nate Brooman replied: >>Easy. MAKE IT YOURSELF! >as a matter of fact I was thinking first to write it, ignore nate's rude usage of all caps, and please don't let it discourage you. >but I don't have much time and also I'm pretty new in Euphoria. i don't have a lot of time myself, especially coming up, but i'll try to hammer out a prototype/outline that you may find usefull to follow... and, IMHO, we are **all** new to Euphoria... even the old-timers are _new_ to Euphoria, cuz it's a really new language (technically :) >Thanks anyway for your advice, the idea comes from a >homework, but I'm going to do the I best I can. this is the line that sorta bothered me, and why i won't write the -full- program out... unless it's not an actual homework assignment, but instead you got the idea in your head to make a hangman game *from* a homework assignment (i could interpret your sentence here either way) irregardless, i'm willing to help :) will try to have something hammered out in a hour or three, maybe a day or three =) --Hawke'
5. Re: I need a simple hangman program
- Posted by Matt Z Nunyabidness <matt1421 at JUNO.COM> Oct 03, 1998
- 443 views
- Last edited Oct 04, 1998
welcome aboard euphorian. I started say last month or a couple months ago. ___________________________ When it comes to programming languages, Euphoria is a cut above - matt1278 at juno.com and matt1421 at juno.com(and soon to be irisnmatt at prodigy.net. Then again, maybe not) Euphoria programmer Webbers: <A HREF=mailto:"matt1421 at juno.com">matt1421 at juno.com</A> or <A ___________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]
6. Re: I need a simple hangman program
- Posted by Hawke <mdeland at NWINFO.NET> Oct 03, 1998
- 463 views
- Last edited Oct 04, 1998
> Alfredo Brand wrote: > can anybody give me a copy or tell where can I get it? > Thanks folks! i whipped up this 'super simple' hangman program prototype. it has one deliberate bug, just for your coding enjoyment, and for my conscience to be clear... can't have the list doing homework now can we?? :) if you fix the bug (no hints please) then the program should work fine (at least as far as my mostly thorough debugging caught... it =seemed= to work fine for me) and you can play/improve to your hearts content. also: to those new guys in alan's tutorial class, yall may wanna jump in here, get your feet wet, see if yall can spot the bug, see if there is anything in the code you do/don't catch... if you think you spot the bug, email me direct... remember: no hints people :) and to those that spot the bug right off: no loud giggling, there's people thinking here =) without futher dribble a'la moi, here's the hangman.ex and i bid you all a restfull slumber--Hawke' ------------begin hangman.ex --******************************************** --*This program deliberately has a bug in it.* --*Your challenge is to find it & terminate * --*it with chili-flavored prejudice. * --******************************************** include get.e constant WordList = --ummm the words to guess mebbe? :) edit to your heart's content. --this version only accepts lowercase, and watch your quotemarks --and commas... EU is picky about sequence delimiters ;) --seems to me we were talking about that, we could just use --spaces to delimit with... *ducks a flame or three* "notepad","bottle","coupon","envelope","spiral", "papyrus","waveform","calendar","shellfish","thermostat", "medicine","pencil","lighter","receipt","lozenge", "manual","notice","driver","address","locale", "cardboard","diary","match","elongate","files", "swing","vacuum","heroes","pasta","crazed"} constant True=1, False=0 sequence GuessedLetters --the list of letters they attempted sequence Word --the word they are trying to guess sequence GuessedArray --an array holding True/False in each element that corresponds --to whether that location of word has a letter that has been --guessed. ie:if Word is "jello" and GuessedLetters is {l,j} then --GuessedArray will be {T,F,T,T,F} (T=True,F=False) atom KeyPress, GuessesLeft integer done object temp function GetWordToGuess() --randomly pick a word from the wordlist to guess integer len atom num len=length(WordList) num=rand(len) return WordList[num] end function procedure ShowWord(sequence glet,sequence wrd, sequence garr) --neatly display the letters that have been guessed already (glet) --and show the word they are working on (partially) as a list --of letters from the guessedletters list and '_' for the --elements of the word that have not been guessed, based upon --the true/false elements of the guessedarray (garr) --ie: if the word is 'powder' and they have guessed 'zawfr' then --display the 'zawfr' as well as '__w__r' to show their progress sequence temp integer len len=length(wrd) temp=repeat(0,len) clear_screen() position(10,30) for i=1 to len do if garr[i]=True then temp[i]=wrd[i] else temp[i]='_' end if end for puts(1,temp) position(20,1) puts(1,"Guessed Letters:" & glet) position(1,1) puts(1,"<ctrl-c> to quit") end procedure function UpdateGuessedArray(sequence garr,atom key,sequence wrd) --this is where the array of true/false elements corresponding --to the positions within Word that have been guessed gets --it's elements updated to reflect the last guess --can't use find() here, cuz it won't handle words --that have the same letter more than once for i=1 to length(wrd) do if wrd[i]=key then garr[i]=True end if end for return garr end function function UpdateGuessedLetters(sequence glet, atom key) --if the user didn't type a duplicate letter, then tag --their last letter typed onto the end of GuessedLetters(glet) for i=1 to length(glet) do if glet[i]=key then return glet end if --duplicate,no charge end for return glet & key --not in there, add it end function function WordGuessed(sequence garr) --are we done? we are done if there are no more False's --within the GuessedArray (garr) for i=1 to length(garr) do if garr[i]=False then return False end if end for return True end function function GetValidLetter() --wait for the user to actually type a letter of the alphabet --(as opposed to a number or other character) then return it atom temp integer ok ok=False while not ok do temp=wait_key() if temp<='a' and temp>='z' then ok=True end if end while return temp end function clear_screen() puts(1,"Hangman: Guess the word I'm thinking of in 12 guesses...\n") puts(1,"Press a key to begin, <ctrl-c> to quit") while get_key()=-1 do end while GuessesLeft =12 Word =GetWordToGuess() GuessedArray =repeat(False,length(Word)) GuessedLetters={} done =False ShowWord(GuessedLetters,Word,GuessedArray) while not done do KeyPress =GetValidLetter() GuessedArray =UpdateGuessedArray(GuessedArray,KeyPress,Word) temp =length(GuessedLetters) GuessedLetters=UpdateGuessedLetters(GuessedLetters,KeyPress) if temp != length(GuessedLetters) then --they didn't duplicate GuessesLeft = GuessesLeft-1 --so we charge them end if ShowWord(GuessedLetters,Word,GuessedArray) if GuessesLeft<=0 or WordGuessed(GuessedArray) then done=True end if end while position(24,1) if GuessesLeft > 0 then puts(1,"You won!") else puts(1,"Sorry! The word was:" & Word) end if --------------------end hangman.ex
7. Re: I need a simple hangman program
- Posted by Alfredo Brand <abrand at ALUMINA.COM.CO> Oct 04, 1998
- 458 views
- Last edited Oct 05, 1998
I'm going to run it and I'll let you know, thanks Hawke for your big help! -----Mensaje original----- De: Hawke <mdeland at NWINFO.NET> Para: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU> Fecha: sábado 3 de octubre de 1998 23:34 Asunto: Re: I need a simple hangman program >> Alfredo Brand wrote: >> can anybody give me a copy or tell where can I get it? >> Thanks folks! > >i whipped up this 'super simple' hangman program prototype. >it has one deliberate bug, just for your coding enjoyment, >and for my conscience to be clear... can't have the list doing >homework now can we?? :) > >if you fix the bug (no hints please) then the program >should work fine >(at least as far as my mostly thorough debugging caught... > it =seemed= to work fine for me) >and you can play/improve to your hearts content. > >also: to those new guys in alan's tutorial class, yall may >wanna jump in here, get your feet wet, see if yall can spot >the bug, see if there is anything in the code you do/don't >catch... > >if you think you spot the bug, email me direct... > >remember: no hints people :) >and to those that spot the bug right off: no loud giggling, > there's people thinking here =) > >without futher dribble a'la moi, here's the hangman.ex and >i bid you all a restfull slumber--Hawke' > >------------begin hangman.ex >--******************************************** >--*This program deliberately has a bug in it.* >--*Your challenge is to find it & terminate * >--*it with chili-flavored prejudice. * >--******************************************** > >include get.e > >constant WordList = >--ummm the words to guess mebbe? :) edit to your heart's content. >--this version only accepts lowercase, and watch your quotemarks >--and commas... EU is picky about sequence delimiters ;) >--seems to me we were talking about that, we could just use >--spaces to delimit with... *ducks a flame or three* > "notepad","bottle","coupon","envelope","spiral", > "papyrus","waveform","calendar","shellfish","thermostat", > "medicine","pencil","lighter","receipt","lozenge", > "manual","notice","driver","address","locale", > "cardboard","diary","match","elongate","files", > "swing","vacuum","heroes","pasta","crazed"} > >constant True=1, False=0 >sequence GuessedLetters --the list of letters they attempted >sequence Word --the word they are trying to guess > >sequence GuessedArray >--an array holding True/False in each element that corresponds >--to whether that location of word has a letter that has been >--guessed. ie:if Word is "jello" and GuessedLetters is {l,j} then >--GuessedArray will be {T,F,T,T,F} (T=True,F=False) > >atom KeyPress, GuessesLeft >integer done >object temp > >function GetWordToGuess() >--randomly pick a word from the wordlist to guess >integer len >atom num > len=length(WordList) > num=rand(len) > return WordList[num] >end function > >procedure ShowWord(sequence glet,sequence wrd, sequence garr) >--neatly display the letters that have been guessed already (glet) >--and show the word they are working on (partially) as a list >--of letters from the guessedletters list and '_' for the >--elements of the word that have not been guessed, based upon >--the true/false elements of the guessedarray (garr) >--ie: if the word is 'powder' and they have guessed 'zawfr' then >--display the 'zawfr' as well as '__w__r' to show their progress >sequence temp >integer len > len=length(wrd) > temp=repeat(0,len) > clear_screen() > position(10,30) > for i=1 to len do > if garr[i]=True then > temp[i]=wrd[i] > else temp[i]='_' > end if > end for > puts(1,temp) > position(20,1) > puts(1,"Guessed Letters:" & glet) > position(1,1) > puts(1,"<ctrl-c> to quit") >end procedure > >function UpdateGuessedArray(sequence garr,atom key,sequence wrd) >--this is where the array of true/false elements corresponding >--to the positions within Word that have been guessed gets >--it's elements updated to reflect the last guess >--can't use find() here, cuz it won't handle words >--that have the same letter more than once > for i=1 to length(wrd) do > if wrd[i]=key then garr[i]=True end if > end for > return garr >end function > >function UpdateGuessedLetters(sequence glet, atom key) >--if the user didn't type a duplicate letter, then tag >--their last letter typed onto the end of GuessedLetters(glet) > for i=1 to length(glet) do > if glet[i]=key then return glet end if --duplicate,no charge > end for > return glet & key --not in there, add it >end function > >function WordGuessed(sequence garr) >--are we done? we are done if there are no more False's >--within the GuessedArray (garr) > for i=1 to length(garr) do > if garr[i]=False then return False end if > end for > return True >end function > >function GetValidLetter() >--wait for the user to actually type a letter of the alphabet >--(as opposed to a number or other character) then return it >atom temp >integer ok > ok=False > while not ok do > temp=wait_key() > if temp<='a' and temp>='z' then > ok=True > end if > end while > return temp >end function > >clear_screen() >puts(1,"Hangman: Guess the word I'm thinking of in 12 guesses...\n") >puts(1,"Press a key to begin, <ctrl-c> to quit") >while get_key()=-1 do end while > >GuessesLeft =12 >Word =GetWordToGuess() >GuessedArray =repeat(False,length(Word)) >GuessedLetters={} >done =False > >ShowWord(GuessedLetters,Word,GuessedArray) > >while not done do > KeyPress =GetValidLetter() > GuessedArray =UpdateGuessedArray(GuessedArray,KeyPress,Word) > temp =length(GuessedLetters) > GuessedLetters=UpdateGuessedLetters(GuessedLetters,KeyPress) > > if temp != length(GuessedLetters) then --they didn't duplicate > GuessesLeft = GuessesLeft-1 --so we charge them > end if > > ShowWord(GuessedLetters,Word,GuessedArray) > if GuessesLeft<=0 or > WordGuessed(GuessedArray) > then done=True > end if >end while > >position(24,1) >if GuessesLeft > 0 then > puts(1,"You won!") >else puts(1,"Sorry! The word was:" & Word) >end if > >--------------------end hangman.ex
8. Re: I need a simple hangman program
- Posted by Hawke <mdeland at NWINFO.NET> Oct 04, 1998
- 467 views
- Last edited Oct 05, 1998
Alfredo Brand wrote: >thanks Hawke for your big help! yer quite welcome... enjoy--Hawke'
9. Re: I need a simple hangman program
- Posted by Lucius Hilley <lhilley at CDC.NET> Oct 18, 1998
- 460 views
Hawke, Pardon me! Let me introduce myself. I am Lucius Hilley III of Hollow Horse Software. I have been out of the Euphoria list for quite some time. I do however glance into the list archives occasionally. I have read several of your messages. I formerly welcome your expertise and enthusiasm. As for Nate. I was very fortunate to have not been around while that was occuring. [Hangman function] I have pasted your function below. It can use find(). It is however a bit tricky. I have pasted my version find() included version just beneath yours. Try it. I have. BTW, I never bothered timing the two for speed. PS: Since we are scanning short sequences this has little effect in efficiency. My guess is that using find() will actually be slower in these short cases. But if this were used in large sequences such as bitmaps or searching for Z's in a document then the find() method would prevail. [needle(s) in a haystack] >function UpdateGuessedArray(sequence garr,atom key,sequence wrd) >--this is where the array of true/false elements corresponding >--to the positions within Word that have been guessed gets >--it's elements updated to reflect the last guess >--can't use find() here, cuz it won't handle words >--that have the same letter more than once > for i=1 to length(wrd) do > if wrd[i]=key then > garr[i]=True > end if > end for > return garr >end function function UpdateGuessedArray(sequence garr,atom key,sequence wrd) integer i, last_i, len --this is where the array of true/false elements corresponding --to the positions within Word that have been guessed gets --it's elements updated to reflect the last guess --uses find because it is much faster for large sequences i = 0 len = length(wrd) last_i = find(key, wrd) while last_i do -- while i != 0 do -- might still be a faster, Robert? i = i + last_i garr[i] = True last_i = find(key, wrd[i + 1..len]) end while return garr end function --Lucius L. Hilley III lhilley at cdc.net --http://www.cdc.net/~lhilley --http://www.americanantiques.com --http://www.dragonvet.com
10. Re: I need a simple hangman program
- Posted by Hawke <mdeland at NWINFO.NET> Oct 18, 1998
- 473 views
Lucius Hilley wrote: >I am Lucius Hilley III yes, you've done very good work in the past... recognized the name right off, as someone not to be reckoned with :) >I formerly welcome your expertise and enthusiasm. thankee! >As for Nate. 'nuff said. > [Hangman function] > I have pasted your function below. It can use find(). actually, technically, it can indeed use find(). your usage of find() is one of two I thought of that could use find() and solve the problem. (the other solution of find() slices wrd instead of incrementing the index and passes smaller and smaller slices of wrd to find() ) so in that context, and taking my function comments literally, i rather misspoke myself when writing those comments. i meant (and should have said) that you cannot use find() efficiently, easily and neatly. remembering that this hangman program was written to assist 'newbies' to euphoria (one in particular), i tried many many different sets of code for almost every function in the program. the ones that won and were included into that hangman program were the ones that strongly met 2 conditions; namely:speed and ease of reading/understanding. why speed? naturally, you wouldn't want to show a newcomer sloppy, inefficient code if you could help it... starts them off with bad habits, dontcha think? the other condition i think is self-evident considering the context and goal of the program (being a teaching aid). your routine works, and I'm glad you spotted that comment and how it was phrased. whilst teaching, precision is paramount, and you receive my official kudo of 'good eyes'. :) > BTW, I never bothered timing the two for speed. i had, prior to the posting of the function/program... >My guess is..find() will..be slower in..short cases. >But if..used in large sequences..then..find()..would prevail. unfortunately, your guess as to speed using find() is rather incorrect, which is why the function i put in the program 'won'. (i also think it's easier to understand) i present the following benchmark program and results, and if you see a grievous error in my testing, please, by all means, inform me and I/we shall remedy it tootsweet. :) ----begin code include machine.e tick_rate(1000) constant True=1 constant Blank="\r" & repeat(' ',70) & "\r" sequence Word,GuessArray atom now,key object junk function UpdateHawke(sequence garr,atom key,sequence wrd) --my original function, sans comments for i=1 to length(wrd) do if wrd[i]=key then garr[i]=True end if end for return garr end function function UpdateLucius(sequence garr,atom key,sequence wrd) --lucius' function posted to the listserv, sans comments integer i, last_i, len i = 0 len = length(wrd) last_i = find(key, wrd) while last_i do -- while i != 0 do -- might still be a faster, Robert? i = i + last_i garr[i] = True last_i = find(key, wrd[i + 1..len]) end while return garr end function procedure Pause() puts(1,"\nPress a key...") while get_key()=-1 do end while puts(1,Blank) --erase Press a key... end procedure function RandLetter() return rand(26) + 'a' end function procedure benchmark(integer size) --init key=RandLetter() puts(1,"Building sequences...") Word = repeat(0,size) GuessArray = repeat(0,size) for z=1 to size do Word[z] = RandLetter() end for puts(1,Blank) --erase Building sequences... --benchmark printf(1,"%9d ",size) junk = {} now=time() junk=UpdateHawke(GuessArray,key,Word) now = time() - now printf(1,"%10.6f",now) junk = {} now=time() junk=UpdateLucius(GuessArray,key,Word) now = time() - now printf(1," %10.6f",now) Pause() end procedure puts(1, "Benchmark size" & " " & "UpdateHawke" & " " & "UpdateLucius\n") puts(1,repeat('-',50) & "\n") for z=5000 to 100000 by 5000 do benchmark(z) end for ---------- end code results on my machine:p200mmx,48Mram Benchmark size UpdateHawke UpdateLucius ------------------------------------------------- 5000 0.002000 0.050992 10000 0.003000 0.191971 15000 0.004999 0.467929 20000 0.006999 0.919860 25000 0.009998 1.404786 30000 0.011998 1.922707 35000 0.011998 2.922555 40000 0.014998 3.652444 45000 0.015998 4.733279 50000 0.018997 5.407177 55000 0.020997 7.004933 60000 0.021997 8.616688 65000 0.023996 9.984480 70000 0.028996 11.797204 75000 0.027996 14.100853 80000 0.030995 15.880582 85000 0.032995 18.426194 90000 0.034995 20.191925 95000 0.036994 22.964503 100000 0.037994 25.959047 i actually went to a size of a million... UpdateHawke was less than a second!!! UpdateLucius... well, I went to smoke a cig, came back over *ten minutes* later and it still hadn't posted a result... I gave up waiting... :) take care--Hawke'