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.
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.

Step by step
Solved in 3 steps









