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

  Write the relational schema and draw its dependency diagram

Write the relational schema, draw its dependency diagram, and identify all dependencies, including all partial and transitive dependencies.

  Use of data definition language-data manipulation language

Pick one of the different types of SQL statements (data definition language, data manipulation language, or data control language). Describe how that type of statement is use.

  Same name to attributes which are in different tables

What about giving same name to attributes which are in different tables but are not same? For instance, "Description" in both a Course table and a Classroom table.

  How much indirect factory wages and factory equipment

How much indirect factory wages and factory equipment depreciation cost would be assigned to the Customer Orders activity cost pool

  Isom database assignment

You are provided with a case which will be used for the assignments dealing with design and implementation of database.

  Modify the clsdatalayer to use a two-step process

Modify the SavePersonnel() function so that instead of just doing a single SQL INSERT operation with all the personnel data, it does an INSERT with only the FirstName and LastName, followed by an UPDATE to save the PayRate, StartDate, and EndDate ..

  Use sql to create database

Use SQL to create the following database; to including referential integrity. You may NOT use the GUI for this part of the exercise. COURSE ( CourseNu, CourseName, CreditHrs).

  Write a script that creates a cursor for a result set

Write a script that creates a cursor for a result set that consists of the ProductName and ListPrice columns for each product with a list price that's greater than $700.

  Search for a record based on a particular field value

For each of the following queries, which of the listed index choices would you choose to speed up the query? If your database system does not consider index-only plans (i.e., data records are always retrieved even if enough information is available i..

  Create a sql statement and execute the same in sqlplus

Statistics can be created on tables, indexes columns and as well as on the individual columns. But, if for some reason table or index statistics have not been updated, then this may result in a full table scan.

  Draw the flowchart for the decision structure

Identify appropriate test values for the decision structure and submit the results of a desk check of the program.

  Program that performs mathematical operations

Create a batch file program that performs 4 mathematical operations such as addition, subtraction, multiplication and division.

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