hangman

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

README

Hangmanenator 2000

old README, please update!

A simple Python script made for making Hangamanen easier for Roulette hosts.

A Roulette a game in Dream Theater Forums' General Music Discussion section, in which a host gathers several players, and per round, the host receives a song from each player. He gives them several listens, then scores them according to personal preference. The goal of Roulettes is to discover new music, and as scores are accumulative, the player who sends the best songs wins.

Part of the fun in recent years is playing a variant of the classic Hangman, in which the players have to guess what songs were sent to the guest, and by who, before he posts results. Because this was a tedious, error-prone process by hand, this little script was born to help that.

To use it, place a text file in the same folder as script, and put the entries for the round using the following format, one per line:

Player: Artist - Song

First, clone it into a folder you like

git clone https://github.com/Sacules/hangmanen.git

or download it as a ZIP file. Afterwards, open a terminal in the folder that was created and run the script with

python3 hangmanen.py

If you're using Linux, it's likely your distro already comes with Python 3.x and git installed. On Windows and OSX, you can download Python from here (make sure you choose the option "Add to PATH" when installing!) and git from here.

Example

Let's look at one of the rounds I hosted - I made a file called round 4.txt, opened it, and saved the following:

Parama: The Hirsch Effekt - Irrath
Bolsters, the Traitor: Amy Shark - Deleted
Nekov: Angra - Wishing Well
Train of Naught: Trivium - The Sin and the Sentence
Evermind: Seventh Wonder - Alley Cat
Tomislav95: Iced Earth - A Question of Heaven
Luoto: Insomnium - Revelation
ariich: Amorphis - Dark Path
home: Blind Guardian -  The Bard's Song - In the Forest
kingshmegland: Pagan's Mind - Through Osiris' Eyes
Kattoelox: Aquaria - Expedition
Elite: Caligula's Horse - A Gift to Afterthought

Using the script, it generates this:

?: ___ ______ ______ - ______
?: ___ _____ - _______
?: _____ - _______ ____
?: _______ - ___ ___ ___ ___ ________
?: _______ ______ - _____ ___
?: ____ _____ - _ ________ __ ______
?: _________ - __________
?: ________ - ____ ____
?: _____ ________ -  ___ ____'_ ____ - __ ___ ______
?: _____'_ ____ - _______ ______' ____
?: _______ - __________
?: ________'_ _____ - _ ____ __ ____________

After guessing some letters, artists, songs, and players:

Parama: The Hirsch Effekt - Irrath
Bolsters, Traitor: Amy Shark - ____t__
?: Angra - __s__n_ ____
?: Trivium - The Sin and the Sentence
?: S___nt_ __n___ - A____ _at
?: ____ _a_t_ - A ___st__n __ __a__n
?: Insomnium - Revelation
?: Amorphis - Dark Path
?: Blind Guardian -  The Bard's Song - In the Forest
?: Pagan's Mind - Through Osiris' Eyes
?: A__a__a - ______t__n
?: Caligula's Horse - A Gift to Afterthought

Guessed letters: M B A S N T

The script saves the guessed letters and words in a separate file from the guessed players.

Documentation

Index

Constants

View Source
const (
	GameEntry = `entry`
	GameEP    = `ep`
)

Is it an entry round or an EP round?

View Source
const (
	// SpecialChars collects characters that shouldn't be turned into '_'
	SpecialChars = `"[]-(),.:;?!'& /_\`
)

Variables

This section is empty.

Functions

func CreateBlankName

func CreateBlankName(name string) string

CreateBlankName generates a string in which each character is replaced with a '_', except for the SpecialChars.

func ReplaceLetter

func ReplaceLetter(name, blankName, letter string) string

ReplaceLetter inserts each occurence of the given letter in name on blankName.

func ReplaceWord

func ReplaceWord(name, blankName, word string) string

ReplaceWord inserts the first occurence of the given word in name on blankName.

Types

type EP

type EP struct {
	Entry

	Entries []*Entry `json:"entries"`
}

EP holds plenty of entries while also being an entry itself.

func NewEP

func NewEP(name, player string) *EP

NewEP generates an EP object with given parameters.

func (*EP) Add

func (ep *EP) Add(e *Entry)

Add appends an entry to the EP

func (*EP) GuessLetter

func (ep *EP) GuessLetter(l string)

GuessLetter tries to fill all instance of the given letter in all the entries' BlankName.

func (*EP) GuessWord

func (ep *EP) GuessWord(w string)

GuessWord tries to fill the given word in all the entries' BlankName. Only replaces the first instance of the word per entry if it exists.

type Entry

type Entry struct {
	Player

	// Usually the song or album's name
	Title string `json:"title"`

	// This represents the title as a sequence of "_", ready to be filled
	BlankTitle string `json:"blank_title"`
}

Entry represents a song, or album sent by a player.

func NewEntry

func NewEntry(title, player string) *Entry

NewEntry generates an Entry object with given parameters.

func (*Entry) GuessLetter

func (e *Entry) GuessLetter(l string)

GuessLetter tries to fill all instances of the given letter in the entry's BlankTitle. If it's already been guessed, nothing happens.

func (*Entry) GuessWord

func (e *Entry) GuessWord(w string)

GuessWord tries to fill the given word in the entry's BlankTitle. Only replaces the first instance of the word if it exists.

type Game

type Game struct {
	Category string `json:"category"`
}

Game represents the currently running game

type Guesses

type Guesses struct {
	Letters  []string `json:"letters"`
	Words    []string `json:"words"`
	Players  []Player `json:"players_guessing"`
	MaxTurns int      `json:"max_turns"`
}

Guesses keeps track of the many guesses players make during the game.

func NewGuesses

func NewGuesses(maxturns ...uint) *Guesses

NewGuesses returns a pointer to a Guesses type, with the given MaxTurns. If missing or given 0, it defaults to 3.

func (*Guesses) AddLetter

func (g *Guesses) AddLetter(l string)

AddLetter to the list of guesses.

func (*Guesses) AddPlayer

func (g *Guesses) AddPlayer(p Player)

AddPlayer a player to the end of a turn queue, and removes the first one.

func (*Guesses) AddWord

func (g *Guesses) AddWord(w string)

AddWord to the list of guesses.

func (*Guesses) Load

func (g *Guesses) Load(filename string) error

Load all the guesses from a JSON file.

func (*Guesses) RepeatedLetter

func (g *Guesses) RepeatedLetter(l string) bool

RepeatedLetter checks if a given letter exists in the list of guesses.

func (*Guesses) RepeatedWord

func (g *Guesses) RepeatedWord(w string) bool

RepeatedWord checks if a word exists in the list of guesses.

func (*Guesses) Save

func (g *Guesses) Save(filename string) error

Save all the guesses to a JSON file.

type Player

type Player struct {
	Name    string `json:"name"`
	Guessed bool   `json:"guessed"`
}

Player represents a user playing the game

Directories

Path Synopsis
backend
hangman Module
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL