Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Ability.class
Binary file not shown.
6 changes: 6 additions & 0 deletions Ability.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#BlueJ class context
comment0.target=String\ toString()
comment1.target=int\ uses()
comment2.params=deck\ discardPile\ players
comment2.target=void\ use(LStack<Card>,\ LStack<Card>,\ ArrayList<Player>)
numComments=3
10 changes: 10 additions & 0 deletions Ability.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.util.ArrayList;

public interface Ability
{
public String toString();
public String name();
public int uses();
public boolean endTurn();
public void use(Deck deck, DiscardPile discardPile, ArrayList<Player> players);
}
Binary file added AggressiveCycle.class
Binary file not shown.
7 changes: 7 additions & 0 deletions AggressiveCycle.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#BlueJ class context
comment0.params=owner
comment0.target=AggressiveCycle(Player)
comment1.params=deck\ playerList\ discardPile
comment1.target=void\ play(LStack<Card>,\ ArrayList<Player>,\ LStack<Card>)
comment1.text=\n@param\ deck\ The\ current\ deck\ we're\ playing\ with.\n@param\ playerList\ The\ list\ of\ playrs\ we're\ playing\ with.\n@param\ discardPile\ The\ growing\ discardPile\ in\ the\ game.\n\n
numComments=2
25 changes: 20 additions & 5 deletions AggressiveBehavior.java → AggressiveCycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* in any situation. If the AI can play several cards in one turn, it will always play those. It will play a matching
* card by number than by suit. If it cannot play a card, it will draw until it has a playable card.
*/
public class AggressiveBehavior implements Behavior
public class AggressiveCycle implements Behavior
{
public Player owner;

public AggressiveBehavior(Player owner)
public AggressiveCycle(Player owner)
{
this.owner = owner;
}
Expand All @@ -20,7 +20,7 @@ public AggressiveBehavior(Player owner)
* @param playerList The list of playrs we're playing with.
* @param discardPile The growing discardPile in the game.
*/
public void play(LStack<Card> deck, ArrayList<Player> playerList, LStack<Card> discardPile)
public void play(Deck deck, ArrayList<Player> playerList, DiscardPile discardPile)
{
ArrayList<Card> hand = owner.hand;
Card topCard = discardPile.peek();
Expand Down Expand Up @@ -51,6 +51,8 @@ public void play(LStack<Card> deck, ArrayList<Player> playerList, LStack<Card> d

// DecisonReached will be set to 'true' as soon as any card is played.
boolean decisionReached = false;
boolean cardDrawn = false;
int cardsDrawn = 0;
while(!decisionReached)
{
// Check the active suit, this will be changed later.
Expand Down Expand Up @@ -82,6 +84,8 @@ public void play(LStack<Card> deck, ArrayList<Player> playerList, LStack<Card> d
{
for(Card card : playableCardsByValue)
{
if(owner.hand.size() == 1)
System.out.println(owner.say(owner.tauntText, "shouted"));
owner.hand.remove(card);
discardPile.push(card);
System.out.println(owner + " played a " + card);
Expand All @@ -102,18 +106,29 @@ public void play(LStack<Card> deck, ArrayList<Player> playerList, LStack<Card> d
// Play the first card from this list if we can play from it.
if(playableCardsBySuit.size() >= 1)
{
if(owner.hand.size() == 1)
System.out.println("Thrall shouted, \"" + owner.tauntText + "\"");

owner.hand.remove(playableCardsBySuit.get(0));
discardPile.push(playableCardsBySuit.get(0));
System.out.println(owner + " played a " + playableCardsBySuit.get(0));
decisionReached = true;
}
else
else if(!cardDrawn)
{
// We can't play a single card, so draw.
Card drawCard = deck.pop();
owner.hand.add(drawCard);
System.out.println(owner + " drew a " + drawCard);
System.out.println(owner + " drew a card.");
cardDrawn = true;
cardsDrawn++;
}
else if(cardDrawn)
{
owner.ability.use(deck, discardPile, playerList);
decisionReached = true;
}
else if(cardsDrawn == 3) decisionReached = true;
}
}
}
Expand Down
Binary file added AggressiveFabricate.class
Binary file not shown.
7 changes: 7 additions & 0 deletions AggressiveFabricate.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#BlueJ class context
comment0.params=owner
comment0.target=AggressiveFabricate(Player)
comment1.params=deck\ playerList\ discardPile
comment1.target=void\ play(LStack<Card>,\ ArrayList<Player>,\ LStack<Card>)
comment1.text=\n@param\ deck\ The\ current\ deck\ we're\ playing\ with.\n@param\ playerList\ The\ list\ of\ playrs\ we're\ playing\ with.\n@param\ discardPile\ The\ growing\ discardPile\ in\ the\ game.\n\n
numComments=2
141 changes: 141 additions & 0 deletions AggressiveFabricate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

import java.util.ArrayList;

/**
* AggressiveBehavior is the basic AI behavior characters will use. AggressiveBehavior favors playing the most cards
* in any situation. If the AI can play several cards in one turn, it will always play those. It will play a matching
* card by number than by suit. If it cannot play a card, it will draw until it has a playable card.
*/
public class AggressiveFabricate implements Behavior
{
public Player owner;

public AggressiveFabricate(Player owner)
{
this.owner = owner;
}

/**
* @param deck The current deck we're playing with.
* @param playerList The list of playrs we're playing with.
* @param discardPile The growing discardPile in the game.
*/
public void play(Deck deck, ArrayList<Player> playerList, DiscardPile discardPile)
{
ArrayList<Card> hand = owner.hand;
Card topCard = discardPile.peek();
ArrayList<Integer> eightSuits = new ArrayList<Integer>(); // The different suits we have for our eight cards.

// NumSuits will store the number of cards we have for each suit. The order of this array is:
// diamond heart club space
// So if we have 4 hearts, 2 clubs, and 2 spades, our array will be {0, 4, 2, 2}
int[] numSuits = {0, 0, 0, 0};
for(Card card : hand)
{
int suitSelector = -1;
// Because suits are stored as strings, and we're selecting by integer, we need
// to appropriately associate our suits with appropriate integer values.
if(card.suit.equals("diamond")) suitSelector = 0;
else if(card.suit.equals("heart")) suitSelector = 1;
else if(card.suit.equals("club")) suitSelector = 2;
else if(card.suit.equals("spade")) suitSelector = 3;

// Select the suit that we'll increment.
if(suitSelector > -1) numSuits[suitSelector]++;

if(card.value == 8)
{
eightSuits.add(suitSelector);
}
}

// DecisonReached will be set to 'true' as soon as any card is played.
boolean decisionReached = false;
boolean cardDrawn = false;
int cardsDrawn = 0;
int abilityUsed = 0;
while(!decisionReached)
{
// Check the active suit, this will be changed later.
String activeSuitName = discardPile.peek().suit;
int activeSuit = -1; // The actual integer value we'll use to select a suit with.
int suitSelector = -1; // Mirrored function above, but activeSuit may differ later on.
if(activeSuitName.equals("diamond")) suitSelector = 0;
else if(activeSuitName.equals("heart")) suitSelector = 1;
else if(activeSuitName.equals("club")) suitSelector = 2;
else if(activeSuitName.equals("spade")) suitSelector = 3;

// Similar to suit.
int activeValue = discardPile.peek().value;
boolean multipleCardPlay = false; // Are we going to play multiple cards?
ArrayList<Card> playableCardsByValue = new ArrayList<Card>();

// Fill a list of cards that we can play from our hand that match with the current card.
for(Card card : hand)
{
if(card.value == discardPile.peek().value)
{
playableCardsByValue.add(card);
}
}

// If we have playable cards from the above list, play all of them since we can play multiple
// cards that all match the active card.
if(playableCardsByValue.size() >= 1)
{
for(Card card : playableCardsByValue)
{
if(owner.hand.size() == 1)
System.out.println("Thrall shouted, \"" + owner.tauntText + "\"");
owner.hand.remove(card);
discardPile.push(card);
System.out.println(owner + " played a " + card);
}
decisionReached = true;
}
else
{
// We didn't have any playable cards by value. Do it by suit instead.
ArrayList<Card> playableCardsBySuit = new ArrayList<Card>();

for(Card card : hand)
{
if(card.suit.equals(discardPile.peek().suit))
playableCardsBySuit.add(card);
}

// Play the first card from this list if we can play from it.
if(playableCardsBySuit.size() >= 1)
{
if(owner.hand.size() == 1)
System.out.println(owner.say(owner.tauntText, "shouted"));

owner.hand.remove(playableCardsBySuit.get(0));
discardPile.push(playableCardsBySuit.get(0));
System.out.println(owner + " played a " + playableCardsBySuit.get(0));
decisionReached = true;
}
else if(abilityUsed < owner.ability.uses())
{
owner.ability.use(deck, discardPile, playerList);
abilityUsed += 1;
}
else if(cardsDrawn < 3)
{
// We can't play a single card, so draw.
Card drawCard = deck.pop();
owner.hand.add(drawCard);
System.out.println(owner + " drew a card.");
cardDrawn = true;
cardsDrawn++;
}
else
{
decisionReached = true;
}
}
}

System.out.println("\n\n");
}
}
Binary file added Behavior.class
Binary file not shown.
4 changes: 4 additions & 0 deletions Behavior.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#BlueJ class context
comment0.params=deck\ playerList\ discardPile
comment0.target=void\ play(LStack<Card>,\ ArrayList<Player>,\ LStack<Card>)
numComments=1
2 changes: 1 addition & 1 deletion Behavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/
public interface Behavior
{
public void play(LStack<Card> deck, ArrayList<Player> playerList, LStack<Card> discardPile);
public void play(Deck deck, ArrayList<Player> playerList, DiscardPile discardPile);
}
Binary file modified Card.class
Binary file not shown.
10 changes: 10 additions & 0 deletions Card.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#BlueJ class context
comment0.params=newValue\ newSuit
comment0.target=Card(int,\ String)
comment0.text=\nConstructor\ for\ objects\ of\ class\ Card\n\n
comment1.target=String\ toString()
comment1.text=\n@return\ This\ card\ in\ the\ format\ of\:\ "{Value}\ of\ {suit}\ ({shorthand})"\n\n
comment2.params=other
comment2.target=int\ compareTo(Card)
comment2.text=\nProvide\ a\ method\ that\ allows\ us\ to\ compare\ to\ cards.\ Card\ order\ is\ determined\ firstly\ by\ suit\ in\ this\ fashion\:\nDiamonds\ >\ Hearts\ >\ Spades\ >\ Clubs\nIf\ the\ suit\ of\ two\ cards\ is\ the\ same,\ then\ compare\ their\ value.\ne.g.\ A\ 2\ of\ Diamonds\ is\ greater\ than\ an\ Ace\ of\ Spaces\nA\ 9\ of\ Diamonds\ is\ less\ than\ a\ King\ of\ Diamonds\nA\ Queen\ of\ Hearts\ is\ greater\ than\ a\ Queen\ of\ Clubs.\nA\ card\ not\ of\ the\ four\ cardinal\ suits\ is\ ALWAYS\ considered\ less\ than\ a\ card\ form\ these\ suits.\n\n@param\ other\ The\ other\ card\ to\ compare\ this\ card\ to.\n@return\ -1,\ 0,\ 1\ Pending\ if\ this\ card\ are\ less\ than,\ equal\ to,\ or\ greater\ than\ the\ other.\n\n
numComments=3
36 changes: 25 additions & 11 deletions Card.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import java.lang.Comparable;
import java.util.ArrayList;

/**
* The Card class holds information on a card's name, it's suit, value. It also includes methods to print
Expand Down Expand Up @@ -86,22 +86,36 @@ public int compareTo(Card other)
// If one card is of a greater suit, return appropriately.
// If not, work it out based on their values. Two cards are only equal if their suit matches as well as their values.
if(ranks[0] > ranks[1])
{
ret = 1;
}
return 1;
else if(ranks[1] > ranks[0])
{
ret = -1;
}
return -1;
else
{
// We now know this to be the same suit.
// We are now just comparing the integer value of the card, so why not reuse ranks?
ranks[0] = this.value;
ranks[1] = other.value;
if(ranks[0] > ranks[1]) ret = 1;
if(ranks[1] > ranks[0]) ret = -1;
if(ranks[0] > ranks[1]) return 1;
if(ranks[1] > ranks[0]) return -1;
}
return ret;
return 0;
}

//Checks if the card is a valid play.
public boolean validPlay(Card other)
{
if(this.value == other.value || this.suit == other.suit)
return true;
else
return false;
}

//Extra method to check that we can have multiple cards played
// in one turn.
// All of the ranks being played must be the same as the discard Pile's top card.
public boolean sameRank(ArrayList<Card> hand, int amount)
{
if(amount == 0) return (this.value == hand.get(0).value);
return (this.value == hand.get(amount).value) && sameRank(hand, amount-1);
}
}
}
Binary file added Classic/c00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Classic/d00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Classic/h00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Classic/s00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Crazy8Driver.class
Binary file not shown.
26 changes: 26 additions & 0 deletions Crazy8Driver.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#BlueJ class context
comment0.params=args
comment0.target=void\ main(String[])
comment1.params=deck\ playerList\ cardStack
comment1.target=void\ playerTurn(LStack<Card>,\ ArrayList<Player>,\ LStack<Card>)
comment1.text=\nThis\ class\ should\ handle\ everything\ that\ goes\ on\ during\ a\ player's\ turn.\n@param\ deck\ The\ deck\ we\ might\ be\ drawing\ from.\n@param\ The\ list\ of\ players\ (their\ hands\ included)\ we're\ working\ with.\n@param\ cardStack\ The\ growing\ stack\ of\ cards.\n\n
comment2.params=userin\ player\ discardPile
comment2.target=boolean\ discard(Scanner,\ Player,\ LStack<Card>)
comment2.text=\n@param\ userin\ The\ scanner\ to\ read\ from.\n@param\ player\ Our\ player.\n@param\ discardPile\ The\ growing\ discard\ pile.\n@return\ If\ a\ card\ was\ discarded\ or\ not.\n\n
comment3.params=player\ deck
comment3.target=Card\ drawCard(Player,\ LStack<Card>)
comment4.params=dialogue\ character
comment4.target=void\ pacedDialogue(String,\ Player)
comment4.text=\npacedDialogue\ is\ a\ method\ we\ use\ that\ enters\ input\ and\ then\ tells\ the\ computer\ to\ wait.\ This\ makes\ it\ so\ that\ the\ player\ can\ notice\ and\ process\nthe\ dialogue,\ instead\ of\ it\ all\ happening\ at\ once.\ Usually,\ .pacedDialogue()\ will\ be\ followed\ another\ call\ to\ this\ method,\ resembling\ some\nartificial\ pause\ in\ speech.\n@param\ dialogue\ The\ string\ to\ print\ out.\n@param\ character\ The\ speaker\ for\ this\ line\ of\ dialogue.\n\n
comment5.target=void\ helpMenu()
comment5.text=\nPrint\ out\ and\ handle\ user\ input\ for\ a\ series\ of\ interactive\ menus\ that\ offer\ rules,\ context,\ and\ assistance\ to\ players.\n\n
comment6.params=playerCache
comment6.target=ArrayList<Player>\ instantiatePlayers(ArrayList<Player>)
comment6.text=\nThis\ class\ is\ used\ to\ offer\ the\ player\ input\ to\ select\ a\ character\ to\ play\ as,\ how\ many\ AI\ opponents\ they\ will\ face,\nand\ randomly\ select\ their\ AI\ opponents.\n@param\ playerCache\ The\ cache\ of\ players\ to\ take\ a\ character\ from.\n@return\ A\ list\ of\ players\ for\ the\ game.\n\n
comment7.params=deck\ players\ playerList
comment7.target=ArrayList<ArrayList<Card>>\ dealCards(LStack<Card>,\ int,\ ArrayList<Player>)
comment7.text=\n@param\ deck\ A\ collection\ of\ cards\ to\ randomly\ deal\ cards\ from.\n@param\ players\ The\ number\ of\ players\ to\ deal\ a\ hand\ to.\n@param\ playerList\ The\ list\ of\ players\ to\ deal\ cards\ to.\n@return\ A\ collection\ of\ hands\ filled\ with\ 8\ cards\ from\ the\ deck.\n\n@precondition\ That\ the\ deck\ passed\ into\ is\ greater\ than\ the\ number\ of\ players\ times\ eight.\n@postcondition\ That\ the\ deck\ passed\ into\ has\ decreased\ in\ size\ by\ a\ multiple\ of\ eight.\n\n
comment8.target=LStack<Card>\ makeDeck()
comment8.text=\n@return\ A\ new,\ randomly\ filled\ deck\ of\ the\ four\ suits,\ 1\ through\ Ace.\n\n
comment9.target=ArrayList<Player>\ populatePlayerCache()
numComments=10
Loading