Project 3 - Deduction

Due - Friday, 4/13, 5:00pm

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:

    • The first player makes an accusation: she picks a Person, Weapon, and Location she thinks describes the crime
      • If the player to the left of the accusing player has a card that refutes the crime, he must show that card to the accusing player. No other player can see the card (though they can see that the accusation was refuted) If there is more than once card that can refute the crime, he may show her any of those cards that he likes. Once the crime is refuted, the first player's turn ends.
      • If the player to the left of the accusing player cannot refute the crime, then the next player has a chance to refute the crime. This continues until either the crime has been refuted, or no one is able to refute the crime.
      • If the accusation is correct, then the accuser wins.
    • After the first person makes an accusation, play continues on the player to her left. Play continues until one player makes a correct accusation.

Code structure:

Your project needs to have the following classes:

    • Card, PersonCard, WeaponCard, LocationCard, Hand (from previous lab)
    • Player, Accusation (provided, see the bottom of this page for the download link)
    • HumanPlayer This class needs to be a subclass of the provided Player class. This class implements a human player, by printing messages out to the screen, and getting input from the keyboard
    • ComputerPlayer This class needs to be a subclass of the provided Player class. This class implements a computer player.
    • Deduction The main class, which handles all of the game logic

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:

  • public Accusation makeAccusation(); Prompt the user to select a weapon, person, and location, by giving a list of possible weapons, people, and locations, and letting the user select by typing in a number. This method should do error checking, and keep prompting the user until a valid accusation is created
  • public Card CheckAccusation(Accusation acc, int accusingPlayer); Print out the accusation, and give the user a list of cards that could refute this accusation, and then prompt the user to pick the desired refutation by typing in a number.
  • public void AccusationRefuted(Accusation accusationMade, Card card, int player) Print out the accusation, who refuted the accusation, and the card that was used to refute the accusation
  • public void OtherPlayerAccusation(Accusation accusationMade, int accusingPlayer, int refutingPlayer); Print out the accusation made by someone else, who made the accusation, and who refuted it.

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.

  • public Accusation makeAccusation() Pick a weapon, location, and person that are all potentially correct.
  • public Card CheckAccusation(Accusation acc, int accusingPlayer); Pick any card that could refute this accusation, Return null if no card can refute this accusation.
  • public void AccusationRefuted(Accusation accusationMade, Card card, int player) Set the location, weapon, or person described by the card as no longer potentially correct.
  • public void OtherPlayerAccusation(Accusation accusationMade, int accusingPlayer, int refutingPlayer) For the simple version of the computer player, you can do nothing for this method. Feel free to write a more complex computer player that uses this information.

Deduction.java:

This is your main class. Your main program should:

    • Prompt the user for how many human and computer players there are
    • Randomly pick a Person, Location, and Weapon card
    • Shuffle the remaining cards, and deal them out into the correct number of hands (one hand for each player)
    • Create an array of players (using proper number of computer and human players)
    • Create all of the players, passing each player a unique player number and a hand of cards
    • Play the game:
      • Call the makeAccusation method of the first player, to get an accusation.
      • Using this Accusation, call the CheckAccusation methods of each of the subsequent players, until either one of these method calls returns a non-null value, or all other players return null from CheckAccusation
      • Call the AccusationRefuted method on the first player, letting that player know who refuted the accusation with which card.
      • Call the OtherPlayerAccusation method on all other players (other than the first player or the player that refuted the accusation) so that all other players know who made the accusation, and who refuted it.
      • If the accusation was true, end the game
      • If the accusation was false, go on to the next player. Continue until one player wins.

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