Hangman is a project mainly written in Ruby, it's free.
Surrey Rubyists Code Competition: Hangman (The game code and all players)
= Surrey Rubyists Coding Competition: Hangman
== Results
The games were played on 28th June 2011. The winner was:
threedaymonk (normal)
You can see the full results in knockout.xls. The teams had 2 hours to create their player, why not create your own player and see how you stack up!s
== Player Class
All you need to do is create a single file and implement a new hangman player class with the below methods.
You should place your player file inside the "players" folder within the hangman game folder.
Your class name must end with "Player" for it to be loaded by the game framework! Please try to make your class and file name unique in some way (with your team name for example) to avoid clashes with other players.
class MyAwesomeSuperDuperHangmanPlayer def name
end
def new_game(dictionary)
# A new game has started, do any clean up from a previous game and initialise for this one.
# The dictionary passed is the full set of words that the phrase is selected from and is passed in as a string array: ["apple", "bear", "cat"]
end
def take_turn(pattern)
# It's your turn. Return a guess (string) which can either be a letter, word or whole phrase.
# The current state of your pattern is passed in the format "s_rr__/r____s_s"
# The pattern is made up from: underscore = missing letter, forward slash = space, letter = correctly placed
end
# If your player needs supporting classes, you can nest them inside your player class.
# This is to keep things simple for the player loader and also to avoid clashes between players.
class MySupportingClass
# ...
end
end
== Running the game
To run the game, open a terminal/command prompt and cd to the hangman folder. Then type the following:
ruby app.rb
This will start up the game and load the valid players from the players folder. You can then select two players and start a new game. You can test your player as you develop it with the game runner. There are two sample players already in the players folder for you to play against while developing your player.
== Guessing
When you return your guess from the +take_turn+ method, you can return a single character, a single word (not multiple words) or the whole phrase. If your guess is incorrect then you are one step closer to death! If however, your guess is correct then it is inserted into your current pattern (replacing the underscores) which is passed into your +take_turn+ method next time round. Your guesses are isolated from your opponent. Here are some examples:
=== Single character guesses
=== Word guesses
=== Whole phrase guesses
=== Invalid guesses
All invalid guesses will count as an incorrect guess and will add a section to your gallows.
== Sample Players
There are two sample players for you to play against and see how a very basic player works:
=== StupidDemoPlayer
This player will randomly select a letter from the alphabet and return it as it's guess. It will track it's guesses and will not guess the same letter twice in a game.
=== HumanDemoPlayer
This player has no AI, it just allows a human player to enter each guess for it.
== Rules
== Good Luck!
You will have about 2 hours to complete your player before the games start. If you have any questions just shout!
== Feedback
I'd love to hear your feedback on the event itself, and also the game code. I'm always looking to improve (even minor things) so feel free to let me know. You can get me on twitter @andypike, or post on Surrey Rubyists Group: http://groups.google.com/group/surrey-rubyists.
Further details of Surrey Rubyists can be found on the website: http://surreyrubyists.tumblr.com/