Remove trailing whitespace throughout, and then widen/vararg/foreachize some

card game stuff that we were looking at.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@804 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Dave Hoover
2009-03-17 17:46:50 +00:00
parent d05664f649
commit 20657dbaff
31 changed files with 271 additions and 301 deletions
@@ -34,8 +34,7 @@ import com.threerings.parlor.turn.client.TurnGameController;
import static com.threerings.parlor.card.Log.log;
/**
* A controller class for card games. Handles common functions like
* accepting dealt hands.
* A controller class for card games. Handles common functions like accepting dealt hands.
*/
public abstract class CardGameController extends GameController
implements TurnGameController, CardCodes, CardGameReceiver
@@ -50,8 +49,7 @@ public abstract class CardGameController extends GameController
Thread.dumpStack();
}
_ctx.getClient().getInvocationDirector().registerReceiver(
new CardGameDecoder(this));
_ctx.getClient().getInvocationDirector().registerReceiver(new CardGameDecoder(this));
super.willEnterPlace(plobj);
}
@@ -61,8 +59,7 @@ public abstract class CardGameController extends GameController
{
super.didLeavePlace(plobj);
_ctx.getClient().getInvocationDirector().unregisterReceiver(
CardGameDecoder.RECEIVER_CODE);
_ctx.getClient().getInvocationDirector().unregisterReceiver(CardGameDecoder.RECEIVER_CODE);
}
// Documentation inherited.
@@ -80,8 +77,8 @@ public abstract class CardGameController extends GameController
}
/**
* Called when the server deals the client a new hand of cards. Default
* implementation does nothing.
* Called when the server deals the client a new hand of cards. Default implementation does
* nothing.
*
* @param hand the hand dealt to the user
*/
@@ -89,8 +86,8 @@ public abstract class CardGameController extends GameController
{}
/**
* Dispatched to the client when it has received a set of cards
* from another player. Default implementation does nothing.
* Dispatched to the client when it has received a set of cards from another player. Default
* implementation does nothing.
*
* @param plidx the index of the player providing the cards
* @param cards the cards received
@@ -99,9 +96,8 @@ public abstract class CardGameController extends GameController
{}
/**
* Dispatched to the client when the server has forced it to send
* a set of cards to another player. Default implementation does
* nothing.
* Dispatched to the client when the server has forced it to send a set of cards to another
* player. Default implementation does nothing.
*
* @param plidx the index of the player to which the cards were sent
* @param cards the cards sent
@@ -110,8 +106,8 @@ public abstract class CardGameController extends GameController
{}
/**
* Dispatched to the client when a set of cards is transferred between
* two other players in the game. Default implementation does nothing.
* Dispatched to the client when a set of cards is transferred between two other players in
* the game. Default implementation does nothing.
*
* @param fromidx the index of the player sending the cards
* @param toidx the index of the player receiving the cards
@@ -48,8 +48,8 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
}
/**
* Returns the value of the card, either from 2 to 11 or
* KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER.
* Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or
* BLACK_JOKER.
*
* @return the value of the card
*/
@@ -59,8 +59,8 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
}
/**
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or
* CLUBS. If the card is the joker, the suit is undefined.
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS. If the card is the joker,
* the suit is undefined.
*
* @return the suit of the card
*/
@@ -116,8 +116,8 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
}
/**
* Checks whether or not this card is valid. The no-arg public
* constructor for deserialization creates an invalid card.
* Checks whether or not this card is valid. The no-arg public constructor for deserialization
* creates an invalid card.
*
* @return true if this card is valid, false if not
*/
@@ -158,14 +158,13 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
}
/**
* Compares this card to another. The card order is the same as the
* initial deck ordering: two through ten, jack, queen, king, ace for
* spades, hearts, clubs, and diamonds, then the red joker and the
* black joker.
* Compares this card to another. The card order is the same as the initial deck ordering: two
* through ten, jack, queen, king, ace for spades, hearts, clubs, and diamonds, then the red
* joker and the black joker.
*
* @param other the other card to compare this to
* @return -1, 0, or +1, depending on whether this card is less than,
* equal to, or greater than the other card
* @return -1, 0, or +1, depending on whether this card is less than, equal to, or greater
* than the other card
*/
public int compareTo (Card other)
{
@@ -36,8 +36,8 @@ import com.threerings.parlor.game.server.GameManager;
import com.threerings.parlor.turn.server.TurnGameManager;
/**
* A manager class for card games. Handles common functions like dealing
* hands of cards to all players.
* A manager class for card games. Handles common functions like dealing hands of cards to all
* players.
*/
public class CardGameManager extends GameManager
implements TurnGameManager, CardCodes
@@ -72,9 +72,8 @@ public class CardGameManager extends GameManager
}
/**
* This should be called to start a rematched game. It just starts the
* current game anew, but provides a mechanism for derived classes to
* do special things when there is a rematch.
* This should be called to start a rematched game. It just starts the current game anew, but
* provides a mechanism for derived classes to do special things when there is a rematch.
*/
public void rematchGame ()
{
@@ -86,10 +85,9 @@ public class CardGameManager extends GameManager
}
/**
* Derived classes can override this method and take any action needed
* prior to a game rematch. If the rematch needs to be vetoed for any
* reason, they can return false from this method and the rematch will
* be aborted.
* Derived classes can override this method and take any action needed prior to a game
* rematch. If the rematch needs to be vetoed for any reason, they can return false from this
* method and the rematch will be aborted.
*/
protected boolean gameWillRematch ()
{
@@ -97,14 +95,13 @@ public class CardGameManager extends GameManager
}
/**
* Deals a hand of cards to the player at the specified index from
* the given Deck.
* Deals a hand of cards to the player at the specified index from the given Deck.
*
* @param deck the deck from which to deal
* @param size the size of the hand to deal
* @param playerIndex the index of the target player
* @return the hand dealt to the player, or null if the deal
* was canceled because the deck did not contain enough cards
* @return the hand dealt to the player, or null if the deal was canceled because the deck did
* not contain enough cards
*/
public Hand dealHand (Deck deck, int size, int playerIndex)
{
@@ -124,14 +121,12 @@ public class CardGameManager extends GameManager
}
/**
* Deals a hand of cards to each player from the specified
* Deck.
* Deals a hand of cards to each player from the specified Deck.
*
* @param deck the deck from which to deal
* @param size the size of the hands to deal
* @return the array of hands dealt to each player, or null if
* the deal was canceled because the deck did not contain enough
* cards
* @return the array of hands dealt to each player, or null if the deal was canceled because
* the deck did not contain enough cards
*/
public Hand[] dealHands (Deck deck, int size)
{
@@ -150,10 +145,8 @@ public class CardGameManager extends GameManager
}
/**
* Gets the player index of the specified client object, or -1
* if the client object does not represent a player. If the game has ended,
* looks through the players of the now-ended game.
*
* Gets the player index of the specified client object, or -1 if the client object does not
* represent a player. If the game has ended, looks through the players of the now-ended game.
*/
public int getPlayerIndex (ClientObject client)
{
@@ -169,8 +162,8 @@ public class CardGameManager extends GameManager
}
/**
* Returns the client object corresponding to the specified player index,
* or null if the position is not occupied by a player.
* Returns the client object corresponding to the specified player index, or null if the
* position is not occupied by a player.
*/
public ClientObject getClientObject (int pidx)
{
@@ -211,34 +204,30 @@ public class CardGameManager extends GameManager
}
/**
* Sends sets of cards between players simultaneously. Each player is
* guaranteed to receive the notification of cards received after the
* notification of cards sent. The length of the arrays passed must
* be equal to the player count.
* Sends sets of cards between players simultaneously. Each player is guaranteed to receive
* the notification of cards received after the notification of cards sent. The length of the
* arrays passed must be equal to the player count.
*
* @param toPlayerIndices for each player, the index of the player to
* transfer cards to
* @param toPlayerIndices for each player, the index of the player to transfer cards to
* @param cards for each player, the cards to transfer
*/
public void transferCardsBetweenPlayers (int[] toPlayerIndices,
Card[][] cards)
public void transferCardsBetweenPlayers (int[] toPlayerIndices, Card[][] cards)
{
// Send all removal notices
for (int i = 0; i < _playerCount; i++) {
ClientObject fromClient = getClientObject(i);
for (int ii = 0; ii < _playerCount; ii++) {
ClientObject fromClient = getClientObject(ii);
if (fromClient != null) {
CardGameSender.sentCardsToPlayer(fromClient,
toPlayerIndices[i], cards[i]);
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIndices[ii], cards[ii]);
}
}
// Send all addition notices and notify everyone else
for (int i = 0; i < _playerCount; i++) {
ClientObject toClient = getClientObject(toPlayerIndices[i]);
for (int ii = 0; ii < _playerCount; ii++) {
ClientObject toClient = getClientObject(toPlayerIndices[ii]);
if (toClient != null) {
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]);
CardGameSender.sendCardsFromPlayer(toClient, ii, cards[ii]);
}
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
notifyCardsTransferred(ii, toPlayerIndices[ii], cards[ii].length);
}
}
@@ -250,8 +239,8 @@ public class CardGameManager extends GameManager
* @param toPlayerIdx the index of the player receiving the cards
* @param cards the number of cards sent
*/
protected void notifyCardsTransferred (final int fromPlayerIdx,
final int toPlayerIdx, final int cards)
protected void notifyCardsTransferred (
final int fromPlayerIdx, final int toPlayerIdx, final int cards)
{
final int senderOid = _playerOids[fromPlayerIdx],
receiverOid = _playerOids[toPlayerIdx];
@@ -25,8 +25,7 @@ import com.threerings.parlor.card.client.CardGameController;
import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
/**
* A card game controller delegate for trick-based card games, such as
* Spades and Hearts.
* A card game controller delegate for trick-based card games, such as Spades and Hearts.
*/
public class TrickCardGameControllerDelegate
extends TurnGameControllerDelegate
@@ -36,8 +35,7 @@ public class TrickCardGameControllerDelegate
*
* @param controller the game controller
*/
public TrickCardGameControllerDelegate (CardGameController
controller)
public TrickCardGameControllerDelegate (CardGameController controller)
{
super(controller);
_cgctrl = controller;
@@ -28,8 +28,6 @@ import java.util.List;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.Interval;
import com.samskivert.util.RandomUtil;
import com.samskivert.util.StringUtil;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
@@ -215,15 +213,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure they're actually a player
int fromidx = _cgmgr.getPlayerIndex(client);
if (fromidx == -1) {
log.warning("Send request from non-player [username=" +
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
log.warning("Send request from non-player",
"username", ((BodyObject)client).who(), "cards", cards);
return;
}
// make sure they have the cards
if (!_hands[fromidx].containsAll(cards)) {
log.warning("Tried to send cards not held [username=" +
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
log.warning("Tried to send cards not held",
"username", ((BodyObject)client).who(), "cards", cards);
return;
}
@@ -253,15 +251,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure their hand contains the specified card
if (!_hands[pidx].contains(card)) {
log.warning("Tried to play card not held [username=" + username +
", card=" + card + "].");
log.warning("Tried to play card not held", "username", username, "card", card);
return;
}
// make sure the card is legal to play
if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) {
log.warning("Tried to play illegal card [username=" + username +
", card=" + card + "].");
log.warning("Tried to play illegal card", "username", username, "card", card);
return;
}
@@ -281,14 +277,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure the requester is one of the players
int pidx = _cgmgr.getPlayerIndex(client);
if (pidx == -1) {
log.warning("Rematch request from non-player [username=" +
((BodyObject)client).who() + "].");
log.warning("Rematch request from non-player", "username", ((BodyObject)client).who());
return;
}
// make sure the player hasn't already requested
if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) {
log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "].");
log.warning("Repeated rematch request", "username", ((BodyObject)client).who());
return;
}
@@ -361,8 +356,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
{
int[] rematchRequests = _trickCardGame.getRematchRequests();
int count = 0;
for (int i = 0; i < rematchRequests.length; i++) {
if (rematchRequests[i] != TrickCardGameObject.NO_REQUEST) {
for (int rematchRequest : rematchRequests) {
if (rematchRequest != TrickCardGameObject.NO_REQUEST) {
count++;
}
}
@@ -562,8 +557,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
*/
protected boolean anyHandsEmpty ()
{
for (int i = 0; i < _hands.length; i++) {
if (_hands[i].isEmpty()) {
for (Hand _hand : _hands) {
if (_hand.isEmpty()) {
return true;
}
}
@@ -33,8 +33,7 @@ public class TrickCardGameUtil
implements TrickCardCodes
{
/**
* For four-player games with fixed partnerships, this returns the index
* of the player's team.
* For four-player games with fixed partnerships, this returns the index of the player's team.
*
* @param pidx the player index
*/
@@ -44,8 +43,7 @@ public class TrickCardGameUtil
}
/**
* For four-player games with fixed partnerships, this returns the index
* of the other team.
* For four-player games with fixed partnerships, this returns the index of the other team.
*
* @param tidx the index of the team
*/
@@ -55,8 +53,8 @@ public class TrickCardGameUtil
}
/**
* For four-player games with fixed partnerships, this returns the index
* of the player's partner.
* For four-player games with fixed partnerships, this returns the index of the player's
* partner.
*/
public static int getPartnerIndex (int pidx)
{
@@ -64,8 +62,8 @@ public class TrickCardGameUtil
}
/**
* For four-player games with fixed partnerships, this returns the index
* of one of the members of a team.
* For four-player games with fixed partnerships, this returns the index of one of the members
* of a team.
*
* @param tidx the index of the team
* @param midx the index of the player within the team
@@ -76,8 +74,8 @@ public class TrickCardGameUtil
}
/**
* For four-player games, this returns the index of the player after the
* specified player going clockwise around the table.
* For four-player games, this returns the index of the player after the specified player
* going clockwise around the table.
*/
public static int getNextInClockwiseSequence (int pidx)
{
@@ -88,8 +86,8 @@ public class TrickCardGameUtil
}
/**
* For four-player games with fixed partnerships, this returns the
* relative location of one player from the point of view of another.
* For four-player games with fixed partnerships, this returns the relative location of one
* player from the point of view of another.
*
* @param pidx1 the index of the player to whom the location is relative
* @param pidx2 the index of the player whose location is desired
@@ -101,8 +99,7 @@ public class TrickCardGameUtil
}
/**
* For four-player games, returns the index of the player to the left of
* the specified player.
* For four-player games, returns the index of the player to the left of the specified player.
*/
public static int getLeftIndex (int pidx)
{
@@ -110,8 +107,8 @@ public class TrickCardGameUtil
}
/**
* For four-player games, returns the index of the player to the right of
* the specified player.
* For four-player games, returns the index of the player to the right of the specified
* player.
*/
public static int getRightIndex (int pidx)
{
@@ -119,8 +116,7 @@ public class TrickCardGameUtil
}
/**
* For four-player games, returns the index of the player across from the
* specified player.
* For four-player games, returns the index of the player across from the specified player.
*/
public static int getOppositeIndex (int pidx)
{
@@ -140,8 +136,8 @@ public class TrickCardGameUtil
*/
public static boolean containsCard (PlayerCard[] cards, Card card)
{
for (int i = 0; i < cards.length; i++) {
if (cards[i].card.equals(card)) {
for (PlayerCard pc : cards) {
if (pc.card.equals(card)) {
return true;
}
}
@@ -149,14 +145,13 @@ public class TrickCardGameUtil
}
/**
* Determines the number of cards that belong to the specified suit within
* the array given.
* Determines the number of cards that belong to the specified suit within the array given.
*/
public static int countSuitMembers (PlayerCard[] cards, int suit)
{
int count = 0;
for (int i = 0; i < cards.length; i++) {
if (cards[i].card.getSuit() == suit) {
for (PlayerCard pc : cards) {
if (pc.card.getSuit() == suit) {
count++;
}
}
@@ -172,21 +167,19 @@ public class TrickCardGameUtil
}
/**
* Returns the highest card (according to the standard A,K,...,2 ordering)
* in the suit lead, with an optional trump suit.
* Returns the highest card (according to the standard A,K,...,2 ordering) in the suit lead,
* with an optional trump suit.
*
* @param trumpSuit the trump suit, or -1 for none
*/
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed,
int trumpSuit)
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed, int trumpSuit)
{
PlayerCard highest = cardsPlayed[0];
for (int i = 1; i < cardsPlayed.length; i++) {
PlayerCard other = cardsPlayed[i];
if ((other.card.getSuit() == highest.card.getSuit() &&
other.card.compareTo(highest.card) > 0) ||
(other.card.getSuit() == trumpSuit &&
highest.card.getSuit() != trumpSuit)) {
(other.card.getSuit() == trumpSuit && highest.card.getSuit() != trumpSuit)) {
highest = other;
}
}