r/dailyprogrammer • u/jnazario 2 0 • Oct 28 '15
[2015-10-28] Challenge #238 [Intermediate] Fallout Hacking Game
Description
The popular video games Fallout 3 and Fallout: New Vegas have a computer "hacking" minigame where the player must correctly guess the correct password from a list of same-length words. Your challenge is to implement this game yourself.
The game operates similarly to the classic board game 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.
There may be ways to increase the difficulty of the game, perhaps even making it impossible to guarantee a solution, based on your particular selection of words. For example, your program could supply words that have little letter position overlap so that guesses reveal as little information to the player as possible.
Credit
This challenge was created by user /u/skeeto. If you have any challenge ideas please share them on /r/dailyprogrammer_ideas and there's a good chance we'll use them.
14
u/hyrulia Oct 28 '15 edited Oct 28 '15
Python3.5
10
u/lukz 2 0 Oct 28 '15
Z80 assembly
I created rather minimal variant, has 8 fixed 3-letter words. It chooses one randomly, which you have to guess. It does not count 4 attempts, you can count that yourself ;-). The program ends when you guess the password correctly.
The program is for Sharp MZ-800 and I use several functions from ROM (3 input line, 6 print new line, 0ch print space, 18h print text). You can run the program from monitor using G1200 command.
Program length is 102 bytes (including data).
Screenshot
7
u/smls Oct 28 '15 edited Oct 28 '15
Perl 6 - difficulty levels based on letter overlaps
This is a drop-in replacement for the
get-wordsfunction in my Perl 6 solution.Rather than simply choosing random words of a certain length, it also requires a minimum number of total letter overlaps between them.
I used a naive brute-force implementation - it simply keeps choosing random sets of words of the correct length, until it finds a set that fulfils the overlap condition.
Here's an example of a set with 6 total letter overlaps (indicated by asterisks) which was found for difficulty 2:
Comments welcome! And I'd love to see other people's approaches (in any programming language!) to choosing "easier" sets for lower difficulty levels, than a random choice would provide.
7
u/Epthelyn Oct 28 '15
Java
Got carried away and ended up making the output as close as possible to the actual in-game display, which comes somewhat at the cost of usability since the input values for the scanner at each step for a given word are 3*(3000+n2) in hexidecimal. Still, it looks pretty and you can count to 15 instead.
Long enough to put into pastebin because of the messing around to get the display:
http://pastebin.com/Eq8hssG6
And, of course, and example output for what would be the last two guesses for an "Average" level terminal:
6
u/smls Oct 28 '15
Perl 6
(translation of hyrulia's Python 3.5 solution)
4
u/mellow_gecko Oct 28 '15
Python3
4
u/supercodes Oct 28 '15
Python
Guess by index of word in list instead of typing it out, I'm too lazy for typing the long words.
4
u/jstaffans Oct 28 '15
Clojure, guesses to be put on a core.async channel.
3
u/fvandepitte 0 0 Oct 28 '15
Haskell, quick and lazy (not that much time) I've just done the compare part, feedback is welcome
3
u/Wiggledan Oct 28 '15 edited Oct 28 '15
C89 edit: forgot to free the words and close the enable1.txt filestream
3
u/SatisfiedWithout Oct 28 '15
Python 3.4
3
u/zengargoyle Oct 28 '15
Perl 6
I should steal somebody's difficulty level determinations. Only thing of interest may be picking N random things from a stream in a single pass.
3
u/[deleted] Oct 28 '15
In Python. Guesses the answer automatically. In 100 games, it gets ~93 right in 4 attempts.
Give me your feedback!
2
u/Scroph 0 0 Oct 28 '15
An intermediate challenge I can solve ! At least I think I solved it.
D (dlang) solution :
2
u/mapmaker_y2k Oct 28 '15 edited Oct 28 '15
PHP
2
u/TheOneOnTheLeft Oct 28 '15 edited Oct 28 '15
Python 3.5
All feedback welcome. It's a bit long, I know, but I've tried to make it readable. After looking at /u/hyrulia's solution, list comprehensions are definitely something I should remember to think about using.
2
u/chunes 1 2 Oct 28 '15
I had fun with this. Java
2
u/japangreg Oct 28 '15
My quick solution in Java. Comments welcome.
2
u/SoftDevPadawan Oct 28 '15
My C# solution. Feedback is welcome.
class Program { static int DifficultyPrompt() { Console.WriteLine("Difficulty (1-5)? "); return int.Parse(Console.ReadLine()); }
2
u/enano9314 Oct 28 '15
Just because this one doesn't have a challenge feature, one can try to implement the other aspects of the hacking game present in Fallout.
Namely that choosing certain characters that are present will reset the amount of tries that you have left.
From the wiki
"There are also things you can do with the characters that are not part of words. Clicking on matching brackets (i.e. () [] {} <>, even with other characters between, but not a whole word between) can remove a dud password or reset the number of remaining guesses to four. The brackets must be of the same type and on the same line. Although you cannot match brackets with a whole word between them, you can match brackets separated by the dots that appear when a dud word is removed ( <.......> ). Also, two or more opening brackets can be matched to a single closing bracket ("[ [ ]" on a line gives you two chances), but the opposite is not true ("[ ] ]" only gives you one chance). When you scroll across this type of entry from left-to-right, the entire entry will be highlighted letting you know if you've found one or not. "
2
u/glenbolake 2 0 Oct 28 '15
Python 3. One of the only solutions I've submitted that doesn't use functions or OOP at all. That feels weird.
2
u/cheers- Oct 28 '15 edited Oct 28 '15
Java
I was originally thinking to do a gui and mimic the way fallout minigame works but dont have time now.
If I have time I will add it later.
Uses Scanner & Regex and it is not case sensitive. Allows to play it again without closing and recalling java myclass ect...
Java doesn't have goto so I had to implement play it again with recursion.
If someone has a better solution to handle it please let me know.
It is commented hence it should not be to hard to read. Feedback is welcomed.
2
u/colbrand Oct 28 '15 edited Oct 28 '15
JAVA with full game logic and messages
2
u/SerkZex Oct 28 '15 edited Oct 28 '15
Python 3!
2
u/[deleted] Oct 28 '15 edited Oct 28 '15
Like /u/fvandepitte, I've done a mini solution. This one's in Fortran... it just illustrates how the match-counting could be done.
2
u/errorseven Oct 28 '15 edited Oct 28 '15
AutoHotkey - Not as concise as I could get it if I took more time but it runs fast and works!
Output: http://i.imgur.com/wKYs1h1.png
2
u/Boom_Rang Oct 28 '15
Definitely not the prettiest way to do it, but here's my attempt in Haskell:
2
u/n2468txd Oct 28 '15
IcedCoffeeScript / nodejs first post here <:
2
u/[deleted] Oct 29 '15 edited Oct 31 '15
D:
My first go around at this:
And now its time for bed.
2
u/Gregman Oct 29 '15
GOLANG or Go
Thanks /u/hyrulia for dict. That was smart!
2
u/Fawzors Oct 29 '15
ABAP 7.4 SP 05 (always winning in line count)
2
u/mantisbenji Nov 03 '15 edited Nov 05 '15
Haskell solution. Probably can use some Control.Monad do block functions instead of if-else.
2
u/neptunDK Nov 04 '15
Python 3. My first intermediate challenge that I have completed, so tips/comments are welcome. :)
2
u/rjggmp Nov 07 '15
Ruby
2
u/kad1n Nov 20 '15
Probably a bit late, but better late than never ;) Here is my java attempt (PS, first time i post here in this subreddit!) Feedback is appreciated.
3
u/Godspiral 3 3 Oct 28 '15 edited Oct 28 '15
In J, does something different: takes an initial word of any length, filters the dictionary by that length and words with at least 1 correct letter location, and returns that new dictionary. It takes a parameter for how long of a sublist to return, and returns that number of random words that pass the test.
this generation allows the generator parameter to be a first blind guess, and compiles the guessing verb while displaying the choices after the first guess and "difficulty" param.
bagnio sleave damply bloops bucket maundy afraid talked dances voting throne rinser
1r3 NB. result is fraction = 2 of 6
g 'maundy'
1r3
g 'bagnio'
1
The difficulty tends to be based mostly on how many common letters the chosen word has with generator word. 1 is hardest.
raggle abrade walrus budges clears wauled macons jagers fixate waxers halter ground rachet syrinx vivary torula brewer bongos barded dasher makers venial convey fanion buyout bulges bosque bailee mutase zinged gonion zenana cleats raffle broken lipoma gyving namers ramous caviar
1r6
more challenging game would be to not show the list. 6133 6 letter words with at least 1 correct position match with banana.
1
u/BHuber09 Oct 28 '15
I actually did this in my Data Structures class last year. Except we used a text file that he provided. Regardless, the solution should be the same. Here was my solution in C++.
https://github.com/BHuber55/LAB03
1
u/oprimo 0 1 Oct 28 '15 edited Oct 28 '15
My Javascript solution below.
To speed things up and help the user, the code groups the dictionary words by length and, inside those groups, it creates kind of a 'hash map' using the word letters, in order, as a key. This effectively groups similar words like "ensued", "sudden" and "unused" under the same key ("densu"). Since similar words make the guesswork easier, the code tries to pick groups with 2 or more words and include all of them among the user choices.
You can play the fully-functional solution (with a quick-and-dirty, old-school-like interface) here.
(EDIT: forgot to tell that feedback is welcome!)
1
u/_seemethere Oct 28 '15
A combination of a lot of the solutions here. Short and concise and to the point. Does error trapping for the difficulty check. Uses list comprehension for both the matching and generating functions.
1
u/fullrobot Oct 28 '15
Python 2. Any feedback welcome!
1
u/ReckoningReckoner Oct 28 '15
Ugly Ruby ugh
1
u/[deleted] Oct 29 '15
Ruby
Completely procedural; how can I improve this?
1
u/SirAceBoogie Oct 29 '15
C# This challenge was a lot of fun! Here is my first attempt in C#. Feed back is welcomed! I plan on improving this and making it more like fallout.
Hacking.cs
}
Program.cs
1
u/hellercopter Oct 29 '15 edited Oct 29 '15
Java:
1
u/chunes 1 2 Oct 29 '15
Befunge-93
Example output:
Caveats:
1
u/demeteloaf Oct 29 '15
erlang: I should probably do something more creative to generate the list such that you get better words instead of totally randomly...
output:
1
u/aXIYTIZtUH9Yk0DETdv2 Oct 29 '15
Rust (since no one has done it yet)
1
u/Qvoovle Oct 29 '15
1
u/WoblyInflatableThing Oct 29 '15
C
1
u/chappell28 Oct 29 '15
Golang
Self-taught newbie, so feedback welcome! Off the top of my head, problems include entire wordlist is stored in memory and input isn't confirmed to match one of the possible choices.
Code:
Output:
1
u/taindissa_work Oct 29 '15
40 lines of ruby
1
u/dangkhoasdc Oct 29 '15
Here is my solution using C++.
1
u/curtmack Oct 29 '15 edited Oct 29 '15
Clojure
Don't really have much to say about this. It's pretty straightforward.
Oh oh wait I do have something to say about this! Clojure does not automatically flush output when you call
(read-line)and friends. It is incredibly annoying.Edit: Fixed to validate guess length - it now rejects guesses that don't have the same number of letters as the password. (Intentionally does not validate whether non-letters are in the guess, though.)
1
u/tarunteam Oct 29 '15
C#
Main Program
ListGen
1
u/hbeggs Oct 29 '15 edited Oct 29 '15
Here's my novice attempt at Python 2.7
Let me know where I can improve
1
u/FreeIceCreen Oct 29 '15
Python 3.5
This is the first time I'm submitting a solution, but I was pretty proud of this, and I think I could make it better. Any tips?
My Solution
1
u/MusicPants Oct 30 '15 edited Oct 30 '15
Hi r/dailyprogrammer
Here is my attempt at making this into a game. This is my first 'untutorialed' use of using ajax. I am using it to grab the .txt file. The program is mostly working and plays reasonably well, but sometimes it seems like the JavaScript is getting stuck somewhere and I am getting a runtime error intermittently.
My code is a bit of a mess so I apologize for that but this is my first try at an intermediate DP challenge so that's a plus.
Thanks for any help. Here is the link, http://musicpants.net/webapps/password-game/
1
u/YonkeMuffinMan Oct 30 '15
Python 2.7
1
u/Krirken Oct 30 '15
Node.js, ES5
1
u/TiZ_EX1 Oct 30 '15
Haxe. thx.core.
Feedback, please! Thank you!
1
u/FlammableMarshmallow Oct 30 '15
Python3!
1
u/Flaminx Oct 30 '15
I had a lot of fun with this one making it a bit more fallout themed, I've tested it and believe it to be bug free. Now back to waiting for fallout 4.... [C++]
1
u/juanchi35 Oct 31 '15 edited Oct 31 '15
C++11, I'm open to feedback (:
1
u/leolas95 Oct 31 '15 edited Oct 31 '15
This is my [ugly] answer in C. This is the same that I did for the #163 intermediate challenge, which I think is the same as this. Any suggestion would be appreciated.
1
u/thevjm Oct 31 '15
Here's another Python solution..
1
u/[deleted] Oct 31 '15
Python 3.4
1
u/PharmyOf1 Oct 31 '15
Python Feedback appreciated...
1
u/netbioserror Nov 01 '15
D
1
u/crossroads1112 Nov 01 '15 edited Nov 01 '15
Rust
This program does a few additional things than the spec covers.
EDIT: Made use of
rand::sampleandinclude_str!1
u/TheSlowestCheetah Nov 02 '15
Python 2.7
First time doing an intermediate challenge! And now that I finished and looked at other python submissions, there are definitely better ways to do this than a bunch of if statements to set word length and number of words.
1
u/shadystone Nov 02 '15
A Clojure solution, with an effort to give it the fallout terminal look-and-feel.
Output:
1
u/darklamouette Nov 02 '15
Python 3.4 # -- coding: utf-8 --
1
u/poole141 Nov 03 '15
python, this was a lot of fun! cool prompt.
1
u/spamburghlar Nov 03 '15
Java
1
u/redragon11 Nov 04 '15
Late, but whatever, randomly assigns word length/number of words, also checks for invalid input.
VB.NET (feedback appreciated):
1
u/ntwt Nov 04 '15
Java
}
1
u/[deleted] Nov 06 '15
Java. Quick and dirty
1
u/coolirisme Nov 07 '15 edited Nov 07 '15
C99 solution. Reviews welcome.
Output
1
u/MondayMonkey1 Nov 08 '15
Here's my node implementation. Aside from a few fat arrows, it's all es5. Cheers!
1
u/sort_of_a_username Nov 16 '15
Python 2.7
1
u/nommywommyo Nov 19 '15 edited Nov 20 '15
Haskell. Been on a Fallout 4 binge so I thought this was appropriate
1
u/chemicalphysicist Dec 04 '15 edited Jan 16 '16
C++/C
I'm a newbie programmer and I wanted to make this into more of a project for myself (although, it is probably excessively long).
removed
I hope someone reads this... even if it is a month old post.
1
u/Tarroy Dec 08 '15 edited Dec 08 '15
Bad C++ Solution
I'm a beginner in C++ so if you got improvements please let me know.
1
u/r4n Dec 08 '15
Java approach:
1
u/duckofdoom12 Dec 20 '15
http://ma.cruxpanel.nl/PROJECTS/PROJECTS-fallout-hacking-game/
r8 m80's
done in JS, made as part of a birthday present for a friend
1
u/BBPP20 Jan 01 '16
C++
Code: http://pastebin.com/gdAcu3Z7 Words are from enable1.txt file. Only problem is that searching the file for acceptable words can take up to 5 seconds.
0
u/ganska_bra Oct 30 '15
Rust
and the output:
0
u/[deleted] Oct 28 '15
[deleted] — view deleted comment
0
u/[deleted] Oct 28 '15
[deleted] — view deleted comment
0
u/[deleted] Nov 07 '15
[deleted] — view deleted comment