Giter Site home page Giter Site logo

wordgame's Introduction

Wordgame

Primitive realisation of well-known game Scrabble as a problem set of the course "MITx: 6.00.1x Introduction to Computer Science and Programming Using Python" at edx.org.

Compatibility: Python 3.4+.

The game is interactive and intended to be lauched in a console. It reads a set of words from the included words.txt file.

A user has to compose words with letters in current hand (set of letters) to move forward.

The final function playGame() has been implemented via helper functions:

— def updateHand(hand, word): """ Assumes that 'hand' has all the letters in word. In other words, this assumes that however many times a letter appears in 'word', 'hand' has at least as many of that letter in it.

Updates the hand: uses up the letters in the given word
and returns the new hand, without those letters in it.

Has no side effects: does not modify hand.

word: string
hand: dictionary (string -> int)    
returns: dictionary (string -> int)
"""

— def isValidWord(word, hand, wordList): """ Returns True if word is in the wordList and is entirely composed of letters in the hand. Otherwise, returns False.

Does not mutate hand or wordList.

word: string
hand: dictionary (string -> int)
wordList: list of lowercase strings
"""

— def calculateHandlen(hand): """ Returns the length (number of letters) in the current hand.

hand: dictionary (string-> int)
returns: integer
"""

— def playHand(hand, wordList, n): """ Allows the user to play the given hand, as follows:

* The hand is displayed.
* The user may input a word or a single period (the string ".") 
  to indicate they're done playing
* Invalid words are rejected, and a message is displayed asking
  the user to choose another word until they enter a valid word or "."
* When a valid word is entered, it uses up letters from the hand.
* After every valid word: the score for that word is displayed,
  the remaining letters in the hand are displayed, and the user
  is asked to input another word.
* The sum of the word scores is displayed when the hand finishes.
* The hand finishes when there are no more unused letters or the user
  inputs a "."

  hand: dictionary (string -> int)
  wordList: list of lowercase strings
  n: integer (HAND_SIZE; i.e., hand size required for additional points)
  
"""

wordgame's People

Watchers

James Cloos avatar Andrii Simakov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.