Hi all. I'm currently programming a game of hangman that is supposed to avoid the user's guesses for as long as possible.
The algorithm should work in this manner:
The player guesses a letter, and the computer goes into the word list and removes all words that contain the guessed letter, and tells the player he/she has guessed incorrectly, thus, deducting a life. This should continue for as long as possible, or until only one vowel remains (considering all words contain vowels). At that point, if the final vowel were "a", and the guess word was currently set at "cat", and then the player then guesses "c", the word should be swapped to another, for example, "bat". However, the "a" must stay, until finally, the computer has no choice but to allow the word to be "bat" or "mat" or any other for that matter.
I already have a working hangman game; I just need to figure out how to incorporate the "cheating algorithm" into the game.
Thanks.
Offline
That sounds complicated. Unfortunately, there's no way to confirm that the new word is an actual word (although I have a a suggestion that would fix this )
Last edited by Greenatic (2012-02-19 19:32:50)
Offline
I already have a list of words. So if my list were to contain 5 words:
apple
ant
bear
cheese
milk
And the first guess was "a", then apple, ant, and bear would be eliminated due to those three containing the letter "a" ... then depending on which letter is chosen first, either milk or cheese will be selected as the finalized secret word.
Does anybody have any idea how to approach this?
Offline
pdubu wrote:
I already have a list of words. So if my list were to contain 5 words:
apple
ant
bear
cheese
milk
And the first guess was "a", then apple, ant, and bear would be eliminated due to those three containing the letter "a" ... then depending on which letter is chosen first, either milk or cheese will be selected as the finalized secret word.
Does anybody have any idea how to approach this?
Give me a sec...
OK, I got it.
I'm assuming the letter is stored in a variable named "letter" and the possible words for use are in a list named "words". Create three additional variables: "c1", "c2", and "bool".
set [c1 v] to (1) repeat (length of [words v]) set [c2 v] to (1) set [bool v] to (0) repeat (length of (item (c1) of [words v])) if < <(bool) = (0)> and <(letter (c2) of (item (c1) of [words v])) = (letter)> delete (c1) of [words v] set [bool v] to (1) end change [c2 v] by (1) end if <(bool) = (0)> change [c1 v] by (1) end endThe new word can then be accessed by:
(item (pick random (1) to (length of [words v])) of [words v])Let me know if you have any problems.
Last edited by Greenatic (2012-02-19 20:15:42)
Offline
Greenatic wrote:
pdubu wrote:
I already have a list of words. So if my list were to contain 5 words:
apple
ant
bear
cheese
milk
And the first guess was "a", then apple, ant, and bear would be eliminated due to those three containing the letter "a" ... then depending on which letter is chosen first, either milk or cheese will be selected as the finalized secret word.
Does anybody have any idea how to approach this?Give me a sec...
Sure thing. Thanks a ton.
Offline
Greenatic wrote:
pdubu wrote:
I already have a list of words. So if my list were to contain 5 words:
apple
ant
bear
cheese
milk
And the first guess was "a", then apple, ant, and bear would be eliminated due to those three containing the letter "a" ... then depending on which letter is chosen first, either milk or cheese will be selected as the finalized secret word.
Does anybody have any idea how to approach this?Give me a sec...
OK, I got it.
I'm assuming the letter is stored in a variable named "letter" and the possible words for use are in a list named "words". Create three additional variables: "c1", "c2", and "bool".set [c1 v] to (1) repeat (length of [words v]) set [c2 v] to (1) set [bool v] to (0) repeat (length of (item (c1) of [words v])) if < <(bool) = (0)> and <(letter (c2) of (item (c1) of [words v])) = (letter)> delete (c1) of [words v] set [bool v] to (1) end change [c2 v] by (1) end if <(bool) = (0)> change [c1 v] by (1) end endThe new word can then be accessed by:(item (pick random (1) to (length of [words v])) of [words v])Let me know if you have any problems.
Could you clarify what your script is supposed to do? And the specifics of c1, c2, and bool would be helpful as well.
Offline
Also, to clarify, I currently have a list of words; not letters.
Once the secret word is chosen (I used the same method you suggested, in terms of matching the length preferred and a random word), the word is inserted into a list of its own, however, broken into separate rows.
If the word were apple, the list would be:
1. a
2. p
3. p
4. l
5. e
So... it makes it sort of difficult to go through the list of words and figure out whether or not each value contains a certain letter.
Offline
"c1" and "c2" are counter variables. They keep track of what list item or letter the program is using.
"bool" is short for "boolean", a true or false statement. 0 = false, and 1 = true. "bool" states whether or not a word was deleted.
Also, it looks like the scratchblocks glitched. Quote the post to see what was supposed to be in that messed up "if" loop.
So do you need a script to turn a list back into a word to process it? Or is the broken-up word in a list with other broken-up words?
Offline
I believe it would take too long to process if I broke up every individual word into a list of letters.
What I'm looking for is a script to check a list of words (of various lengths and letters) for a certain letter.
If the list of words included:
a
cup
white
pitcher
book
capital
bunt
And the player guessed "a", then the list would delete words so that it would look like:
cup
white
pitcher
book
And then if the player guessed "i" next, then it would become:
cup
book
Then if the player guessed "o", the list would be left with:
cup
bunt
And if the player guesses "u" at this point, then the program has no choice but to accept either "cup" or "bunt" as the secret word.
Depending on the next letter, if the player were to guess "c", then cup would be eliminated, or if the player guessed "n", then bunt would be eliminated, and the final word would be selected.
Thank you so much for helping me out.
Offline
pdubu wrote:
I believe it would take too long to process if I broke up every individual word into a list of letters.
What I'm looking for is a script to check a list of words (of various lengths and letters) for a certain letter.
If the list of words included:
a
cup
white
pitcher
book
capital
bunt
And the player guessed "a", then the list would delete words so that it would look like:
cup
white
pitcher
book
And then if the player guessed "i" next, then it would become:
cup
book
Then if the player guessed "o", the list would be left with:
cup
bunt
And if the player guesses "u" at this point, then the program has no choice but to accept either "cup" or "bunt" as the secret word.
Depending on the next letter, if the player were to guess "c", then cup would be eliminated, or if the player guessed "n", then bunt would be eliminated, and the final word would be selected.
Thank you so much for helping me out.
OK, the script I gave you has you covered until you start replacing words--how do you expect "cup, book" to become "cup, bunt"? If you put "bunt" in the list of words, it will already be there, along with "cup" and "book". If you don't, then your project has no way to know that "bunt" exists. Perhaps you made a typo?
Offline
Sorry, I forgot to include bunt in the middle two lists.
Are you saying the script you provided will delete words?
Because I'm not sure how to verify whether or not a particular word includes a letter, and then if it does, delete it, or if it doesn't, move on to the next word.
Offline
pdubu wrote:
Sorry, I forgot to include bunt in the middle two lists.
Are you saying the script you provided will delete words?
Because I'm not sure how to verify whether or not a particular word includes a letter, and then if it does, delete it, or if it doesn't, move on to the next word.
The script I provided does this:
1. Runs through the first item of "words" and sees if it contains "letter".
2. If it does, it deletes it.
3. Repeats this for the whole list.
Offline
pdubu wrote:
How would the computer realize at a certain point when to stop deleting, due to their only existing words such as, in my example, cup and bunt?
My guess is this: Edit my script to copy all the words into another list at the beginning. If, at the end of the script, (length of [words v]) = 0, then copy the values from the other list to "words". Otherwise, delete all of the other list.
If you want, I can script that out for you.
Last edited by Greenatic (2012-02-20 09:16:03)
Offline
Hm.. is it possible to test for length of words to equal 1 at the beginning, and if that is the case, then submit to the player's guess and allow the final word to be the secret word? And if the list is not depleted to 1, then continue deleting words?
Also, there's something odd about the script you gave me--yes, it deletes words, but it doesn't delete all the words on the first click. It often requires me to active the script a second time in order to clear all the words I'm trying to delete.
If the list looks like:
a
able
ant
advil
gatorade
cup
batter
And I guess "a" ...
the list will look something like:
gatorade
cup
batter
Then if I click it again, it'll turn into:
cup
I'm not sure what's causing that either.
Offline
pdubu wrote:
Hm.. is it possible to test for length of words to equal 1 at the beginning, and if that is the case, then submit to the player's guess and allow the final word to be the secret word? And if the list is not depleted to 1, then continue deleting words?
Also, there's something odd about the script you gave me--yes, it deletes words, but it doesn't delete all the words on the first click. It often requires me to active the script a second time in order to clear all the words I'm trying to delete.
If the list looks like:
a
able
ant
advil
gatorade
cup
batter
And I guess "a" ...
the list will look something like:
gatorade
cup
batter
Then if I click it again, it'll turn into:
cup
I'm not sure what's causing that either.
Hm, that list worked for me...could you post a specific list that's giving you problems?
And as for the question of the beginning of your post, put this loop at the beginning of the script:
if <(length of [words v]) = (1)> endPut your code inside that loop. The word can then be referenced by:
(item (1) of [words v])
Last edited by Greenatic (2012-02-20 16:43:57)
Offline
pdubu wrote:
It was the list that you provided--the c1, c2, and bool. It does not guarantee that every item containing letter "?" will be deleted.
Thank you.
No, I mean: Could you give an example of words that you know caused a problem?
Last edited by Greenatic (2012-02-20 17:25:31)
Offline
My list:
shouldntdelete
nyquil
a
a
ant
add
bay
can
that
natural
I run the script once, and I'm left with:
shouldntdelete
nyquil
a
add
can
natural
I run it a second time.. I'm left with:
shouldntdelete
nyquil
add
natural
I run it a third time.. and now I'm left with:
shouldntdelete
nyquil
At this point, the job has been done: it removed any word that contained the letter "a" in it. However, as you can see, it took three separate clicks rather than just one run through.
Offline
pdubu wrote:
My list:
shouldntdelete
nyquil
a
a
ant
add
bay
can
that
natural
I run the script once, and I'm left with:
shouldntdelete
nyquil
a
add
can
natural
I run it a second time.. I'm left with:
shouldntdelete
nyquil
add
natural
I run it a third time.. and now I'm left with:
shouldntdelete
nyquil
At this point, the job has been done: it removed any word that contained the letter "a" in it. However, as you can see, it took three separate clicks rather than just one run through.
My project deleted them all in one go--I think you must have put it together wrong somehow. Could you post your script in Scratchblocks?
EDIT: Nevermind, I figured out where you went wrong--I don't think "bool" is changing. Did you remember to put the "set [bool v] to (1)" block inside the first "if" loop?
Last edited by Greenatic (2012-02-20 17:49:14)
Offline
Wow, [removed] myself. You were exactly right--I had it set to 0 rather than 1. It's working now. Okay, great. That eliminates the first issue.
So I should just allow this script to run until my list dwindles down to 1, is that correct?
Last edited by cheddargirl (2012-02-20 18:52:56)
Offline
Okay, here's another problem.
How would I eliminate words that don't match the preferred length at the very beginning?
And after running the script a few times, I found this issue: if the secret word was set at "bat" and I guessed "e", I want all the words in my list that contain "e" to be deleted. However, when I run the script that you provided, it will not delete the words. It'll only delete the first word with a letter "e" in it. Any ideas?
Offline
pdubu wrote:
Okay, here's another problem.
How would I eliminate words that don't match the preferred length at the very beginning?
And after running the script a few times, I found this issue: if the secret word was set at "bat" and I guessed "e", I want all the words in my list that contain "e" to be deleted. However, when I run the script that you provided, it will not delete the words. It'll only delete the first word with a letter "e" in it. Any ideas?
OK, you messed up the script again somehow. Do you want me to just upload a project with the script?
Last edited by Greenatic (2012-02-20 18:20:42)
Offline
Sorry about the curse. I'm a little stressed out from this program.
And scratch out part of my previous comment: I figured out how to delete words not in the list.
I'm still confused as to how I should approach the second letters and third, and so on. As well as how to rid myself of words that don't match the length criteria.
Offline
As a matter of fact, that'd be great.
Here's another error I just came across...
I'm using a list of 2000 words.
The secret word is "hot"
I type in "a".. it removes all the words with "a" in it.
Then I type in "p", but then it doesn't remove any words.
I try "e", same result--no deleting.
Any ideas as to where I went wrong this time?
Just kidding. I figured that part out. Gosh this is intense..
Offline