Scrabble is a word game in which two to four players score points by placing tiles bearing a single letter onto a board divided into a 15×15 grid of squares. The tiles must form words which, in crossword fashion, read left to right in rows or downwards in columns, and be defined in a standard dictionary or lexicon.
The name is a trademark of Hasbro, Inc. in the United States and Canada; outside these two countries it is a trademark of Mattel. The game is sold in 121 countries and is available in 29 languages; approximately 150 million sets have been sold worldwide.
- Define architecture and high-level design to implement the Scrabble board game
- Define components of the game and discuss possible software implementations
- Define modules and/or classes for the components
- Define methods to allow interaction between classes and/or components
- All classes must include unit tests
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify its associated data fields. There is significant diversity of OOP languages, but the most popular ones are class-based, meaning that objects are instances of classes, which typically also determine their type.
Ruby Object-Oriented Programming
tile_place, tile_places matrix
valid_play, calculate_word_score(word)
name, tiles, plays
initialize, add_play(word), word_score(word), total_score
words, players
initialize, play (start_game, setup_players, show_winner)
tiles
initialize, draw_tiles(num_tiles), remaining_tiles
validate_word(word)
word, score, letter_scores
initialize, calculate_word_score
This test-driven pair-programming exercise will focus on the WordScorer class. This class provides the ability to store a word and its score. It uses an internal letter scores look-up table to calculate total word score.
One approach to pair-programming is developers take turns in writing tests/code using the ping-pong method. In general, they try to take careful steps by writing small units of tests/code at a time.
Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
As most programming languages, Ruby leverages a wide set of third-party libraries. Nearly all of these libraries are released in the form of a gem, a packaged library or application that can be installed with a tool called RubyGems.
Version control (aka revision control or source control) is the management of changes to documents, computer programs, large web sites, and other collections of information.
Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.
Create and initialize new project repository. Example: scrabble
- Initialize New Project/Repository
- Create local and remote repository
- Add README markdown file
- Commit changes
- Push to remote repository
- Add Unit Test Framework
- Add Gemfile ('test-unit' gem)
- Bundle install
- Add
TestWordScorer
class - Add test with
assert_equal(true,true)
- Note: 'Write the code you wished you had available'
- WordScorer Initialization
- Add test to verify WordScorer class
- Add
WordScorer
class - Add empty
initialize
method - GitHub: View code commits
- WordScorer Attributes
- Add test to verify WordScorer attributes
- Add attributes to initialize method
- Add methods to get/retrieve word and score
- WordScorer Score Calculation
- Add test to verify word score (RUBY: 9, JAVASCRIPT: 24, PYTHON: 14)
- Add method to calculate word score (hard-coded values)
- IRB: String.split and data structure for dictionary of key/value pairs.
- Update method to calculate word score (increment score using letter scores)
- Refactor
- Add test
setup
method - Add attribute reader for word
- Add attribute accessor for score
- Use
+=
operator to increment score - Add private methods to help calculate word score