Solved

# One for the Experts...

Posted on 2011-10-09
313 Views
Okay, so it feels great to come up with a solution to a problem. It's even greater when it's a challenging problem. And greater still when your solution is "ACCEPTED" and you bag points.

So, I'd like to think Experts such as: paultomasi (that's me by the way), Qlemo, billprew, dragon-it, ReneGe, KnightEknight, oBdA, leew, BillDL (and whatever happened to AmazingTech?) infact, anyone who wants to participate, could take it in turn to think of a challenging question to be solved by us all.

It shouldn't be seen as a race and the aim is to share problem solving ideas and knowledge.

So, on that note, there are 500 points up for grabs for this first question....

QUESTION

Create a text-based hangman game

CPU randomly chooses a word from a 10-letter word-pool (seperate text file).

CPU initially displays 10 underscore characters and prompts user for letter.

At each turn, CPU displays:
number of turns so far ie, Turn #1 or whatever...
10-letter string containing mix of correctly guessed letters and underscores
number of lives remaining
A-Z list of available letters with underscores showing used letters
list of letters used so far

When entering letters (for each guess),
if a letter is entered it's treated as a letter
an incorrect letter costs a life
if a word is entered it's treated as a guess
an incorrect guess costs a life and play continues
a correct guess wins the game early

Play continues until either:
word is guessed (by entering whole word at any time)
all letters of word found (in which case word is guessed)
all lives lost

Socre for each round:
correctly guessed word:
lives remaining:
0: 1pt
1: 2pts
2: 3pts
3: 5pts
4: 8pts
5: 13pts
::
10: 89pts (unlikely unless you're psychic or VERY lucky!!)

points progress by adding previous number ie: 1, 2, 3, 5, 8, 13, 21, 34, 55 and 89.

otherwise, unguessed word = 0

Loop for 10 rounds of play showing 'Round number' or 'Game number' ... 1-10

At the end of each round, display correct word and score for that round.
Output word and score to file.

After 10 rounds (or when user quits play), read data from file and display following stats:
number of rounds played
display list of words played and score by side
average score

Notes:
when entering letters, will accept either case.
if letter already chosen - ignore it - do not lose a life
when displaying word - use uppercase letters/underscores
use lowercase when displaying A-Z available letter and letters used lists
display minimum short appropriate messages during game play

user can quit anytime if entering blank when required to enter letter however, user MUST be asked to confirm (Y/N) and either continue or end.

if user quits early, stats must still be displayed - what is displayed depends on what has been played.

Experts will submit their programs for other participating experts to run and to comment on / judge. Details to follow in a later comment - Ideas are welcome.

Code and comments can be posted any time.

The deadline for submitting programs is THREE days before the end of the month (to allow for judging). For this month, the deadline is midnight of 28 October.

The expert judged to have submitted the best program will receive points AND will set the next question. The deadline for setting the next quetion is midnight on the SEVENTH day of each month.

If an expert fails to set a question by this time, or decides to pass then it will be open for experts to decide who submits the next question. (Details will follow in a later post. Ideas are welcome).

RUles and conditions may well be fine-tuned as time goes on. Ideas are welcome.

FINALLY

To make it easy for all experts to run your code, confine your batch file AND any external files to a single directory. For example:

C:\EE\########\author\

where:

'########' is the EE ID question number.

Sub-directories may exist below (inside) this directory if required. Suggestions for naming conventions are:

C:\EE\########\author\TEMP
C:\EE\########\author\SOURCE
C:\EE\########\author\DESTINATION
etc...

All sub-directories must be created by your program.

Your batch file will reside in 'C:\EE\########\author\' and calls to sub-directories and files will be relative to this location.

Dummy files can be created using:

COPY NUL filename.extension >NUL

Any files needed to make your batch file run must also be submitted by you.

ALL FILES TO BE PLACED INSIDE A .ZIP FILE.

Basically, it should be as simple as just opening your .ZIP file and dragging your program etc into the 'C:\EE\########\author\ folder' and running the main batch file.  Please keep names short ie, for this assignment: HANGMAM.BAT will do.

Other details will be posted as and when. All ideas are welcome.

These instructions are bound to be fine-tuned as we progress.... It's early days, this is our FIRST challenge and there's bound to be teethig problems...

Good luck.

0
Question by:paultomasi

LVL 43

Expert Comment

hmm, i wonder when a question gets triggered as 'neglected' = 2800 points :-)

You must have way too much time on you hands Paul!!  Sounds like quite a challenge there to do in bitch, but I bet there will be several appearing any how.

I couldnt work out your puzzle question either!

steve
0

LVL 11

Author Comment

Steve

The puzzle question is pure genius...!! Believe me, when the solution is revealed you will be ABSOLUTELY amazed....

Too much time on my hands?.... No, not enough questions in this zone....

Also, think about it.... what better way of bumping up our points than to set each other questions....

But that's not the real reason.... It's mostly for fun and for a way to be creative and to express our ideas.

Anyway, I haven't started mine yet.... Will post back tonight....
0

LVL 8

Expert Comment

hmm.. i will wait for the answer, i think Renge will come up with something for sure. All the best RenGee.
0

LVL 95

Expert Comment

So this is a good challenge... I THINK I could do it... and eventually, I may well try... unfortunately, right now, I think this will take at least 30 - 90 minutes and I'm not sure when I'll get to it... (I've had limited time and haven't been on EE much lately) I'm going to stay subscribed and if I can dig up the time, I'll see what I can do.
0

LVL 11

Author Comment

leew

30-90 minutes sounds really optimistic....

I find breaking it down into modules and concentrating on just one aspect of the task I can focus more clearly. If I'm on the bus, a train, the loo, in the park or just about anywhere, I can whip out a small notebook and work on an algorithm....

It would be very courageous of anyone to attempt to complete the task in a single sitting or even a single day. That's NOT what this task is about.
0

LVL 95

Expert Comment

Maybe I underestimate it... or missed a key part or two... reading it, I could generally picture how everything would work... so I thought a "beta" would be done in 30-45 minutes and then 45-60 of debugging.

With your subsequent comment, I now feel I'm in the reverse position of what my friend and colleague once told our boss - Our boss wanted a calendaring system for our company... my friend John said "Lee and I can build it in a day"... (using ASP and SQL).  Well, that was at 2pm or so in the afternoon.  By 6am we walked out of the office - past our boss coming in for the day - and had the basic system in place... it needed weeks of tweaks and adjustments as a more defined set of requirements became more detailed... but it was basically functional in a day.

(And when we were done, it remained in use for about 6-7 years with no further modification from us (one of those things I'm most proud of, programmatically speaking).
0

LVL 11

Author Comment

TECHNICAL BITS

No additional processing was required. All words are saved in a single flat file named 10LETTERWORDS.TXT.

10LETTERWORDS.TXT
0

LVL 11

Author Comment

TECHNICAL BITS

Pulling a random 10-letter word from 10LETTERWORDS.TXT is not as straight forward as one might first think it is....

Speed could be a problem...
0

LVL 13

Expert Comment

are you saying you are required to use the 10letterwords.txt?
0

LVL 11

Author Comment

TECHNICAL BITS

Just noticed there are 20,404 words not 20,405. There was a blank line at line 12718.

See attached updated file.

Apologies!

10LETTERWORDS.TXT
0

LVL 43

Expert Comment

Paul,

Speed seems OK to me.... why would it be slow?  Method I used was fractions of a second to return a specific line.

Steve
0

LVL 11

Author Comment

5g6tdcv4

You can if you want to or you can pre-process the file in any way you think will help your program.

The only proviso is is that the FULL list of 20404 words must be available to your program.

The challenge here is:

1) how do you select a word at random
2) how do you address the issue of speed (or delay) or is this not a worry
3) how do you organise or pre-process your files (ie, a single flat text file etc...)

to name just a few early concerns....

0

LVL 43

Expert Comment

So are we supposed to share code as we go along or come up with a solution ll in one?
0

LVL 95

Expert Comment

Selecting a word at random is easy.  Speed... not sure...
0

LVL 43

Expert Comment

23:32:12.83
25620 is too big, redoing
The word to find is nonlegumes from line 11751
23:32:12.88
0

LVL 11

Author Comment

Steve (dragon-it)

There could be a small delay generating a random word due to the number of words in the word-pool (20,404).

Fractions of a second, eh?.... Sounds like we might be using the same method...
0

LVL 43

Expert Comment

A fairly obvious one I'd say Paul!
0

LVL 11

Author Comment

Steve (dragon-it)

Sharing code is good....

Leew

What method are you using leew?...

Steve (dragon-it)

That's pretty fast. What's inside your box? Mine's only a AMD 2-core Athlon 250

0

LVL 11

Author Comment

Steve (dragon-it)

I take it you're using %RANDOM%....
0

LVL 43

Expert Comment

i3-2100 3.1GHz, 6Gb, Win 7 64-bit .... bit better than the 10 year old P4 2.4Ghz, 1Gb RAM Win2000 I've been using until eventually got fed up with it!

roughly.... %Random%, find /n, find.
0

LVL 43

Expert Comment

which considering it was Â£280 quid I thought pretty good spec!
0

LVL 43

Expert Comment

Well this is as far as I've got.... and likely to get for the time being.  Postman Pat ringing away in my ears as #3 refuses to sleep and early wake up in the morn.  Interested to see what else anyone comes up with.
@echo off
setlocal enabledelayedexpansion

call :configure
call :setupwordlist

call :getrandom
call :getword "%linenum%"
echo The word to find is %Word% from line %linenum%

exit /b

REM **************************
REM Returns random no. 1-20405
REM into variable LineNum
REM **************************

:getrandom
set linenum=%random%
if %linenum% GTR 20405 (
echo %linenum% is too big, redoing
goto :getrandom
)
exit /b

REM **************************
REM Returns word from the line
REM specified on call to Word
REM **************************

:getword
set Word=
for /f "tokens=2 delims=]" %%A in ('find "[%~1]" %NumWords%') do set word=%%A
exit /b

REM **************************
REM General subs and functions
REM **************************

:configure
set FullWords="10letterwords.txt"
set NumWords="10letters.txt"
exit /b

:setupwordlist
find /n /v "###" %FullWords% > %NumWords%
exit /b

0

LVL 43

Expert Comment

Anyone seen how many there are on a google btw :-)

e.g. http://screwthelotofyou.webs.com/files/Hangman2
0

LVL 95

Expert Comment

This is what I mean... conceptually, I see what I'd be doing - even played around a bit...

yes, I'd be using %RANDOM% to get random numbers and then they would correspond to the word number.

But I'm getting some odd behavior that's me probably just doing something stupid and I don't have any more time to debug.
0

LVL 11

Author Comment

Wow!! Didn't even stop to think this might already have been done in batch language...

Well, let's hope we submit SOME original code....
0

LVL 11

Author Comment

TECHNICAL BITS

The obvious choice is to use %RANDOM%.

It would be neater to generate a number from 1 to 20404 say, something like this:
set /a rnd=%random% %% 20404 +1


Then, use that number to grab your word from your word list
0

LVL 43

Expert Comment

Haven't actually looked at the code....but the guy has done all sorts :-)
0

LVL 11

Author Comment

TECHNICAL BITS

Steve

I note you're using a pre-processed (ie, pre-inexed) file... Just what I had in mind too.

In my case I have:

n:w

where n is the index number (1 - 20404) and w is a 10-letter word

My word extraction looks like this:
for /f "tokens=2 delims=:" %%a in ('findstr /b "%index%:" 10letterwords.txt') do (

The file is (slightly) smaller than using 2 delimeters and a space. Using just 1 delimeter saves 40KB.

0

LVL 11

Author Comment

Steve, I'm not going to look at his code (yet)... I'm sure it's the dog's bollox (or should that be the mutt's nuts?).

At the moment, I'm more interested in OUR code.

We'll all favour different ways of tackling this I'm sure...

BTW, personally I'm NOT concerned about fancy screen presentation - the focus should be on logic, fucntionality, validation, clarity, design, style, ingenuity, use of DOS and the filesystem etc...
0

LVL 43

Expert Comment

Well I've got this running so far.... on account of being up still at 3am :-(
Hangman by Stephen Knight (dragon-it) for EE question 27387453

Round 1

Press letter keys, or 9 to have a full guess

[1] ___a______    (already tried _ A)
[2] ___a______    (already tried _ A E)
[3] _o_a______    (already tried _ A E O)
[4] _o_a_i_i__    (already tried _ A E O I)
[4] _o_a_i_i__    (already tried _ A E O I)
[5] _o_a_isi__    (already tried _ A E O I S)
[6] _o_a_isi__    (already tried _ A E O I S R)
[7] _o_a_isi__    (already tried _ A E O I S R B)
[8] _o_a_isi__    (already tried _ A E O I S R B P)
[9] _o_a_isi_g    (already tried _ A E O I S R B P G)
[10] _o_a_isi_g    (already tried _ A E O I S R B P G C)
[11] _o_alisi_g    (already tried _ A E O I S R B P G C L)
[12] _o_alising    (already tried _ A E O I S R B P G C L N)
[12] _o_alising    (already tried _ A E O I S R B P G C L N)
[13] _o_alising    (already tried _ A E O I S R B P G C L N D)
[14] _o_alising    (already tried _ A E O I S R B P G C L N D F)
[14] _o_alising    (already tried _ A E O I S R B P G C L N D F)
[15] _o_alising    (already tried _ A E O I S R B P G C L N D F J)

Time up.  Only 15 allowed.  The word was totalising

Press any key to continue . . .

0

LVL 11

Author Comment

Steve

Nice to see you've got the 'letters used' thing working.

By the way, the criteria called for 10 lives... A life is lost if you incorrectly guess a letter or a word.

If you duplicate a guess (letter or word) you don't lose another life - but a short polite message might serve to handle this event.

The game ends when:

1) entered a letter which completes the word
2) last life left, entered a letter & word still NOT completed
3) entered a 10-letter word which correctly guesses the word
4) last life left, entered a 10-letter word & word not guessed
5) enter nothing - confirm user wants to quit (Y/N) & quit

Anything else you enter is ignored or output short polite message.

Hope that makes it clearer.
0

LVL 43

Expert Comment

Yes, some of the criteria are a bit of a pain... not least the fact that the words in the file are in lower case and the "requirement" is for upper case ones... and the requirement to have the guesses etc. in lower case.

Could easily solve this by processing the file etc. but I don't think it loses anything by being the other way around.

15 lives was just my testing... to give me slight chance of finding the word... have you actually tried guessing some of those obscure 10 letter words!?

#1, #2, #3, #4, #5 working, though not exactly as your plan...
0

LVL 11

Author Comment

Would you prefer it if case was not a criteria? Only, case imposes the use of a couple of functions.

I haven't tried guessing any myself (I haven't got a working program yet) but I see some words I've never heared of.
0

LVL 43

Expert Comment

Well after a rough night of little sleep it gave me something to try and keep me awake.... so I've got one built here.... not strictly correct since it doesn't show the selected letters in lower case... but I thought that looked a bit messy?

It just needs the words file which is included in the zip.

Steve         ExampleRun1.txt ExampleRun2.txt 27387453.zip
0

LVL 11

Author Comment

Oops, sorry Steve....

Just run your code and got a continuous scrolling error:

[0] __________ [Lives:10. Tried:  ]
'choice' is not recognized as an internal or external command,
operable program or batch file.

FYI, I'm running XP Pro.

'VER'='Microsoft Windows XP [Version 5.1.2600]'

'HELP /?' doen't list 'CHOICE' as one of DOS' commands.
0

LVL 43

Expert Comment

Arse... is there on Windows Vista, 7 machines natively.... and the Server 2003 I normally end up scripting for... and think it is in the resource kits on XP but forgot wasn't native :-(

Can soon copy from another OS if that is acceptable?

e.g. this is the one from Server 2003:
www.dragon-it.co.uk/files/2003-choice.exe

Drop it in the path or in the same dir as the batch and call it choice.exe

Steve
0

LVL 51

Expert Comment

Here's the basic shell I got working yesterday afternoon.  Was going to wait until it was more polished to post, but since we seem to be in open source collaboration mode, here it is.

hangman.bat.txt words.txt
0

LVL 11

Author Comment

billprew

'Guesses reamining' should not count down if user chooses corrent letter in word.

Also, I guess displaying NEWWORD is for debug purposes (?)

Hmmm... 'Letters guessed' appends EVERY guess - even if duplicate or different case.

NOTE: Do you think it would be better to declare the use of uppercase letters throughout? It might add clarity to the program's logic... What's your opinion and is it too late to specify that at this stage?
0

LVL 11

Author Comment

Steve

[8] S__TI_I_E_ [Lives:2. Tried:  EAITSNRV]

however, 'Lives' should NOT decrease if a correct letter is guessed. Lives ONLY deplete for wrong guesses (letters or words).

0

LVL 43

Expert Comment

Ahh OK.  I see so it is not that you have 10 guesses then altogether, just 10 wrong guesses.... of course, durgh! hangman.1.21.cmd
Hangman by Stephen Knight (dragon-it) for EE question 27387453        ______
Version 1.21                                                          |    |
|    O
Round 02                                                              |   \|/
|    |
Press letter keys, 1 to quit, or 9 to have a full guess               |   / \
|_______
[1] ______A___ [Lives:10. Tried:  A]
[2] __E___A_E_ [Lives:10. Tried:  AE]
[3] __E___A_E_ [Lives:9. Tried:  AEO]
[4] __E___A_E_ [Lives:8. Tried:  AEOU]
[5] __E___A_E_ [Lives:7. Tried:  AEOUS]
[6] __E___ATE_ [Lives:7. Tried:  AEOUST]
[7] __E_R_ATE_ [Lives:7. Tried:  AEOUSTR]
[8] __EBR_ATE_ [Lives:7. Tried:  AEOUSTRB]
[9] __EBR_ATE_ [Lives:6. Tried:  AEOUSTRBC]
[9] __EBR_ATE_ [Lives:6. Tried:  AEOUSTRBC]
[10] __EBR_ATE_ [Lives:5. Tried:  AEOUSTRBCL]
[10] __EBR_ATE_ [Lives:5. Tried:  AEOUSTRBCL]
[11] __EBR_ATE_ [Lives:4. Tried:  AEOUSTRBCLV]
[12] __EBR_ATE_ [Lives:3. Tried:  AEOUSTRBCLVM]
[13] _NEBR_ATE_ [Lives:3. Tried:  AEOUSTRBCLVMN]
[13] _NEBR_ATE_ [Lives:3. Tried:  AEOUSTRBCLVMN]
[14] INEBRIATE_ [Lives:3. Tried:  AEOUSTRBCLVMNI]
[15] INEBRIATED [Lives:3. Tried:  AEOUSTRBCLVMNID]

===========================================================================

You got it  The word was INEBRIATED

Overall score: 0.  This game: 0

===========================================================================

Continue to the next round? [Y/N]

0

LVL 43

Expert Comment

Oops, that broke the scoring since it relied on "turns" rather than "lives".....  hangman.1.22.cmd
0

LVL 51

Expert Comment

@paultomasi

==> 'Guesses reamining' should not count down if user chooses corrent letter in word.

Ah, guess I should have known that (don't play hangman much :-) )

==> Also, I guess displaying NEWWORD is for debug purposes (?)

Correct, purely for testing.

==> Hmmm... 'Letters guessed' appends EVERY guess - even if duplicate or different case.

Yes, I figure since we're showing prior guesses each time then if the player is stupid enough to try the same letter they should lose a turn.

==> NOTE: Do you think it would be better to declare the use of uppercase letters throughout? It might ==> add clarity to the program's logic... What's your opinion and is it too late to specify that at this
==> stage?

Might not hurt I guess.

~bp
0

LVL 11

Author Comment

TECHNICAL BITS

Case-sensitivity requirement is trivial. I would suggest keeping everything in just one case (uppercase or lowercase - whichever you decide for your program).

If you decide to use uppercase, then you may convert the contents of 10LETTERWORDS.TXT to uppercase too if you so wish to do so.

The ONLY proviso here is that when a player enters a letter or text, it is validated, and if necessary, converted to your chosen case before moving on.
0

LVL 11

Author Comment

0

LVL 11

Author Comment

Okay, I've given this a little thought (not actually started coding yet)...

I'm going to incorporate (in my own program) the ability to continue from where a user quits with the option of starting from new.

My game is going to be file-based.

I haven't sketched a flowchart yet so I'm unsure about how I'm going to tackle each process at this early stage.

Steve (dragon-it) and billprew, you're way ahead of me at the moment...

Also, it would be nice to see something from subhashchy, ReneGe, leew and 5g6tdcv4.
0

LVL 43

Assisted Solution

Ok this is probably my final offer on this one... honest.  And note the option "8" to turn off the annoying new bit.

Steve
hangman.1.23.cmd
0

LVL 10

Expert Comment

Hey guys, I just ran into Paul's journey.
Working lots of hours. Will look at it soon!!

Cheers to you all,
Rene
0

LVL 11

Author Comment

Just to let you guys know I've looked at both dragon-it's and billprew's code so far.

I'm hoping there will be other submissions, including my own (when I can get around to focus on this). This is why I allowed a month to tackle this question.

Some of the areas I will be paying close attention to when judging submissions are:

Presentation of code

Style of code

Modularity

Use of variables

Use of DOS

Clarity (easy to follow through code and understand what's going on)

Program logic / program flow

How each step of the program is approached and solved

Data flow

Validation

How closely it meets the criteria set out in the question

Functionality

Optimisation (code and execution)

User-friendliness

As this is a DOS text-based program I am not expecting any fancy graphics as this might impede the clarity of your code however, you should aim for 'neatness' and 'consistency'.

The aim of this task is to demonstrate your EXPERTISE as an all-round developer (analysis, design and implementation and skills in coding).

This task provides us the opportunity to be 'creative' and 'technically expressive'. It also provides us with an opportunity to show off our best efforts as craftspeople.

The question I will be asking myself throughout is, "[i]Am I satisfied this is the best[/i] I can do?"

Time remaining: 14 days.

Happy coding, Experts !!
0

LVL 43

Expert Comment

So where is yours Paul :-)
0

LVL 11

Author Comment

Good question....

I started putting some ideas together ie, decided to make it file-based and how I'd implement generating a random word.

I'm aware in the back of my mind there's still over a week to go...

Will look at it after gym (tis my first session today)...
0

LVL 43

Expert Comment

2 days Paul :-)
0

LVL 11

Author Comment

I know... and I've got NOTHING to offer.

The kids are off school and I'm struggling to snatch a momemt or two on the PC.

Will try to post a few ideas tomorrow when my kid's in bed.

:)
0

LVL 13

Expert Comment

BTW dragon just looking at your script has taught me much.......very nice work. I will not be submitting anything due to time constraints and the fact that Dragon has already won the points....IMHO.
Unless Paul can pull the rabbit out of the hat.....:-)
0

LVL 43

Expert Comment

I know the feeling.... snatched two days working this week, son's 2nd birthday too....  what you need is a rubbish night being stuck up all night and bored for something to do like I was!
0

LVL 11

Author Comment

I'm not after the points... I'm giving them!

What I'm after is an opportunity for us experts to show off our skills...

Give me a moment and I'll provide you with a relevent example... but I don't think there'll be any rabbits on this occasion though!

0

LVL 10

Expert Comment

Very nice work Steve !!
Currently working on an other approch. I dont expect it to be as complete as Steve, but will do my current best.
0

LVL 10

Expert Comment

Here is my displaying strategy.

Will continue another time.

Cheers,
Rene
@ECHO OFF

SETLOCAL EnableDelayedExpansion

CALL :Footer
SET Body.1=Here is where the game logic will be displayed
CALL :Man0
CALL :Display
PAUSE
EXIT

:Display
FOR /F "tokens=2 delims==" %%A IN ('SET Header.') DO IF %%A EQU crlf (ECHO.) ELSE (ECHO %%A)
FOR /F "tokens=1,2 delims==" %%A IN ('SET Body.') DO (
IF %%B EQU crlf (ECHO.) ELSE (ECHO %%B)
SET %%A=
)
FOR /F "tokens=2 delims==" %%A IN ('SET Hangman.') DO IF %%A EQU crlf (ECHO.) ELSE (ECHO %%A)
FOR /F "tokens=2 delims==" %%A IN ('SET Footer.') DO IF %%A EQU crlf (ECHO.) ELSE (ECHO %%A)

EXIT /b

EXIT /b

:Footer
SET Footer.01=crlf
EXIT /b

:Man0
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|   \^|/
SET HangMan.5=^|    ^|
SET HangMan.6=^|   / \
SET HangMan.7=^|_______
EXIT /b

:Man1
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|   \^|/
SET HangMan.5=^|    ^|
SET HangMan.6=^|   /
SET HangMan.7=^|_______
exit /b

:Man2
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|   \^|/
SET HangMan.5=^|    ^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man3
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|   \^|
SET HangMan.5=^|    ^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man4
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|    ^|
SET HangMan.5=^|    ^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man5
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|    O
SET HangMan.4=^|
SET HangMan.5=^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man6
SET HangMan.1=______
SET HangMan.2=^|    ^|
SET HangMan.3=^|
SET HangMan.4=^|
SET HangMan.5=^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man7
SET HangMan.1=______
SET HangMan.2=^|
SET HangMan.3=^|
SET HangMan.4=^|
SET HangMan.5=^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man8
SET HangMan.1=crlf
SET HangMan.2=^|
SET HangMan.3=^|
SET HangMan.4=^|
SET HangMan.5=^|
SET HangMan.6=^|
SET HangMan.7=^|_______
exit /b

:Man9
SET HangMan.1=crlf
SET HangMan.2=crlf
SET HangMan.3=crlf
SET HangMan.4=crlf
SET HangMan.5=crlf
SET HangMan.6=crlf
SET HangMan.7=_______
exit /b

:Man10
SET HangMan.1=crlf
SET HangMan.2=crlf
SET HangMan.3=crlf
SET HangMan.4=crlf
SET HangMan.5=crlf
SET HangMan.6=crlf
SET HangMan.7=crlf
exit /b

0

LVL 51

Expert Comment

@paul

In the header for this question it says:

Socre for each round:
correctly guessed word:
lives remaining:
0: 1pt
1: 2pts
2: 3pts
3: 5pts
4: 8pts
5: 13pts
::
10: 89pts (unlikely unless you're psychic or VERY lucky!!)

but shouldn't that actually be:

0: 1pt
1: 2pts
2: 3pts
3: 5pts
4: 8pts
5: 13pts
6: 21
7: 34
8: 55
9: 89
10: 144

~bp
0

LVL 51

Expert Comment

Actually I guess it's maybe more accurately represented as this:

1: 1pt
2: 2pts
3: 3pts
4: 5pts
5: 8pts
6: 13pts
7: 21
8: 34
9: 55
10: 89

~bp
0

LVL 51

Accepted Solution

Okay, I think this may be where I end work on this question.  I have something that seems to work pretty well, at least from my perspective.  I did take a little judgement on some of the "specs", but in general I think it complies to most of the requirements.  One of the things I did take a different approach to was the history file. I decided not to keep track of games played in a log file, but just have a user file of stats saved for a particular user from prior sessions.  For me this felt a bit more useful, but I know that's just my opinion.  The basic idea is you can specify a single work username when you start play if you want, and then then if you return to the game and specify that username again it will add to the prior games played and points scored.

I also added a "hidden" capability where when you are guessing letters you can type a question mark and it displays the current word.  Made it a lot easier to debug.

Here's some sample output from this version:

[Thu 10/27/2011 14:31:22.93 c:\ee]hangman
Enter R for returning player, N for new player, or G for guest (no stats saved). [R,N,G]?R
*** Welcome back Snoopy

Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):a
Known:[----------], Remain:[9], Guessed:[A], Enter guess (letter or word):e
Known:[----E-----], Remain:[9], Guessed:[AE], Enter guess (letter or word):i
Known:[I---E--I--], Remain:[9], Guessed:[AEI], Enter guess (letter or word):?
*** Word is: INSPECTION
Known:[I---E--I--], Remain:[9], Guessed:[AEI], Enter guess (letter or word):n
Known:[IN--E--I-N], Remain:[9], Guessed:[AEIN], Enter guess (letter or word):s
Known:[INS-E--I-N], Remain:[9], Guessed:[AEINS], Enter guess (letter or word):o
Known:[INS-E--ION], Remain:[9], Guessed:[AEINSO], Enter guess (letter or word):p
Known:[INSPE--ION], Remain:[9], Guessed:[AEINSOP], Enter guess (letter or word):c
Known:[INSPEC-ION], Remain:[9], Guessed:[AEINSOPC], Enter guess (letter or word):x
Known:[INSPEC-ION], Remain:[8], Guessed:[AEINSOPCX], Enter guess (letter or word):t
*** Congratulations, word guessed, points scored=34

Play again (Y/N)? [Y,N]?Y

Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):?
*** Word is: HITHERWARD
Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):hitherward
*** Congratulations, word guessed, points scored=89

Play again (Y/N)? [Y,N]?Y

Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):a
Known:[A----A----], Remain:[10], Guessed:[A], Enter guess (letter or word):e
Known:[A----A----], Remain:[9], Guessed:[AE], Enter guess (letter or word):i
Known:[A--I-A----], Remain:[9], Guessed:[AEI], Enter guess (letter or word):o
Known:[A--I-A----], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):?
*** Word is: ACRITARCHS
Known:[A--I-A----], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):x
Known:[A--I-A----], Remain:[7], Guessed:[AEIOX], Enter guess (letter or word):x
Known:[A--I-A----], Remain:[7], Guessed:[AEIOX], Enter guess (letter or word):x
Known:[A--I-A----], Remain:[7], Guessed:[AEIOX], Enter guess (letter or word):q
Known:[A--I-A----], Remain:[6], Guessed:[AEIOXQ], Enter guess (letter or word):w
Known:[A--I-A----], Remain:[5], Guessed:[AEIOXQW], Enter guess (letter or word):e
Known:[A--I-A----], Remain:[5], Guessed:[AEIOXQW], Enter guess (letter or word):r
Known:[A-RI-AR---], Remain:[5], Guessed:[AEIOXQWR], Enter guess (letter or word):t
Known:[A-RITAR---], Remain:[5], Guessed:[AEIOXQWRT], Enter guess (letter or word):y
Known:[A-RITAR---], Remain:[4], Guessed:[AEIOXQWRTY], Enter guess (letter or word):u
Known:[A-RITAR---], Remain:[3], Guessed:[AEIOXQWRTYU], Enter guess (letter or word):i
Known:[A-RITAR---], Remain:[3], Guessed:[AEIOXQWRTYU], Enter guess (letter or word):o
Known:[A-RITAR---], Remain:[3], Guessed:[AEIOXQWRTYU], Enter guess (letter or word):p
Known:[A-RITAR---], Remain:[2], Guessed:[AEIOXQWRTYUP], Enter guess (letter or word):s
Known:[A-RITAR--S], Remain:[2], Guessed:[AEIOXQWRTYUPS], Enter guess (letter or word):d
Known:[A-RITAR--S], Remain:[1], Guessed:[AEIOXQWRTYUPSD], Enter guess (letter or word):f
Known:[A-RITAR--S], Remain:[0], Guessed:[AEIOXQWRTYUPSDF], Enter guess (letter or word):g
Sorry, no more tries, word was "ACRITARCHS"

Play again (Y/N)? [Y,N]?Y

Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):a
Known:[----------], Remain:[9], Guessed:[A], Enter guess (letter or word):e
Known:[----------], Remain:[8], Guessed:[AE], Enter guess (letter or word):i
Known:[-----I-I--], Remain:[8], Guessed:[AEI], Enter guess (letter or word):o
Known:[-O---I-I--], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):
Quit game (Y/N)? [Y,N]?N
Known:[-O---I-I--], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):?
*** Word is: NONUTILITY
Known:[-O---I-I--], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):nonutility
*** Congratulations, word guessed, points scored=34

Play again (Y/N)? [Y,N]?Y

Known:[----------], Remain:[10], Guessed:[], Enter guess (letter or word):a
Known:[-------A--], Remain:[10], Guessed:[A], Enter guess (letter or word):e
Known:[-E----EA--], Remain:[10], Guessed:[AE], Enter guess (letter or word):i
Known:[-E----EA--], Remain:[9], Guessed:[AEI], Enter guess (letter or word):o
Known:[-E----EA--], Remain:[8], Guessed:[AEIO], Enter guess (letter or word):u
Known:[-E----EA--], Remain:[7], Guessed:[AEIOU], Enter guess (letter or word):
Quit game (Y/N)? [Y,N]?Y

Play again (Y/N)? [Y,N]?N

*** Thanks for playing Snoopy
Total games played: 8
Total points scored: 513

~bp
hangman.bat.txt
0

LVL 11

Author Comment

billprew, and all...

You're absolutely right. It is meant to be:

1: 1pt
2: 2pts
3: 3pts
4: 5pts
5: 8pts
6: 13pts
7: 21
8: 34
9: 55
10: 89

(Obviously, if there are no lives left ie, lives=0, then the game is clearly over).

0

LVL 43

Expert Comment

Has anyone actually found a word come up in that list that you can guess before about 7 letters have come up.... some are so obscure I've had 9 letters and still not known what it was!

Steve
0

LVL 10

Expert Comment

Me, but I was purely lucky!! On all the letters, I failed only 3 and guess what, I had no clue what that word ment!!
0

LVL 51

Expert Comment

So, when does this question "close", wondering if I have time for another enhancement...

~bp
0

LVL 11

Author Comment

bp

Go for it...
0

LVL 11

Assisted Solution

Okay, I just saw this tonight, and COULD NOT RESIST!!!  So much so I spent the last four hours writing this batch file.

Only to realize I'm not going to get to my destination till 4 AM, and I am not going to win either because I did not read the instructions fully.

Still with a slight tweaking my code would meet the few remaining requirements, however I'm going to cut my losses and go see my Girlfriend!

Please see attached Zip File.  I didnl;t have time to more than scan the list here for the word file, but I have to say that the logic for the guessing to note whether a letter was a re-guess and display things nicely was the only "Hard" part.

I think the easiest thing was picking a random line.

OH!  Please NOTE:  My Version of this CAN Be used with Words of ANY Length, if you so choose.  I didn't want it to be hemmed in by having to be 10 letters, because I figured that would lead to some poor coding choices!

If not for the fact I have a 6 hours journey ahead of me, I would have made the minor changes necessary to make the game fully conform to the requirements, I don't think it would be more than another hour or two, but that also brings us near to, or past the "Midnight" requirement, so again, I'll just hang my head and cut my losses.

On a final Note, the Files need to be re-named "HangMan.bat" and "WordFile.dat" As they cannot be uploaded with .bat or .dat extensions to Experts Exchange...

-Q HangMan.zip
0

LVL 51

Expert Comment

Great to see another hat in the ring QCubed, will take a look at that more tomorrow, getting late here.  Travel safe, be happy.

My approach also should handle various length words, I though like you did that was useful.

I was going to try and add a bit more to mine but at this point I think I'll let it stand where it is.

Like a good drive, the joy is in the journey, not the destination.

~bp
0

LVL 11

Expert Comment

Just an FYI:  I was pretty tired when I wrote my batch, and the last thing I did was the part where it stops the used letters from displaying.

I was obviously not thinking strait, and it kept pecking at the back of my brain while I was going over the Tappan See Bridge!

Stupidly I used A FOR Loop to set the list of Available Letters to show Used ones as an underscore!

The Offending code goes something like this:

FOR %%A IN (%LetterList%) DO ECHO %%A|FIND /I "%TGuess:~0,1%"  >NIL && (SET G%%A=_"&GOTO :EOF )

Obviously this can be greatly simplified to this command instead:

SET "G%TGuess:~0,1%=_"

Not only is that code far more simple, it will save the long delay caused by the FOR Loop at that spot.

(My apologies for undoubted errors and omissions in the code of this post, I'm still in the midst of my Trek to Maryland, and it's taken two hours to post this via the phone due to needing to manually rout around traffic snarls on the other phone using google maps traffic view..

-Q
0

LVL 11

Expert Comment

Hey Bill,

Good to hear from you!  Thanks for the kind words, I figure you would also write the more general-use code which would allow for the words of any length as well!

I look forward to reading through your code for this as well when I get the chance, I know from experience you write some pretty elegant stuff!!

However I don't expect I'm in the running considering I wrote the script. In a four (4) hour quick run, after skimming the requirements.

For Example, these are the deficiencies I Already know are present in the code after reskimming before conceding and posting:

A) I do not explicitly list the letters used, I only explicitly list the letters unused and replace the used ones with an underscore.

B) I did not abide by the requirements for different cases for different parts of the output.

C) I did not count guesses against the user.

D) I did count correct letter guesses against the user.

E) I did not notice the requirement to do 10 rounds and give statistics to the user.  (The script let's you play 1 to infinite Games, with stats displaying furring gameplay only.)

F) I did not have time to implement the scoring element, its strictly a pass/fail approach. (I was going to implement scoring and realized that there was at least a couple more hours work left because of the other items, and that It was 10:45 is and was very late to get on the road!"

G?) I'm not sure if this last one was strictly nessessary:  I do all my work without writing any files what so ever..  I'm sure that there was a legitimate reason for requesting the file writes, but, I have a strong habit of avoiding filewrites at all..

Still it does do a fair bit though it most certainly could be tightened up quite a bit  (I've already thought of a few other improvements to my code while writing this response)

What it DOES Do is:

1) Select 1 word at random from the file.

2) Print out a status & guess accepting screen.

3) Tracks and diUsed verses Max guesses of letters

4) Tracks and displays # of guesses

5) Updates the Underscores to reveal the letters of the word as they are guessed

6) Updates the Alphabet list to change unused letters into underscores.

7) Displays status messagesto the user regarding their guesses (Without changing the size of the display area).

8) Ends the game with Win or Lose Dialog which let's the user know what the word actually was

9) Asks the user if they would like to play another round, and resets picking a new word if they do.

10)  Care was given to avoid storing the word or the random number used to find the word, in a system variable longer than nessessary to minimize the chances of cheating.

I do hope that is enough at least to get it looked at.

I should note, per my usual practices, I avoided using delayed expansion; which likely makes some of the code a bit archaic.

-Q

0

LVL 43

Expert Comment

Another late runner then....sounds good and will pick through and nick bits of code for future ;)

Have you got there yet or still on the road, I'm not very good with the geography of the US and distances involved.... i know we (well I with Jo in the car...) drove back from the south of France to the English midlands in one go which was a little tiring shall we say... But then at the moment I can't drive until May after diagnosis of epilepsy so driving to Cornwall (250 miles) with my wife driving and 3 kids in the back took us about 8 hours...

Steve

Steve
0

LVL 11

Expert Comment

Hey Steve,

I'm nearly to Maryland, combing From New York, right now I'm at a rest-stop in Delaware that is about an hour from my destination.  It's about 250 miles from NY to MD.  But only takes about 5 hours give or take an your depending on pit stops and/or traffic.

All this posting on here has really helped the time fly by though!  =)

-Ben
0

LVL 43

Expert Comment

Ben... I get this... like it can't find the words.dat file, but it IS there and renaming it then it complains with your check for the file being there OK.

Haven't checked through the logic yet so might be something silly Win7 related but would give you something to ponder in the final bit of journey!!

Wouldn't advise booting up laptop onto EE as soon as you get see GF though...

Steve

angMan: By QCubed

===============================================================================

ou Have Tried 0 of  Letters.

etters Which Remain:
-------------------------------------------------------------------------------

- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -
-------------------------------------------------------------------------------

he Word you are trying to Match is 1 Long: "_"

===============================================================================

lease Input a Letter or a Guess:

0

LVL 43

Expert Comment

OK, is spaces in path issue.... I always do my EE stuff from a root folder path with spaces in so I don't get caught (when I actually test and not just type in...) by that bit!

FOR /F "Skip=%WordLine% Tokens=*" %%W IN (%~dp0Words.dat) DO Call :Start-Main "%%W"&GOTO :Start-End-Game

FOR /F "usebackq Skip=%WordLine% Tokens=*" %%W IN ("%~dp0Words.dat") DO Call :Start-Main "%%W"&GOTO :Start-End-Game

Has run through OK after that by the looks, was able to guess a word etc. though when I completed all the letters I got this:

Steve
HangMan: By QCubed

================================================================================

You Have Tried 8 of  Letters.

Letters Which Remain:
--------------------------------------------------------------------------------

- _ B C D _ _ G H _ J K L _ _ O P Q _ S _ U V W X Y Z -
--------------------------------------------------------------------------------

The Word you are trying to Match is 11 Long: "freemartin"

================================================================================

Your Guess Was Incorrect! Try again!

Please Input a Letter or a Guess:

0

LVL 11

Author Comment

QCubed

Nice to see a late addition.

You fear you didn't implementing much however, I'm confident there's enough there to be considered for points...

0

LVL 11

Author Comment

billprew

I was hoping to see your 'other enhancement'...
0

LVL 51

Expert Comment

@paultomasi

Ran out of time Paul, been a hectic week in the office.  I had fun working up what I submitted, I think I'll be happy with that for now and let the chips fall where they may.  Still need to make time to go through some of the other submissions more closely, always things to be learned I'm sure.

~bp
0

LVL 11

Author Comment

UPDATE

Just a note to let you all know I'll be looking at your submissions over the next 2 days or so.
0

LVL 11

Author Comment

billprew

I'm having problems with the CHOICE command in your program.

I'm running XP Pro 5.1.2600
0

LVL 51

Expert Comment

@paultomasi

==> I'm having problems with the CHOICE command in your program.

This seems to have been in and out of MS-DOS on and off, starting in DOS 6.22.  Are you having trouble because the command does not exist on your system, in which case you can download a copy from a few places online, for example in prior post 36942035 in this thread, or http://www.dynawell.com/download/reskit/microsoft/win2000/choice.zip). Or do you have the command and some options not working properly?

Since no Windows version was specified I developed and tested on the current version, Windows 7, where Choice is a native command.

~bp
0

LVL 51

Expert Comment

With regard to choice.exe, I am using the newer (current) syntax of the command, so this link is a version that supports that.

www.dragon-it.co.uk/files/2003-choice.exe

~bp
0

LVL 11

Author Comment

Yep, that's the one!
0

LVL 51

Expert Comment

So, what's the verdict here Paul?

~bp
0

LVL 11

Author Comment

billprew & ALL

Please note I am currently looking at your code(s) (bits on a daily basis), analysing each line, each module, each program.

Admittedly, I didn't realise this process would take this long.

And, unfortunately, I'm hampered by personal problems on the home-front which will settle towards the end of the week. I will provide positive feedback soon afterwards.

All I ask is that you all bear with me in the meantime.

Thank you.
0

LVL 51

Expert Comment

No problem Paul, honestly, I too still want to spend more time in some of the contributed code.

~bp
0

LVL 16

Expert Comment

That's not a real chalenge, (less then 5 minutes) you should had limit it to use BAT files only :-)
0

LVL 43

Expert Comment

@murphey2 - It took me much longer than 5 mins just to read and digest Paul's question :-)

Anyway they do, no VBScript, no nothing.  OK mine uses choice.exe (which available on Windows 7 I was using it on and various other windows / resource kits), and find - standard command since early MS-DOS but that's it: http:#36947012  Don't think the other's use anything either.

Steve
0

LVL 11

Author Comment

Murphey2

>> That's not a real chalenge...

What do you mean, not a real challenge? Are you refering to the task?...
0

LVL 43

Expert Comment

Merry Christmas and all that.... maybe some time to close this off over Christmas break (well I am told SOME people get to have a break!)

Steve
0

LVL 11

Author Comment

Just to let you all know, I'm still looking at this question from time-to-time and as time permits...

I have lots of other 'fun' challenges but I'll need to focus more c;osely next time around so that it doesn't get dragged out as long as this one has been.

0

LVL 51

Expert Comment

Paul,

Are you ever going to close this question?  If you don't have time to digest it fully just award some points and lets move on, no point letting it sit out here...

~bp
0

LVL 43

Expert Comment

yes.... what's that 10 days short of a year?

Steve
0

LVL 11

Expert Comment

agreed, we all get busy, but the question will be catagorized as abandoned and there is some good code here.
0

LVL 11

Author Comment

Gonna be closing this real soon now.

2 seperate hard drive failures and one total system failure (taking 3 months to recover from) has put me behind on everything...

I'm gradually inching my way to bringing this to a conclusion.
0

LVL 43

Expert Comment

Just seen the hangman shortcut in my EE directory.... Had any time to look back at this recently Paul?
0

LVL 15

Expert Comment

I comment, can i get points?
0

LVL 38

Expert Comment

I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0

LVL 43

Expert Comment

Personally I'd stay to split them..... obviously I like my solution but the only other two I think were.... Paul has been away from EE for a while I think but maybe can come back and comment now!

Billprew - http:#aa37040222
QCubed - http:#a37048575
dragon-it - http:#a36947012

Steve

: It said in my comment question was to be deleted but now it like might have just been closed with 0 points, don't mind about the points just don't delete it!
0

LVL 10

Expert Comment

I agree with Steve.
0

LVL 11

Author Comment

I will review this question during the next 36 hours....
0

## Featured Post

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For someâ€¦
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered wâ€¦
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custoâ€¦
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidtâ€¦