For your third project, you will create a computer version of the game Deduction, a variant of the board game "Clue", Clue's rules can be found on wikipedia. Deduction is somewhat simplified, and is played as follows:
There are 6 Person cards, 6 Weapon cards, and 9 Location cards. A Person card, Weapon card, and Location card are selected at random in secret. These 3 cards represent a crime -- the location, murderer, and weapon used. The object of the game is to determine who committed the crime where using what weapon. More prosaically, the players are trying to determine which 3 cards were chosen secretly.
After the 3 cards are chosen, the remaining 18 cards are shuffled and divided evenly among the players. Play then proceeds as follows:
Code structure:
Your project needs to have the following classes:
Taking a closer look at each of these classes:
Accusation.java. This class represents an accusation -- essentially just 3 cards, representing a person, location, and weapon. See the bottom of this webpage for a link to download this file.
public class Accusation
{
public PersonCard person;
public LocationCard location;
public WeaponCard weapon;
public Accusation(PersonCard person, LocationCard location, WeaponCard weapon)
{
this.person = person;
this.location = location;
this.weapon = weapon;
}
public String toString()
{
return person.toString() + " did it in the " + location.toString() + " with the " + weapon.toString();
}
public boolean equals(Accusation other)
{
return person.equals(other.person) && location.equals(other.location) && weapon.equals(other.weapon);
}
}
Player.java This class is an abstract superclass that you need to extend for the human player and computer player. See the bottom of this webpage for a link to download this file. You may modify this class (adding methods, etc) if you would like
public abstract class Player
{
protected Hand myHand;
protected int playerNumber;
public Player(Hand myHand, int playerNumber)
{
this.myHand = myHand;
this.playerNumber = playerNumber;
}
public String toString()
{
return "Player " + playerNumber;
}
/**
* This method is called by the main program when this player's accusation has been refuted.
* The main program will first call the makeAccusation method of this class to make the
* actual accusation, and then the main program will discover who can refute this
* accusation, and then call this method to inform this player how the accusation was refuted
* @param accusationMade The accusation that was made
* @param card The card that refutes the accusation (or null if there is no refutation)
* @param player the player that refuted the accusation (or -1 if there is no refutation)
*/
public abstract void AccusationRefuted(Accusation accusationMade, Card card, int player);
/**
* This method is called when an accusation is made by some other player, and then refuted
* by a different other player. For human players, a message should be printed to the
* screen, computer players will need to store this information to make better guesses in
* the future
* @param accusationMade The accusation that was made
* @param accusingPlayer The player that made the accusation
* @param player the player that refuted the accusation (or -1 if there was no refutation)
*/
public abstract void OtherPlayerAccusation(Accusation accusationMade, int accusingPlayer, int refutingPlayer);
/**
* This method is called by the main program when it is this player's turn to make an accusation.
* The player decides what accusation to make (for a human player by prompting the human for
* input, for a computer player by deciding in code), and returns the accusation
* @return The accusation for this player to make
*/
public abstract Accusation makeAccusation();
/**
* This method is called when a different player has made an accusation, and this player
* needs to check to see if the accusation is valid. If this player has a card that
* refutes the accusation, then return that card. If this player does not have a card
* that refutes the accusation, return null
* @param acc The accusation that was made
* @return A card that refutes this accusation, or null if this player does not have a card
* to refute this accusation
*/
public abstract Card CheckAccusation(Accusation acc, int accusingPlayer);
}
HumanPlayer.java
HumanPlayer has the following methods:
ComputerPlayer.java
Your computer player can be somewhat naive. Keep track of an array of booleans for Locations, People, and Weapons, that state which locations, people, and weapons are potentially correct. Start by setting all potential locations, people, and weapons are potentially correct. For each card in the computer hand, mark the location, person, or weapon defined by that card to be not potentially correct. To make an accusation, pick any location, person, and weapon that are all still possible. When a response is given to the application, set the appropriate potential value to false.
Deduction.java:
This is your main class. Your main program should:
Sample Output 1:
Enter number of Computer Players:
1
Enter number of Human Players:
1
Player 0 hand:
Person Card: Wolber
Person Card: Pacheco
Person Card: Rollins
Location Card: Dean's Office
Location Card: Library
Location Card: Harney Hallway
Location Card: Kudlick Room
Weapon Card: Laptop
Weapon Card: Monitor
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
1
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
1
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
5
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: K Hall with the Weapon Card: Smartphone refuted by player 1 with card Weapon Card: Smartphone
Player 0. Accusation made by 1
Person Card: Benson did it in the Location Card: Kudlick Room with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Location Card: Kudlick Room
1: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: Kudlick Room with the Weapon Card: Laptop made by player 1 refuted by player 0
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
0
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
2
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
5
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: K Hall with the Weapon Card: Router not refuted
Player 0 wins with accusation Person Card: Benson did it in the Location Card: K Hall with the Weapon Card: Router
Sample Output 2:
Enter number of Computer Players:
2
Enter number of Human Players:
1
Player 0 hand:
Person Card: Benson
Person Card: Rollins
Location Card: Lone Mountain
Location Card: CS Office
Location Card: Dean's Office
Weapon Card: Laptop
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
1
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
0
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
7
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: Lone Mountain with the Weapon Card: Laptop refuted by player 1 with card Person Card: Galles
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: Kudlick Room with the Weapon Card: Laptop made by player 1 refuted by player 2
Player 0. Accusation made by 2
Person Card: Benson did it in the Location Card: CS Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Person Card: Benson
1: Location Card: CS Office
2: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: CS Office with the Weapon Card: Laptop made by player 2 refuted by player 0
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
0
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
7
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Lone Mountain with the Weapon Card: Laptop not refuted
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: Laptop Lab with the Weapon Card: Laptop made by player 1 refuted by player 2
Player 0. Accusation made by 2
Person Card: Galles did it in the Location Card: CS Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Location Card: CS Office
1: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: CS Office with the Weapon Card: Laptop made by player 2 refuted by player 0
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
1
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
4
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Dean's Office with the Weapon Card: Smartphone not refuted
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: Library with the Weapon Card: Laptop made by player 1 refuted by player 2
Player 0. Accusation made by 2
Person Card: Galles did it in the Location Card: Dean's Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Location Card: Dean's Office
1: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: Dean's Office with the Weapon Card: Laptop made by player 2 refuted by player 0
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
1
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
0
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Kudlick Room with the Weapon Card: Smartphone refuted by player 2 with card Location Card: Kudlick Room
Player 0. Accusation made by 1
Person Card: Benson did it in the Location Card: CS Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Person Card: Benson
1: Location Card: CS Office
2: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Benson did it in the Location Card: CS Office with the Weapon Card: Laptop made by player 1 refuted by player 0
Player 0. Accusation made by 2
Person Card: Galles did it in the Location Card: K Hall with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: K Hall with the Weapon Card: Laptop made by player 2 refuted by player 0
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
1
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
1
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Laptop Lab with the Weapon Card: Smartphone refuted by player 2 with card Location Card: Laptop Lab
Player 0. Accusation made by 1
Person Card: Jung did it in the Location Card: CS Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Location Card: CS Office
1: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: CS Office with the Weapon Card: Laptop made by player 1 refuted by player 0
Player 0. Accusation made by 2
Person Card: Galles did it in the Location Card: K Hall with the Weapon Card: Smartphone
Player 0 does not have a card to refute Accusation
Message to Player 0:
Accusation Person Card: Galles did it in the Location Card: K Hall with the Weapon Card: Smartphone made by player 2 refuted by player 1
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
1
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
2
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Library with the Weapon Card: Smartphone refuted by player 2 with card Location Card: Library
Player 0. Accusation made by 1
Person Card: Jung did it in the Location Card: Dean's Office with the Weapon Card: Laptop
Pick a card to show to refute Accusation
0: Location Card: Dean's Office
1: Weapon Card: Laptop
0
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: Dean's Office with the Weapon Card: Laptop made by player 1 refuted by player 0
Player 0. Accusation made by 2
Person Card: Jung did it in the Location Card: K Hall with the Weapon Card: Smartphone
Player 0 does not have a card to refute Accusation
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: K Hall with the Weapon Card: Smartphone made by player 2 not refuted
Player 2 wins with accusation Person Card: Jung did it in the Location Card: K Hall with the Weapon Card: Smartphone
Sample Output 3:
Enter number of Computer Players:
0
Enter number of Human Players:
1
Player 0 hand:
Person Card: Wolber
Person Card: Rollins
Person Card: Galles
Person Card: Pacheco
Person Card: Benson
Location Card: UC
Location Card: Harney Hallway
Location Card: Library
Location Card: Lone Mountain
Location Card: K Hall
Location Card: Dean's Office
Location Card: Laptop Lab
Location Card: Kudlick Room
Weapon Card: Keyboard
Weapon Card: Smartphone
Weapon Card: Cable
Weapon Card: Monitor
Weapon Card: Laptop
Player 0
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
8
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
-3
Pick a person to accuse:
0: Person Card: Benson
1: Person Card: Galles
2: Person Card: Jung
3: Person Card: Pacheco
4: Person Card: Rollins
5: Person Card: Wolber
2
Pick a Weapon:
0: Weapon Card: Laptop
1: Weapon Card: Smartphone
2: Weapon Card: Router
3: Weapon Card: Cable
4: Weapon Card: Monitor
5: Weapon Card: Keyboard
2
Pick a Location:
0: Location Card: Kudlick Room
1: Location Card: Laptop Lab
2: Location Card: Library
3: Location Card: CS Office
4: Location Card: Dean's Office
5: Location Card: K Hall
6: Location Card: Harney Hallway
7: Location Card: Lone Mountain
8: Location Card: UC
3
Message to Player 0:
Accusation Person Card: Jung did it in the Location Card: CS Office with the Weapon Card: Router not refuted
Player 0 wins with accusation Person Card: Jung did it in the Location Card: CS Office with the Weapon Card: Router