Solve the following problems using Scala with Classic Akka Actors.  For each problem, also implement client actors for sending the messages required for beginning the required computation.  Use these client actors for testing your application actors. Recall the card shuffling problem.  In a Faro shuffle, a stack of cards is broken up into two, and then combined so that a card from one sub-stack is followed by one from the other, and so on.   A perfect Faro shuffle breaks up the stack into two sub-stacks of exactly the same size, and then combines them in the manner described above.  An out-shuffle results in the top and the bottom cards of the stack remaining the same after the shuffle; an in-shuffle results in these cards becoming the second and the second last cards of the shuffled stack. Implement a shuffler actor which accepts a message containing a deck of cards as a list of even length, an integer indicating the number of times that the deck is to be shuffled, and a boolean indicating whether the shuffles should be in-shuffle (false) or out-shuffle (true).  Once it is done shuffling the deck, it returns the shuffled deck to the sender of the message.  The shuffler shuffles with the help of two other actors -- splitter and faroShuffler.  The shuffler sends a message to the splitter containing the deck of cards, and the name of faroShuffler.  The shuffler also sends a message to faroShuffler with a boolean indicating whether in-shuffle or out-shuffle is required.  On receiving the deck, the splitter evenly splits the deck of cards into two lists, and sends the two lists to faroShuffler, one at a time.  Once faroShuffler has received the two lists, and once it knows what type of shuffle is to be carried out, it first tells a cardCollector actor the shuffler's name and the number of cards to expect to receive; next, it begins sending the cards from its two decks to the cardCollector actor -- one card at a time, alternating between the two lists, beginning with the list required for the correct type of shuffle.  The cardCollector actor simply collects the cards in the order in which they are received in a list, and when it has received all of them, it sends the list of cards to shuffler.  Only the shuffler keeps track of how many shuffles have been completed, and when the required number of shuffles are done, it sends the shuffled deck to the actor requesting it.  Develop code to implement these actors for shuffling a deck of cards.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Solve the following problems using Scala with Classic Akka Actors.  For each problem, also implement client actors for sending the messages required for beginning the required computation.  Use these client actors for testing your application actors.

Recall the card shuffling problem.  In a Faro shuffle, a stack of cards is broken up into two, and then combined so that a card from one sub-stack is followed by one from the other, and so on.   A perfect Faro shuffle breaks up the stack into two sub-stacks of exactly the same size, and then combines them in the manner described above.  An out-shuffle results in the top and the bottom cards of the stack remaining the same after the shuffle; an in-shuffle results in these cards becoming the second and the second last cards of the shuffled stack.

Implement a shuffler actor which accepts a message containing a deck of cards as a list of even length, an integer indicating the number of times that the deck is to be shuffled, and a boolean indicating whether the shuffles should be in-shuffle (false) or out-shuffle (true).  Once it is done shuffling the deck, it returns the shuffled deck to the sender of the message. 

The shuffler shuffles with the help of two other actors -- splitter and faroShuffler.  The shuffler sends a message to the splitter containing the deck of cards, and the name of faroShuffler.  The shuffler also sends a message to faroShuffler with a boolean indicating whether in-shuffle or out-shuffle is required.  On receiving the deck, the splitter evenly splits the deck of cards into two lists, and sends the two lists to faroShuffler, one at a time.  Once faroShuffler has received the two lists, and once it knows what type of shuffle is to be carried out, it first tells a cardCollector actor the shuffler's name and the number of cards to expect to receive; next, it begins sending the cards from its two decks to the cardCollector actor -- one card at a time, alternating between the two lists, beginning with the list required for the correct type of shuffle.  The cardCollector actor simply collects the cards in the order in which they are received in a list, and when it has received all of them, it sends the list of cards to shuffler. 

Only the shuffler keeps track of how many shuffles have been completed, and when the required number of shuffles are done, it sends the shuffled deck to the actor requesting it. 

Develop code to implement these actors for shuffling a deck of cards.  

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education