Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSCI 1110: Assignment 4

Due: 11:59 pm, Sunday, December 4, 2022

The purpose of this assignment is to reinforce your understanding of linear data structures, in particular, linked lists.  For this problem you will be provided with sample tests in Codio. All input is done via the console and all output is to be done to the console as well. You must submit your assignment via Codio, and you can test it by submitting your code. Note: for this assignment you are ex- pected to install and use an IDE (other than Codio) to develop your code. Please see How-To videos in the How-To Tutorial Section of our Brightspace page on how to install an IDE.

This assignment is divided into three problems, where each problem builds on the next. Each problem subsumes the previous one. Hence, if you complete Problem 3, you will have also completed Problem 2 and Problem 1. Note: For this assignment you may NOT use any kind of collection or array provided by Java. E.g., you cannot use arrays, you cannot use ArrayList, LinkedList, Queue, Vector,  etc.

Problem 1 : Circular Linked List

For this problem you will be asked to implement a generic circular linked list, which is a simplified version of a linked list.  A circular linked list is like a linked list except that

1.    There is no head or tail because the last node in the list is linked to the first.

2.    Instead of a head or tail there is a cursor, which points to the current node in the list.  The cursor

can   be   moved   forward   or

backward    in    the    circular

linked list.  If the cursor is re-

peatedly  moved  forwards,  it

will  eventually  return to the

node from where it started.

Implement a class called CircularList in CircularList.java.

The CircularList class should have the following generic declaration:


public class CircularList {
private Node cursor
}


You will also need to implement a Node class to implement nodes in the circular linked list. You can decide if you would prefer to declare the Node class inside the CircularList class or in a separate file.  It is recom- mended that your Node class have the following declaration


class Node {
private Node next;
private Node prev;
T value;
}


To declare a variable and instantiate a CircularClass to store String you would do something like:


CircularList stringList = new CircularList<>();


Your CircularList class should provide the following public methods:

Constructor / Method

Description

void add(T value)

Creates a node and adds it to the circular list imme- diately before the cursor. If the list is empty, the cursor refers to the new node.

T current ()

Returns the value stored in the node referred to by the cursor. If list is empty, return null.

void next()

Move cursor to next node. If the list is empty or has one node in it, the cursor does not change.

T remove()

Remove the node referred to by the cursor from the circular list and return its value. If the list is empty return null.

String toString()

Returns a string containing a representation of the list. See toString() format below.

toString() Format of CircularList

The format of the string returned by the toString() method is

[string0 ,string1 ,string2 ,…,stringN-1 ]

Where string0  is the string representation of value referred to by the cursor, string1  is the string represen- tation of the value after the cursor, and so on up to stringnn- 1, which is the string representation of the value before the cursor.  Use the toString() method of a value to get its string representation.

Input, Processing, and Output

A TestCircularListl.java program will be provided for you to test your CircularList class. This program will instantiate a CircularLIst object and then add, remove, access, and print out elements in the list.  The format of the input is a series of one-word commands, where a command is one of add, next, current, remove, and end.  Where each of the commands performs the corresponding method, ex- cept for end, which ends the test.   After each of the commands, the circular list will be printed out, using the toString() method you implemented.

Examples

Input

Output

current

add

add

add

next

remove

remove

end

Current: null

[]

[0]

[0,1]

[0,1,2]

[1,2,0]

Remove:  1

[2,0]

Remove:  2

[0]

Problem 2: No Choice Duo

For Problem 2 you will implement a simulator for the card game No Choice” .

Game Specification

The game of “No Choice” is a simple card game that can be played among 2 or more players.  The objective of the game is to win as many cards as possible. Each player starts with a pile of cards placed face down in front of them.  The game consists of a fixed number of rounds or until everyone becomes bored.  In each round of play:

1.    All players flip up the top card from their pile in front of them so that all players can see each other’s cards.

2.    The players compare the flipped-up cards and determine the highest card and the lowest card of all flipped-up cards.

3.    All the players except for the one with the lowest card, keep their card and place it face down at the bottom of their pile.  I.e., the card is returned to the pile from which it was taken.

4.    The player with the lowest card gives their card to the player with the highest card, who places the new card face down at the bottom of the pile.

The cards are standard playing cards with values A (Ace), 2, 3, 4, 5, 6, 7, 8, 9, 10, J (Jack), Q (Queen), K (King) and suits: C (clubs), D (diamonds), H (hearts), and S (spades).

When comparing cards, the card with the higher value is consider higher than a card with a lower value. If the values are the same, the tie is broken by the suit in alphabetical order.  I.e., Clubs are the lowest suit and spades are the highest suit.  E.g., a 7 of hearts is higher than a 7 of clubs.

The Task

Write a program called NoChoice.javathat simulates the game of No Choice.. Note: You may not use any existing Collection class in Java, such as ArrayList, or LinkedList, or even a simple array. You may only use your CircularList class and statically initialized arrays that are not modified during runtime.   E.g., arrays containing the possible card values and suits.

Input

All input will be from the console (keyboard) just like in previous assignments.  The input consists of

1.    An integer R denoting the number of rounds of play.

2.    An integer P denoting the number of players.

3.    Followed by P players, where each player is represented by

a.    A single word denoting the players name

b.    An integer C denoting the number of cards the player receives

c.    Followed by C cards, where each card consists of two strings denoting the value and suit of the card, I.e.,

V S

where V is one of A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, and S is one of C, D, H, S. For example, the following game consists of 3 players with 17 cards each, playing 10 rounds:


10

3

Alice  17  9  H  J  S  6  D  8  C  6  C  7  H  A  S  5  S  2  S  7  S  10  S  6  S  4  H  10  H  A  H  9  D  4  S

Bob  17  4  D  3  D  8  D  8  H  10  D  2  D  J  D  4  C  K  D  K  H  5  H  5  D  A  D  J  H  7  D  7  C  5  C

Carol  17  9  S  3  C  K  S  9  C  Q  D  3  H  3  S  2  H  10  C  2  C  K  C  6  H  Q  S  Q  C  J  C  Q  H  8  S


Processing

For Problem 2, you can assume that there are only 2 players.  I.e., the second integer will always be 2. Your No Choice simulator should simulate a game of No Choice between the two players and output the result (see Output). You may assume that

•    All the input will be correct.

•    All the cards are unique, there are no duplicates.

•    Not all the cards in a deck may be used.

•    If a player runs out of cards, the game ends immediately.

Output

After each round output which player loses a card and which player gets it using the format

Loser aiAes VS to Winner

where Loser is the name of the player who lost the card, Winner is the name of the player who won the card, V is the value of the card and S is the suit of card j.  E.g., 10S is the 10 of spades

At the end of the game, for each player, output their name and all the cards that they have in their deck, from top to bottom.

Name [V1S1 ,V2S2 ,V3S3 ,…,VnSn ]

where Vj is the value of the card j and Sj is the suit of card j.  E.g., JH is the jack of hearts.   All output should be to the console, and each line terminated by a newline.  The order of the players should be the same as the input order.

Examples

Input

Output

10

2

Alice 5 9 H J S 6 D 8 C 6 C

Bob 5 4  D  3  D  8  D  8  H  10  D

Bob gives 4D to Alice

Bob gives 3D to Alice

Alice gives 6D to Bob

Alice gives 8C to Bob

Alice gives 6C to Bob

Bob gives 8D to Alice

Alice gives 4D to Bob

Bob gives 8H to Alice

Alice gives 3D to Bob

Alice gives 9H to Bob

Alice [8D,JS,8H]

Bob [6C,6D,4D,8C,3D,10D,9H]

Recommended Approach

•    Decompose your program into a Card class, a Player class and a NoChoice class

•    The main method in your NoChoice class should

o  Read in the number of rounds and the number of players

o  Read in the players and their cards

o Simulate the game for the specified number of rounds.  This will require a nested loop.

o  Print out each player

•    The Player class should use the CircularList implementation to store the cards

•    The Card class should implement the Comparable interface to allow easy comparison of cards.

•    The Player, CircularList, and the Card classes should have their own toString() methods for easy printing of the game results and debugging

Problem 3 : No Choice Complete

Extend your program from Problem 2 to handle one change. There can now be more than two players in a game.  You may not use any Collections or arrays, except CircularList, like before.  Note, you will need to store the players (Player objects) in CircularList.

Input

The input format is the same as in Problem 1.

Processing

Your program should perform the same task as in Problem 2, but with more than two players.

Output

The output format is the same as in Problem 2.

Examples