Interaction in a tic-tac-toe game

Assignment Help Database Management System
Reference no: EM131224581

Your assignment should be submitted in a single Word doc (.doc or .docx). It should include your scenario diagram for Problem 1, and your Ruby source code for Problems 2 and 3. Contact me or post to our discussion board if you have any questions concerning this assignment. Note that, per the course syllabus, no submission will be accepted past the due date.

This assignment asks you to use scenario diagrams to think about the interactions between objects, and explores Ruby a bit further.

Problem 1:

Here is an interaction in a tic-tac-toe game, with user input in bold:

>> gm = Game.new('andy', 'mike')
=> #<Game:0x2e91d78 @players=[Andy, Mike]>
>> gm.play_game('mike')
Mike, enter your next O move (1-9): 1
O - -
- - -
- - -
Andy, enter your next X move (1-9): 3
O - X
- - -
- - -
Mike, enter your next O move (1-9): 5
O - X
- O -
- - -
Andy, enter your next X move (1-9): 3
Bad move dude! You go again. O - X
- O -
- - -
Andy, enter your next X move (1-9): 6
O - X
- O X
- - -
Mike, enter your next O move (1-9): 9
O - X
- O X
- - O
Mike, you won!
=> nil
>> gm.play_game('karen')
I don't know that player. Please try again.
=> nil

>> gm.play_game('andy')
Andy, enter your next O move (1-9): 5
- - -
- O -
- - -

When a new game is created, two players register with it by name (the arguments to Game.new). The play_game message is called with one of the player's names and starts a new game where that player plays first using the O marker. (A game can be sent repeated play_game messages so the same pair of players can play multiple games). In each iteration, the current player is prompted for the position of her move and then she enters the move number, where the nine squares are numbered in row-major order from 1 through 9. If a move is illegal (i.e., already occupied), the current player is scolded and prompted again for a move. After each move, the board is redrawn. A game ends when either one of the players forms a horizontal, vertical, or diagonal row of her three markers (in the usual way), or the board is full indicating a tie.

The assignment is not to implement this game in Ruby. Rather, the assignment is to use scenario diagrams to discover the objects, their responsibilities, and the messages they respond to.

Specifically, focus on the scenario of a typical iteration: If the current game is not over, the current player is prompted for a legal move which she supplies and then the move is made and the current game board is displayed. Hand in a single scenario diagram that you believe represents your best design. You can use whatever tools you want to create this diagram including the online tool at https://www.websequencediagrams.com/ which I use for my scenario diagrams.

Problem 2

A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash:

NUCLEOTIDE_COMPLEMENT = {
'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C'
}

The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements are important in bioinformatics since a strand of DNA can be read in forward direction or, equivalently, its complementary strand can be read in its forward direction, which is reverse of the original string's direction. Add the reverse_complement method to your DNA class. In response to reverse_complement, it returns a new DNA instance representing its reverse-complement. Note also that a == b if and only if DNA instances a and b represent the same DNA strand.

>> dna1 = DNA.new('ATTGCC')
=> ATTGCC
>> dna2 = dna1.reverse_complement
=> GGCAAT
>> dna2
=> GGCAAT
>> dna1
=> ATTGCC
>> dna2.reverse_complement
=> ATTGCC
>> dna1.reverse_complement.reverse_complement == dna1
=> true

Problem 3

Write a PhoneContact class that gets initialized with a phone number and a label. The phone number should follow one of the formats of the Phone class from the previous assignment (and you should use the Phone class in this assignment). A label is either a symbol or a string. A phone contact responds to the label, phone_number, and to_s messages. Note that phone_number returns a Phone object:

>> contact1 = PhoneContact.new('(954) 555-1212', :work)
=> (954) 555-1212 (work)
>> contact1.label
=> "work"
>> contact1.phone_number
=> "(954) 555-1212"
>> contact1.to_s
=> "(954) 555-1212 (work)"
>> contact2 = PhoneContact.new(' 955-555-1212', "cell")
=> (955) 555-1212 (cell)
>> contact2.phone_number.area_code
=> 955

Reference no: EM131224581

Questions Cloud

Calculate the labor force participation rate : In the economy of Macroland 60.3 percent of the population is employed, while the unemployment rate is 8.0 percent. Calculate the labor force participation rate.
What makes the person or organization stand out : There are leaders in every field of study and business around the world. Select a business leader you admire. Use your textbook, the Argosy University online library resources, and the Internet to select a leader and then to research the leader's ..
What about special pricing for some markets or customers : What about special pricing for some markets or customers? Show effect on revenues and profitability based on stated assumptions. Potential advantages and disadvantages, both financial and non-financial.
Calculate the income elasticity of demand : Calculate the income elasticity of demand for this good at the point from part d).  Is good X normal or inferior? Calculate the effect of a 3.5 percent decrease in income on the demand for good X (all other demand factors being held constant and pr..
Interaction in a tic-tac-toe game : Write a PhoneContact class that gets initialized with a phone number and a label. The phone number should follow one of the formats of the Phone class from the previous assignment (and you should use the Phone class in this assignment).
Determine the percentage of mass transfer resistance : ENSC3019 Assignment - Mass Transfer and Absorptions. Water is used to absorb the vapor of methanol at 300 K and 101.325 kPa. The concentration of methanol in both gas and liquid phases are very low, with the equilibrium relation following Henry's L..
Prepare an income statement and balance sheet : Formulating Financial Statements from Raw Data . -  Prepare an income statement, balance sheet, and statement of cash flows for General Mills, Inc.
What is a managerial accounting model : How can we reconcile the two statements? What is a managerial accounting model? Read the article and comment on some aspect of the discussion in an attempt to shed some light on this topic. What are your thoughts at this juncture?
Recruitment process and the selection process : What are the differences (if any) between the recruitment process and the selection process? In what ways are they interchangeable and dependent on each other?

Reviews

Write a Review

Database Management System Questions & Answers

  Knowledge and data warehousing

Design a dimensional model for analysing Purchases for Adventure Works Cycles and implement it as cubes using SQL Server Analysis Services. The AdventureWorks OLTP sample database is the data source for you BI analysis.

  Design a database schema

Design a Database schema

  Entity-relationship diagram

Create an entity-relationship diagram and design accompanying table layout using sound relational modeling practices and concepts.

  Implement a database of courses and students for a school

Implement a database of courses and students for a school.

  Prepare the e-r diagram for the movie database

Energy in the home, personal energy use and home energy efficiency and Efficient use of ‘waste' heat and renewable heat sources

  Design relation schemas for the entire database

Design relation schemas for the entire database.

  Prepare the relational schema for database

Prepare the relational schema for database

  Data modeling and normalization

Data Modeling and Normalization

  Use cases perform a requirements analysis for the case study

Use Cases Perform a requirements analysis for the Case Study

  Knowledge and data warehousing

Knowledge and Data Warehousing

  Stack and queue data structure

Identify and explain the differences between a stack and a queue data structure

  Practice on topic of normalization

Practice on topic of Normalization

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd