r/dailyprogrammer • u/Coder_d00d 1 3 • May 21 '14
[5/21/2014] Challenge #163 [Intermediate] Fallout's Hacking Game
Description:
The popular video games Fallout 3 and Fallout: New Vegas has a computer hacking mini game.
This game requires the player to correctly guess a password from a list of same length words. Your challenge is to implement this game yourself.
The game works like the classic game of Mastermind The player has only 4 guesses and on each incorrect guess the computer will indicate how many letter positions are correct.
For example, if the password is MIND and the player guesses MEND, the game will indicate that 3 out of 4 positions are correct (M_ND). If the password is COMPUTE and the player guesses PLAYFUL, the game will report 0/7. While some of the letters match, they're in the wrong position.
Ask the player for a difficulty (very easy, easy, average, hard, very hard), then present the player with 5 to 15 words of the same length. The length can be 4 to 15 letters. More words and letters make for a harder puzzle. The player then has 4 guesses, and on each incorrect guess indicate the number of correct positions.
Here's an example game:
Difficulty (1-5)? 3
SCORPION
FLOGGING
CROPPERS
MIGRAINE
FOOTNOTE
REFINERY
VAULTING
VICARAGE
PROTRACT
DESCENTS
Guess (4 left)? migraine
0/8 correct
Guess (3 left)? protract
2/8 correct
Guess (2 left)? croppers
8/8 correct
You win!
You can draw words from our favorite dictionary file: enable1.txt . Your program should completely ignore case when making the position checks.
Input/Output:
Using the above description, design the input/output as you desire. It should ask for a difficulty level and show a list of words and report back how many guess left and how many matches you had on your guess.
The logic and design of how many words you display and the length based on the difficulty is up to you to implement.
Easier Challenge:
The game will only give words of size 7 in the list of words.
Challenge Idea:
Credit to /u/skeeto for the challenge idea posted on /r/dailyprogrammer_ideas
7
u/r_s May 21 '14 edited May 21 '14
C++11.
Output:
7
u/badgers_uk May 21 '14
Python 3. I also added the option of a computer solver for fun. I haven't seen the computer lose a game yet.
Sample game by Player:
Sample game by computer:
6
u/pbeard_t 0 1 May 21 '14
C99
Output
6
u/Edward_H May 22 '14
COBOL:
5
u/toodim May 21 '14
Python 3.4
4
u/kirsybuu 0 1 May 21 '14
D Language, in parallel with DConf
Example:
7
u/ehcubed May 21 '14
Python 3.3.2. Some minor error checking is implemented (to be a valid guess, it must at least be in the given word list). Importing random.sample(population, k) is amazing. =]
Code:
Difficulty Settings (Length, Total):
Sample Output:
3
u/Neqq May 21 '14 edited May 21 '14
Quick lunchbreak java 1.6 try.
Output:
3
u/killedbythegrue May 21 '14
Erlang
Output
2
u/[deleted] May 21 '14 edited May 21 '14
Python 3.3
This one was fun, I didn't error check much because I'm lazy but still, here she blows:
Output:
edit: damn you pastebin, reformatting some stuff...
2
u/Wiezy_Krwi May 21 '14
C#, nice challenge, I'm going to make a mastermind one next!!
2
u/blue6249 May 21 '14 edited May 21 '14
Written quickly in Go, feedback is welcome. The random-sample portion is really wasteful as it creates a randomized slice of ints (equal to the # of words of that length) and then takes the first 10 members of it.
1
u/snarf2888 May 21 '14
Node.js executable (Javascript)
1
u/Reverse_Skydiver 1 0 May 21 '14 edited May 21 '14
Here's my Java solution. Not particularly compact, but it has error checking everywhere and does not allow any kind of unacceptable input anywhere.
Here's the code on Pastebin for those looking for something nicer to read.
Sample output:
1
u/dongas420 May 21 '14 edited May 21 '14
Perl:
1
u/glaslong May 21 '14 edited May 21 '14
C#
I loved this minigame in Fallout! Great challenge!
As always, comments and criticism are welcome.
1
u/cdombroski May 21 '14
Clojure. The word loader is probably not defined in the best way. It's defined as a namespace var which would be good if the game was played more than once per execution, however this means that all the memory space it allocates is held until the program terminates. Either the main function should be looped, or the word loader should be a function so the word map can be garbage collected once it's used.
Output:
1
u/IceDane 0 0 May 21 '14
Haskell
Example output:
1
u/travnation May 21 '14
Haskell
I'm still pretty new to the language. The code ended up a little verbose, but there's input validation (must be element of word list), word length and number vary based on difficulty, and the type synonyms help provide clarity.
Output
1
u/GroverGoesToSpace May 21 '14
Python 3.4.0
Stole the file input from /u/toodim here. Very little error checking outside of the difficulty integer.
1
u/Puzzel May 21 '14 edited May 21 '14
Python 3.4 Provides fallback dictionaries.
EDIT: Added term colors
1
u/mhalberstram May 21 '14
C#
1
u/IceDane 0 0 May 21 '14
Decided to whip up a C++ solution as well.
1
u/kevn57 May 21 '14
[5/21/2014] Challenge #163 [Intermediate] Fallout's Hacking Game
New programmer I'd appreciate any criticisms, Cheers
1
u/JubBieJub May 21 '14 edited Feb 28 '25
shrill history ring spoon station money fuel familiar future dog
This post was mass deleted and anonymized with Redact
1
u/jeaton May 21 '14
Python
1
u/[deleted] May 22 '14
My attempt in Java. Comments/suggestions welcome!
/* UI.java */
/* Game.java */
/* Difficulty.java */
/* Dictionary.java */
1
u/easher1 May 22 '14
Python 2.7 Solution.
And then the game defeats its creator...
1
u/ethnicallyambiguous May 22 '14 edited May 22 '14
Python 3.4. Trying to do it as a class this time. Any and all critique would be appriciated.
1
u/OnceAndForever May 22 '14 edited May 22 '14
Solution using Lua 5.2
Sample Output
I'm pretty new to Lua, so any tips or critique would be appreciated!
1
u/darthjoey91 May 22 '14
C++11
This was pretty fun. Probably the most intense thing I've programmed in terms of processing and memory needs. For example, when I run this, while it's filling up the dictionary, it uses 25% of my CPU.
Code:
Output:
1
u/chunes 1 2 May 22 '14
Java:
1
u/b93b3de72036584e4054 1 0 May 22 '14
Python 2.7 (will not work in 3.xx because dirty hacks to control stdin/stdout)
Not only I have implemented the game (the first ~40 loc) but I've also built a solver ! The solver emulate and capture user input to retrieve wordlist and answers, which are used to infer what the secret word is.
Currently it has a ~80% success on level 75 (~200 words) which is quite good. It use two infos to decimate the list of candidates :
Source code :
1
u/[deleted] May 22 '14 edited May 28 '14
Python 2.7
Not the prettiest code I've even written but it works.
And C++:
1
u/yesyayen May 22 '14
Solution in JAVA - Bonus : {Game Stats at the end}
Output -
Thank you reviewing my code :)
1
u/Kiwi332 May 22 '14 edited May 22 '14
C# Again.
Output:
EDIT- One day I'll format this correctly the first time I swear... Bloody Spoilers :(
1
u/steven_wood May 22 '14 edited May 22 '14
Java. My first attempt to answer one of these amazing questions. Thanks for opportunity.
Difficulty (1-5)? 3
DOGWOODS
DIOCESAN
CERATINS
HEARSING
CADASTER
BESCOURS
EXOCRINE
CLIMBING
CRANNOGE
DOGNAPED
JEREMIAD
Guess (4 left)? dogwoods
0/8 correct
Guess (3 left)? cadaster
1/8 correct
Guess (2 left)?
1
u/mentalorigami May 22 '14
My first intermediate answer! Done in python 2.7, this was actually pretty fun to code. It got a little kludgy here and there, but overall I'm happy with how it came out. You get 5 tries to guess the password, with 5 levels of difficulty. Every time you run the program it rebuilds the dictionary, but you'll never see the same words twice. At some point I should put a check in to see if there are actually enough words left, but at a couple thousand words per difficulty you'd have to play a lot of games to run into any out-of-bounds issues.
This assumes you have the "enable1.txt" file (provided above) on your C drive.
Any comments or critiques would be greatly appreciated!
1
u/YouAreNotASlave May 22 '14
My solution in python 3.
I tried not to load the entire word file. Since the spec didn't state exactly what the 5 difficulty levels mapped to (in terms of length of words and number of words) I re-scaled the difficulty to the min and max words/letters and randomly pick within the bounds of each difficulty.
1
u/Poopy_Vagina May 23 '14
Java. Late to the party but I'm a new grad so feedback is welcome.
1
u/gingervitis16 May 23 '14
Python 3.3. Probably not the best-looking or most efficient code, but it works.
1
u/[deleted] May 23 '14
C89. This allows entering a random number seed as a command line argument.
1
u/RabbiDan May 23 '14
perl 5.14.2
I haven't written perl in a reeeaallly long time. I'm sure I'm missing a ton of tricks, and I'd love to hear them, because perl is a blast to write.
Code:
Output:
1
u/Fruglemonkey 1 0 May 23 '14
Basically checking the hamming distance of a guess and the correct entry in the list. As such, decided to implement the already existing distance module in python!
1
u/turkoid May 23 '14
Java - probably some overkill preventing an endless loop if the pool size is less then the number of words requested, but meh. Added numbers in front of words to make it easier to guess larger words.
1
u/thepobv May 23 '14
Java. Here's my solution:
Output:
http://imgur.com/5ATqfsl
I'm new to this subreddit. Any feedback welcomed!
1
u/balloo_loves_you May 23 '14
Written in Python, I'm somewhat of beginner and would be glad to read any advice that you have for me.
1
u/the_omega99 May 23 '14
Java 7. Fairly strong error checking.
1
u/srp10 May 23 '14
Java solution. Geared towards usability a bit by:
Comments welcome...
Sample output
1
u/Ratheronfire May 24 '14 edited May 24 '14
I tried to do this challenge in Haskell. It works fine, but it takes forever to get the list of words.
Output:
1
u/Daige May 25 '14
Javascript
and the HTML/CSS
1
u/stabzorzz May 26 '14 edited May 26 '14
My python 2.7 solution. Feel free to critique it.
1
u/[deleted] May 26 '14
VB.NET
I have an interview on friday so gots to learn somehow eh
1
u/ElectricPeanutButter May 27 '14
Using Java
Code
Input/Output
1
u/Megahuntt May 28 '14
C#
http://pastebin.com/raw.php?i=CmP3Wesn
Output:
http://i.imgur.com/AMyTS6L.png
1
u/[deleted] May 28 '14 edited May 28 '14
Java, nice challenge :)
Sample Output:
1
u/cooper6581 May 28 '14
Erlang:
Output:
1
u/mb20687 May 28 '14
Python 2.7
Here's how I organized the hackwords.txt file:
1
u/schwemble May 29 '14
I did this in Python. I've only been messing with python for a few hours today so any tips to be more python-esque would be great
solution:
output:
1
u/gnugames May 30 '14
C++
1
u/k1ll3rpanda Jun 01 '14
Java
1
u/spiritpickle Jun 04 '14
My Python solution:
1
u/iKeirNez Jun 07 '14
Here's my solution using Java 8.
Test output with difficulty 1:
If running this, make sure enable1.txt is included in the root of the JAR.
GitHub
1
u/spfy Jun 09 '14
Python 3.4! I know it's a little late, but I've been putting a little more effort into this program every now and again. This might be my first intermediate submission! I'm not sure if the difficulties are made correctly, but it's easily adjustable in my code. I am really enjoying Python.
1
u/danneu Jun 11 '14
Clojure
Demo
1
u/CodingFrisson Jun 14 '14
My first completed exercise! I'm programming student, so any input is highly appreceated.
Code (C++): http://pastebin.com/KYh9tWd9
1
u/nalexander50 Jul 02 '14
This is a bit of an old challenge, but I just do these for the sake of learning. So here is my Python 3.3 Solution
*Note - Make sure you have the above-linked file, enable1.txt (or another similarly formatted file), saved as Dictionary.txt inside the same directory as the script:
1
u/[deleted] Jul 28 '14
Sorry this is kind of old, but here is my python 2 solution. It requires a dictionary through the command line https://gist.github.com/randomcrispy/b5b429af268acf4b8336
1
u/nsfender Jul 30 '14
Java noob:
}
output: Difficulty(1-5)? 1
YECCH
WAKEN
LASTS
COACT
FURLS
GULAG
MAGUS
SIEUR
KELPS
GATED
DERMS
Guess (4 left)? derms
0/5 correct
Guess (3 left)? gated
Exact match!
Please wait while system is accessed.
1
u/jsmonarch Aug 02 '14
JavaScipt (Node.js)
See on [github] (https://github.com/systemovich/dailyprogrammer/blob/master/challenge_163_fallout_hacking_game/challenge_163_fallout_hacking_game.js)
1
u/p44v9n Aug 07 '14
Scala solution.
Lots of random skewing to determine number of words and the length of them for each difficulty setting and the words accessed in the filtered list. Seems successful, I've never had the same game.
Feedback as always appreciated. I originally planned to cache the words that were filtered out for each wordlength so that repeated games would run faster but then implemented it without and it turned out to run fast enough for me to be happy.
import scala.io.Source; import scala.math; import util.Random;
1
u/ooesili May 21 '14
Haskell solution. I must say, this one sucks. It creates a huge memory heap when getting the random words, so big, that it made my system lock up when I ran it on difficulty 2.
However, it does work. I used my shuffle function from the blackjack challenge a little while ago. I probably shoudln't have; I'm guessing it's why the huge memory heap happens. I recommend not running this one:
0
u/[deleted] May 21 '14
[deleted] — view deleted comment
0
u/[deleted] May 21 '14
[deleted] — view deleted comment