au.com.solidsoftware.multimahjong.mmc.game
Class Payout

java.lang.Object
  |
  +--au.com.solidsoftware.multimahjong.mmc.game.Payout

public class Payout
extends java.lang.Object

The Payout class is used for two purposes. Namely:

1) At the end of a hand the handlePayout method is used to determine how much the winning player's hand scores and how much all losing players must payout to the winner. 2) The handleScoring method will calculate the score of a given hand, thus the Payout class can also be used to compare the scores of different combinations of hands.

Author:
Joel Brakey
See Also:
PayoutInfo, PayoutGUI, Game

Field Summary
static int ALL_HONOUR
          ALL_HONOUR is an element of the doubleFlags array.
private static int ALL_KONG
          ALL_KONG is a symbolic constant for a position in the boolean array checkSpecial.
private static int ALL_WINDS_AND_DRAGS
          ALL_WINDS_AND_DRAGS is a symbolic constant for a position in the boolean array checkSpecial.
static int AT_LEAST_DOUBLE
          AT_LEAST_DOUBLE is an element of the doubleFlags array.
private  boolean[] checkSpecial
          Used to determine whether the hand is a special hand.
static int CHOWS
          CHOWS is a symbolic constant for a position in the array of ints doubleInfo.
static int CLEAN
          CLEAN is an element of the doubleFlags array.
static int CONC_OTHER_SETS
          CONC_OTHER_SETS is a symbolic constant for an element in the array of ints groundInfo.
static int CONC_SIMPLE_SETS
          CONC_SIMPLE_SETS is a symbolic constant for an element in the array of ints groundInfo.
static int CONCEALED_MAHJONG
          CONCEALED_MAHJONG is an element of the gameDoubleFlags array.
(package private)  Tile[] concealedHand
          Stores all of the Winner's concealed Sets of tiles.
(package private)  int[] consecutiveChows
          Used in determining whether the hand has 3 consecutive chows, thus earning an extra double if it's an ordinary suit hand.
static int DISCARD
          DISCARD indicates the LAST_PICKUP was from the discard of another player.
(package private)  int discardersPos
          The position of the discarding player (if there was one) in the playerNames and playerWinds arrays.
static int DOUBLE_SUIT
          DOUBLE_SUIT is a symbolic constant for a position in the array of ints doubleInfo.
(package private)  boolean[] doubleFlags
          Used to determine what doubles apply to the hand if it's an Ordinary Suit hand.
(package private)  int[] doubleInfo
          Used to store information required in determining what doubles apply to the hand if it's found to be an Ordinary Suit Hand by the Payout class (in the handleScoring method).
static int DRAGON_PAIR
          DRAGON_PAIR is a state which EXTRA_PAIR in the groundInfo array can take.
static int DRAGON_SETS
          DRAGON_SETS is a symbolic constant for a position in the array of ints doubleInfo.
static int EARTHS_GRACE
          A symbolic constant for one of the values which the private integer specialHand can take.
static int EXP_DOUBLE_SETS
          EXP_DOUBLE_SETS is a symbolic constant for a position in the array of ints doubleInfo.
static int EXP_OTHER_SETS
          EXP_OTHER_SETS is a symbolic constant for an element in the array of ints groundInfo.
static int EXP_SIMPLE_SETS
          EXP_SIMPLE_SETS is a symbolic constant for an element in the array of ints groundInfo.
static int EXTRA_PAIR
          EXTRA_PAIR is a symbolic constant for an element in the array of ints groundInfo.
static int FIRST_DISCARD_BONUS
          FIRST_DISCARD_BONUS is an element of the gameDoubleFlags array.
private static int FOUR_BIG_WINDS
          FOUR_BIG_WINDS is a symbolic constant for a position in the boolean array checkSpecial.
private static int FOUR_LITTLE_WINDS
          FOUR_LITTLE_WINDS is a symbolic constant for a position in the boolean array checkSpecial.
(package private)  boolean[] gameDoubleFlags
          Stores information supplied by the Game required for calculating the score of the hand.
(package private)  int[] gameInfo
          Stores information supplied by the Game required for calculating the score of the hand.
static int GATES_OF_HEAVEN
          A symbolic constant for one of the values which the private integerspecialHand can take.
static int GROUND_CM_BONUS
          GROUND_CM_BONUS is an element of the doubleFlags array.
(package private)  int[] groundInfo
          Used to gather Ground Score Information for an Ordinary Suit Hand.
private static int HEADS_AND_TAILS
          HEADS_AND_TAILS is a symbolic constant for a position in the boolean array checkSpecial.
static int HEAVENS_GRACE
          A symbolic constant for one of the values which the private integer specialHand can take.
private static int IMPERIAL_JADE
          IMPERIAL_JADE is a symbolic constant for a position in the boolean array checkSpecial.
private static int IS_CONS_CHOW
          IS_CONS_CHOW is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_GREEN_DRAGON
          IS_GREEN_DRAGON is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_GREEN_TILE
          IS_GREEN_TILE is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_HONOUR
          IS_HONOUR is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_NORMAL_WIND
          IS_NORMAL_WIND is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_SPEC_WIND
          IS_SPEC_WIND is a symbolic constant used to reflect a check which the checkSet methods makes.
private static int IS_TERMINAL
          IS_TERMINAL is a symbolic constant used to reflect a check which the checkSet methods makes.
static int LAST_DISCARD
          LAST_DISCARD indicates the LAST_PICKUP was the last discard possible in the Hand.
static int LAST_PICKUP
          LAST_PICKUP is an element of the gameInfo array.
static int LAST_TILE
          LAST_TILE indicates the LAST_PICKUP was the last tile in the Honour Wall.
(package private)  Tile lastTile
          Used to store the last tile of the hand, ie the tile the winner went Mahjong with.
static int LIMIT
          LIMIT is an element of the gameInfo array.
static int LOOSE_TILE
          LOOSE_TILE indicates the LAST_PICKUP was one of the loose tiles in the Dead Wall.
static int MAX_CONCEALED
          The maximum number of concealed sets a player can have.
static int MAX_EXPOSED
          The maximum number of exposed sets a player can have.
private static int MIXED_PUNG
          MIXED_PUNG is a symbolic constant for a position in the boolean array checkSpecial.
static int MOON
          A symbolic constant for one of the values which the private integer specialHand can take.
static int NONE
          A symbolic constant for one of the values which the private integer specialHand can take.
static int NORM_WIND_SETS
          NORM_WIND_SETS is a symbolic constant for a position in the array of ints doubleInfo.
static int ONE_CHANCE_HAND
          ONE_CHANCE_HAND is an element of the doubleFlags array.
(package private)  int[] payout
          Holds how much each player has to payout.
static int PAYOUT_SIZE
          PAYOUT_SIZE is the size of the payout array.
(package private)  PayoutInfo payoutData
          The object sed to convert the data generated by Payout into what is to be output by the PayoutGUI class.
(package private)  java.lang.String[] playerNames
          Lists the names of all four players in the Game.
(package private)  int[] playerWinds
          Lists the winds of all four players in the Game.
static int PLUM_BLOSSOM
          A symbolic constant for one of the values which the private integer specialHand can take.
static int PURITY
          PURITY is an element of the doubleFlags array.
static int REQ_CON_CHOWS
          REQ_CON_CHOWS is the value of how many consecutive chows are required in order to gain one extra double if the player has an Ordinary Suit Hand.
static int ROBBED_KONG
          ROBBED_KONG indicates the LAST_PICKUP was from Robbing the Kong.
(package private)  int score
          Holds the score of the winning player's hand.
static int SIMPLES
          SIMPLES is an element of the doubleFlags array.
static int SPEC_WIND_SETS
          SPEC_WIND_SETS is a symbolic constant for a position in the array of ints doubleInfo.
(package private)  int specialHand
          Indicates whether the player has formed a special hand.
static int STANDING_HAND
          STANDING_HAND is an element of the gameDoubleFlags array.
private static int THREE_GREAT_SCHOLARS
          THREE_GREAT_SCHOLARS is a symbolic constant for a position in the boolean array checkSpecial.
static int UNIQUE_WONDER
          A symbolic constant for one of the values which the private integer specialHand can take.
static int WALL
          WALL indicates the LAST_PICKUP was from The Wall.
static int WIN_WIND_PAIR
          WIN_WIND_PAIR is a state which EXTRA_PAIR in the groundInfo array can take.
(package private)  int winnersPos
          The position of the discarding player (if there was one) in the playerNames and playerWinds arrays.
static int WOR
          WOR is an element of the gameInfo array.
static int WOR_PAIR
          WOR_PAIR is a state which EXTRA_PAIR in the groundInfo array can take.
static int WRIGGLY_SNAKE
          A symbolic constant for one of the values which the private integer specialHand can take.
 
Constructor Summary
Payout()
          Resets all scoring and payout variables by calling the resetPayOutData and initialiseScoreData methods.
 
Method Summary
private  void applyDoubles(Set[] exposedSets)
          Determines and applies relevant doubles to the ground score of the ordinary suit hand.
private  void applyExtraPoints()
          Applies relevant extra points to the ground score of the ordinary suit hand.
private  void calcFinalScore(Set[] exposedSets)
          Using all information gathered from the methods which examine sets contained in the players hand (scoreExposedSets, scoreConcealedSets and all worker methods of these two methods) calcFinalScore is used to determine whether the player has won with a special hand or ordinary suit hand.
private  boolean checkSet(Set anySet, int checkID)
          Checks if a given set meets a given check ID.
private  void handleChows(Set anySet)
          Gather the scoring details from a Chow.
private  void handleKongOrPung(Set anySet, int baseNumber, boolean isConc)
          Gather the scoring details from a concealed Kong or Pung.
private  void handleOneChanceHand(Set anySet)
          Checks whether the player won with a One Chance Hand.
private  void handlePair(Set anySet)
          Gather the scoring details from a Pair.
 void handlePayout(Set[] concealedSet, Set[] exposedSet, Game gameReference)
          The handlePayout method is called once a hand has been completed, ie a player has gone Mahjong.
 int handleScoring(Set[] concealedSets, Set[] exposedSets)
          handleScoring first sets all scoring information which the Payout class determines internally to the required initial values by invoking the initialiseScoreData method.
private  void initialiseScoreData()
          The initialiseScoreData method sets all variables used by the Payout class to their required initial values.
 void resetPayOutData()
          Resets all variables need in calculating the payout to the winner.
private  void scoreConcealedSets(Set[] concealedSets)
          Uses the hand's concealed sets to gather the scoring details for the concealed sets in a player's hand.
private  void scoreExposedSets(Set[] exposedSets)
          Uses the hand's exposed sets to gather the scoring details for the exposed sets in a player's hand.
private  void scoreIfEasySpecial()
          scoreIfEasySpecial checks firstly whether any of the unusual special hands have been set and then makes trivial checks to see if the given hand is one of 2 other special hands. The unusual special hands are set by the Game because they can only be checked for there.
 void setConcealedMahjong()
          Sets that the player won with a concealed mahjong.
 void setEarthsGrace()
          Sets that the hand is an Earths Grace
 void setFirstDiscardBonus(boolean bonusVal)
          Sets that the player earnt a first discard bonus by punging/konging the first discard made by the east wind player at the start of the hand.
 void setGameLimit(int limit)
          Sets the limit for the hand.
 void setGatesOfHeaven(Tile[] concealedHand)
          Sets that the hand is a Gates of Heaven Hand.
 void setHeavensGrace()
          Sets that the hand is a Heaven's Grace Special Hand.
 void setLastPickUp(int lastPickupID)
          Sets the the ID of where the last pickup occurred in the game.
 void setLastTile(Tile finalTile)
          Sets what the last tile to be picked up by the winner was.
 void setPlayerInfo(java.lang.String[] thePlayerNames, int[] thePlayerWinds, int theWinnersPos, int theDiscardersPos)
          Sets the info relating to all players.
private  void setSpecialDoubles(Set anySet)
          Toggles doubleFlags boolean values depending on whether or not the hand satisfies any of the doubles of an Ordinary Suit Hand.
 void setStandingHand()
          Sets the fact that the player won with a standing hand.
 void setUniqueWonder(Tile[] concealedHand)
          Sets that the hand is a Unique Wonder Special Hand.
 void setWOR(int windID)
          Sets the current wind of the round.
 void setWrigglySnake(Tile[] concealedHand)
          Sets that the hand is a Wriggly Snake Hand
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
A symbolic constant for one of the values which the private integer specialHand can take. NONE indicates that the winner hasn't won with a special hand. NONE is also used as a symbolic constant to reflect that the DOUBLE_SUIT element of the doubleInfo array hasn't yet been assigned a suit value.

UNIQUE_WONDER

public static final int UNIQUE_WONDER
A symbolic constant for one of the values which the private integer specialHand can take. UNIQUE_WONDER indicates that the player has won with a Unique Wonder. As only the Game can check whether the player has a Unique Wonder it is a public int.

HEAVENS_GRACE

public static final int HEAVENS_GRACE
A symbolic constant for one of the values which the private integer specialHand can take. HEAVENS_GRACE indicates that the player has won with a Heaven's Grace. As only the Game can check whether the player has a Heaven's Grace it is a public int.

GATES_OF_HEAVEN

public static final int GATES_OF_HEAVEN
A symbolic constant for one of the values which the private integerspecialHand can take. GATES_OF_HEAVEN indicates that the player has won with a Gates of Heaven (or Nine Gates) hand. As only the Game can check whether the player has a Gates of Heaven hand it is a public int.

WRIGGLY_SNAKE

public static final int WRIGGLY_SNAKE
A symbolic constant for one of the values which the private integer specialHand can take. WRIGGLY_SNAKE indicates that the player has won with a Wriggly Snake hand. As only the Game can check whether the player has a Wriggly Snake hand it is a public int.

EARTHS_GRACE

public static final int EARTHS_GRACE
A symbolic constant for one of the values which the private integer specialHand can take. EARTHS_GRACE indicates that the player has won with an Earth's Grace. As only the Game can check whether the player has an Earth's Grace it's a public int.

PLUM_BLOSSOM

public static final int PLUM_BLOSSOM
A symbolic constant for one of the values which the private integer specialHand can take. PLUM_BLOSSOM indicates whether the player has Plucked the Plum Blossom from the Roof. As only the Game can check whether the player has managed to do this it is a public int.

MOON

public static final int MOON
A symbolic constant for one of the values which the private integer specialHand can take. MOON indicates that the player has Picked the Moon from the Bottom of the Sea. As only the Game can check whether the player has managed to do this it is a public int.

IMPERIAL_JADE

private static final int IMPERIAL_JADE
IMPERIAL_JADE is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with an Imperial Jade special hand.

ALL_KONG

private static final int ALL_KONG
ALL_KONG is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with an All Kong special hand.

ALL_WINDS_AND_DRAGS

private static final int ALL_WINDS_AND_DRAGS
ALL_WINDS_AND_DRAGS is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with an All Winds and Dragons special hand.

HEADS_AND_TAILS

private static final int HEADS_AND_TAILS
HEADS_AND_TAILS is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with a Heads and Tails special hand.

MIXED_PUNG

private static final int MIXED_PUNG
MIXED_PUNG is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with a Mixed Pung special hand.

FOUR_BIG_WINDS

private static final int FOUR_BIG_WINDS
FOUR_BIG_WINDS is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with a Four Big Winds special hand.

FOUR_LITTLE_WINDS

private static final int FOUR_LITTLE_WINDS
FOUR_LITTLE_WINDS is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with a Four Little Winds special hand.

THREE_GREAT_SCHOLARS

private static final int THREE_GREAT_SCHOLARS
THREE_GREAT_SCHOLARS is a symbolic constant for a position in the boolean array checkSpecial. It reflects whether the player was won with a Three Great Scholars special hand.

DOUBLE_SUIT

public static final int DOUBLE_SUIT
DOUBLE_SUIT is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the suit of the first Set that Payout uses in its calculations. This then makes it possible to determine whether the player has a Clean or Purity Hand which are booleans in the array.

CHOWS

public static final int CHOWS
CHOWS is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the number of Chows the player has in their hand. Thus it can be determined whether the player earns 1 double for either a non scoring hand, ie a hand with only Chows and a pair, or for a hand with no Chows.

DRAGON_SETS

public static final int DRAGON_SETS
DRAGON_SETS is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the number of Pungs/Kongs of Dragons which the player has in their hand.

SPEC_WIND_SETS

public static final int SPEC_WIND_SETS
SPEC_WIND_SETS is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the number of Pungs/Kongs of Special Winds, ie the Wind of the Round or Winner's Wind, which the player has in their hand.

NORM_WIND_SETS

public static final int NORM_WIND_SETS
NORM_WIND_SETS is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the number of Pungs/Kongs of Normal Winds, ie not the Wind of the Round or Winner's Wind. Kongs/Pungs of Normal Winds don't earn any doubles in an Ordinary Suit Hand.

EXP_DOUBLE_SETS

public static final int EXP_DOUBLE_SETS
EXP_DOUBLE_SETS is a symbolic constant for a position in the array of ints doubleInfo. It is used to hold the number of exposed Pungs/Kongs the player has. It's used to check whether the player has 3 exposed Kongs/Pungs, because if they do and also have an Ordinary Suit Hand they earn one extra double.

CONC_SIMPLE_SETS

public static final int CONC_SIMPLE_SETS
CONC_SIMPLE_SETS is a symbolic constant for an element in the array of ints groundInfo. It keeps track of the amount of points the player has scored for concealed Kongs and Pungs of Simple tiles, ie tiles 2-8 in any suit. This is part of the Ground Score information of the player's hand (if they have an Ordinary Suit Hand).

EXP_SIMPLE_SETS

public static final int EXP_SIMPLE_SETS
EXP_SIMPLE_SETS is a symbolic constant for an element in the array of ints groundInfo. It keeps track of the amount of points the player has scored for exposed Kongs and Pungs of Simple tiles, ie tiles 2-8 in any suit. This is part of the Ground Score information of the player's hand (if they have an Ordinary Suit Hand).

CONC_OTHER_SETS

public static final int CONC_OTHER_SETS
CONC_OTHER_SETS is a symbolic constant for an element in the array of ints groundInfo. It keeps track of the amount of points the player has scored for concealed Kongs and Pungs of all other tiles besides Simple tiles, ie Terminal and Honour tiles. This is part of the Ground Score information of the player's hand (if they have an Ordinary Suit Hand).

EXP_OTHER_SETS

public static final int EXP_OTHER_SETS
EXP_OTHER_SETS is a symbolic constant for an element in the array of ints groundInfo. It keeps track of the amount of points the player has scored for exposed Kongs and Pungs of all other tiles besides Simple tiles, ie Terminal and Honour tiles. This is part of the Ground Score information of the player's hand (if they have an Ordinary Suit Hand).

EXTRA_PAIR

public static final int EXTRA_PAIR
EXTRA_PAIR is a symbolic constant for an element in the array of ints groundInfo. It keeps track of whether the player has a pair that adds extra points to the ground score.

DRAGON_PAIR

public static final int DRAGON_PAIR
DRAGON_PAIR is a state which EXTRA_PAIR in the groundInfo array can take. It indicates that the player has a pair of dragons.

WIN_WIND_PAIR

public static final int WIN_WIND_PAIR
WIN_WIND_PAIR is a state which EXTRA_PAIR in the groundInfo array can take. It indicates that the player has a pair of the Winner's wind.

WOR_PAIR

public static final int WOR_PAIR
WOR_PAIR is a state which EXTRA_PAIR in the groundInfo array can take. It indicates whether the player has a pair of the Wind of the Round's wind.

SIMPLES

public static final int SIMPLES
SIMPLES is an element of the doubleFlags array. It indicates whether the hand is comprised entirely of Simple tiles, thus earning 1 double if the player has an Ordinary Suit Hand.

CLEAN

public static final int CLEAN
CLEAN is an element of the doubleFlags array. It indicates whether the player has a clean hand, ie the hand contains only sets from the same suit with/without honour tiles. A clean hand gives 1 extra double if the player has an Ordinary Suit Hand.

PURITY

public static final int PURITY
PURITY is an element of the doubleFlags array. It indicates whether the player has a purity hand, thus giving 3 doubles.

ALL_HONOUR

public static final int ALL_HONOUR
ALL_HONOUR is an element of the doubleFlags array. It indicates whether the player has an all honour hand, which gives 3 doubles.

AT_LEAST_DOUBLE

public static final int AT_LEAST_DOUBLE
AT_LEAST_DOUBLE is an element of the doubleFlags array. It indicates whether the player has a hand in which every set contains at least one honour/terminal tile. If the player has an Ordinary Suit Hand they earn an extra double for this.

GROUND_CM_BONUS

public static final int GROUND_CM_BONUS
GROUND_CM_BONUS is an element of the doubleFlags array. It indicates whether the player has a earnt an extra 10 points to their Ground Score for completing a Concealed Mahjong with a discard.

ONE_CHANCE_HAND

public static final int ONE_CHANCE_HAND
ONE_CHANCE_HAND is an element of the doubleFlags array. It indicates whether the player has a One Chance Hand, ie they complete their hand with a pair, they complete their hand in the middle of a Chow or they complete their hand at the inside end of a terminal Chow. Thus 2 points are added to a player's ground score if they have a One Chance Hand.

STANDING_HAND

public static final int STANDING_HAND
STANDING_HAND is an element of the gameDoubleFlags array. It indicates whether the player has won with a Standing Hand (adding 100 points to the Ground Score).

FIRST_DISCARD_BONUS

public static final int FIRST_DISCARD_BONUS
FIRST_DISCARD_BONUS is an element of the gameDoubleFlags array. It indicates whether the player has Punged/Konged the first discard made by east at the beginning of a hand.

CONCEALED_MAHJONG

public static final int CONCEALED_MAHJONG
CONCEALED_MAHJONG is an element of the gameDoubleFlags array. It indicates whether the playerhas one with a Concealed Mahjong. Game has to checkfor this because a Concealed Mahjong can include one exposed set if it was made exposed by picking up the last discard.

LAST_PICKUP

public static final int LAST_PICKUP
LAST_PICKUP is an element of the gameInfo array. It indicates where the winning player made their last pickup from in order to go Mahjong.

WOR

public static final int WOR
WOR is an element of the gameInfo array. It indicates the wind of the round.

LIMIT

public static final int LIMIT
LIMIT is an element of the gameInfo array. It indicates the limit of the hand.

WALL

public static final int WALL
WALL indicates the LAST_PICKUP was from The Wall.

DISCARD

public static final int DISCARD
DISCARD indicates the LAST_PICKUP was from the discard of another player.

LOOSE_TILE

public static final int LOOSE_TILE
LOOSE_TILE indicates the LAST_PICKUP was one of the loose tiles in the Dead Wall.

ROBBED_KONG

public static final int ROBBED_KONG
ROBBED_KONG indicates the LAST_PICKUP was from Robbing the Kong.

LAST_DISCARD

public static final int LAST_DISCARD
LAST_DISCARD indicates the LAST_PICKUP was the last discard possible in the Hand.

LAST_TILE

public static final int LAST_TILE
LAST_TILE indicates the LAST_PICKUP was the last tile in the Honour Wall.

IS_SPEC_WIND

private static final int IS_SPEC_WIND
IS_SPEC_WIND is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is the Wind of the Round's wind or the Winner's Wind.

IS_NORMAL_WIND

private static final int IS_NORMAL_WIND
IS_NORMAL_WIND is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is one of the winds besides both the Wind of the Round's wind and the Winner's Wind.

IS_HONOUR

private static final int IS_HONOUR
IS_HONOUR is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is a set of Honour tiles.

IS_TERMINAL

private static final int IS_TERMINAL
IS_TERMINAL is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is a set of Terminal tiles.

IS_CONS_CHOW

private static final int IS_CONS_CHOW
IS_CONS_CHOW is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set could contribute to the player having 3 consecutive chows.

IS_GREEN_DRAGON

private static final int IS_GREEN_DRAGON
IS_GREEN_DRAGON is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is a Kong/Pung of Green Dragon tiles.

IS_GREEN_TILE

private static final int IS_GREEN_TILE
IS_GREEN_TILE is a symbolic constant used to reflect a check which the checkSet methods makes. The check is to see whether the set is a "Green" tile set, ie a 2,3,4,6 or 8 of Bamboo set.

REQ_CON_CHOWS

public static final int REQ_CON_CHOWS
REQ_CON_CHOWS is the value of how many consecutive chows are required in order to gain one extra double if the player has an Ordinary Suit Hand.

PAYOUT_SIZE

public static final int PAYOUT_SIZE
PAYOUT_SIZE is the size of the payout array. The size is equal to the number of players + 1. The extra one is required to accomodate the constants defined in the Tile class. As the NORTH constant in the Tile class has a value of 4 an extra element is required in the payout array.

MAX_EXPOSED

public static final int MAX_EXPOSED
The maximum number of exposed sets a player can have.

MAX_CONCEALED

public static final int MAX_CONCEALED
The maximum number of concealed sets a player can have.

score

int score
Holds the score of the winning player's hand.

payout

int[] payout
Holds how much each player has to payout.

specialHand

int specialHand
Indicates whether the player has formed a special hand.

checkSpecial

private boolean[] checkSpecial
Used to determine whether the hand is a special hand.

groundInfo

int[] groundInfo
Used to gather Ground Score Information for an Ordinary Suit Hand.

doubleInfo

int[] doubleInfo
Used to store information required in determining what doubles apply to the hand if it's found to be an Ordinary Suit Hand by the Payout class (in the handleScoring method).

doubleFlags

boolean[] doubleFlags
Used to determine what doubles apply to the hand if it's an Ordinary Suit hand.

consecutiveChows

int[] consecutiveChows
Used in determining whether the hand has 3 consecutive chows, thus earning an extra double if it's an ordinary suit hand.

lastTile

Tile lastTile
Used to store the last tile of the hand, ie the tile the winner went Mahjong with.

gameInfo

int[] gameInfo
Stores information supplied by the Game required for calculating the score of the hand.

gameDoubleFlags

boolean[] gameDoubleFlags
Stores information supplied by the Game required for calculating the score of the hand.

payoutData

PayoutInfo payoutData
The object sed to convert the data generated by Payout into what is to be output by the PayoutGUI class.

playerNames

java.lang.String[] playerNames
Lists the names of all four players in the Game.

playerWinds

int[] playerWinds
Lists the winds of all four players in the Game.

winnersPos

int winnersPos
The position of the discarding player (if there was one) in the playerNames and playerWinds arrays.

discardersPos

int discardersPos
The position of the discarding player (if there was one) in the playerNames and playerWinds arrays.

concealedHand

Tile[] concealedHand
Stores all of the Winner's concealed Sets of tiles.
Constructor Detail

Payout

public Payout()
Resets all scoring and payout variables by calling the resetPayOutData and initialiseScoreData methods.
Method Detail

resetPayOutData

public void resetPayOutData()
Resets all variables need in calculating the payout to the winner. Allows scoring information to be kept and still calculate the Payout.

initialiseScoreData

private void initialiseScoreData()
The initialiseScoreData method sets all variables used by the Payout class to their required initial values. These values are essential to the way in which the Payout class works.

For instance, some of the elements in the checkSpecial array are set to true initially and some are set to false. The reason for this is that some checks for special hands can be assumed to be true until seen to be false in the scoring methods, or vice versa. All initial values have been chosen to make calculating the score of the winning hand easier.


handlePayout

public void handlePayout(Set[] concealedSet,
                         Set[] exposedSet,
                         Game gameReference)
The handlePayout method is called once a hand has been completed, ie a player has gone Mahjong. It determines how much all losing players must payout to the winner based on the score calculated for the winning hand (which is determined by calling the handleScoring method.

It then calls the drawPayoutInfo method in order to display to the user in a dialog box the breakdown of the scoring for that hand and how much each losing player had to payout.

Parameters:
concealedSet - The array of concealed tile sets which is contained in the winning hand.
exposedSet - The array of exposed tile sets which is contained in the winning hand.

handleScoring

public int handleScoring(Set[] concealedSets,
                         Set[] exposedSets)
handleScoring first sets all scoring information which the Payout class determines internally to the required initial values by invoking the initialiseScoreData method. This is required in order for handleScoring to be used on multiple hands during the course of a hand.

After this a check is made as to whether the given hand is an "easy" special hand via the scoreIfEasySpecial method, and if it is then the score will be changed to reflect the value of the hand. They are so called "easy" special hands because they are very quick to check for and so don't need to be part of the main score determining methods.

So if the given hand is not one of these "easy" special hands the score will not change and so the main scoring methods will be called.

Parameters:
concealedSet - - The array of concealed tile sets which is contained in the winning hand.
exposedSet - - The array of exposed tile sets which is contained in the winning hand.
Returns:
score - The score calculated for the winning hand.

scoreIfEasySpecial

private void scoreIfEasySpecial()
scoreIfEasySpecial checks firstly whether any of the unusual special hands have been set and then makes trivial checks to see if the given hand is one of 2 other special hands.

The unusual special hands are set by the Game because they can only be checked for there. These unusual special hands (Unique Wonder, Heaven's Grace, Gates of Heaven, Wriggly Snake and Earth's Grace) are unlike other special hands and need to be checked for specially.


scoreExposedSets

private void scoreExposedSets(Set[] exposedSets)
Uses the hand's exposed sets to gather the scoring details for the exposed sets in a player's hand.
Parameters:
exposedSets - - The array of exposed tile sets which is contained in the winning hand.

scoreConcealedSets

private void scoreConcealedSets(Set[] concealedSets)
Uses the hand's concealed sets to gather the scoring details for the concealed sets in a player's hand.
Parameters:
concealedSets - - The array of concealed tile sets which is contained in the winning hand.

handleKongOrPung

private void handleKongOrPung(Set anySet,
                              int baseNumber,
                              boolean isConc)
Gather the scoring details from a concealed Kong or Pung.
Parameters:
anySet - - An exposed or concealed Kong/Pung.
baseNumber - - The base number which the given set scores. It reflects the lowest score which the Kong/Pung can earn. This is used as part of determining the ground score if the player has an Ordinary Suit Hand.
isConc - - Indicates whether anySet is concealed.

handleChows

private void handleChows(Set anySet)
Gather the scoring details from a Chow.
Parameters:
anySet - - An exposed or concealed Kong/Pung.

handlePair

private void handlePair(Set anySet)
Gather the scoring details from a Pair.
Parameters:
anySet - - A pair of tiles.

setSpecialDoubles

private void setSpecialDoubles(Set anySet)
Toggles doubleFlags boolean values depending on whether or not the hand satisfies any of the doubles of an Ordinary Suit Hand.
Parameters:
anySet - - An exposed or concealed kong/pung/chow/pair of tiles.

handleOneChanceHand

private void handleOneChanceHand(Set anySet)
Checks whether the player won with a One Chance Hand. If they did then this is set by setting element ONE_CHANCE_HAND in the double flags array to true.
Parameters:
anySet - - An exposed or concealed kong/pung/chow/pair of tiles.

calcFinalScore

private void calcFinalScore(Set[] exposedSets)
Using all information gathered from the methods which examine sets contained in the players hand (scoreExposedSets, scoreConcealedSets and all worker methods of these two methods) calcFinalScore is used to determine whether the player has won with a special hand or ordinary suit hand. It also establishes the final score of the hand. This is done within the method for a special hand and through worker methods for an ordinary suit hand.
Parameters:
exposedSets - - Required if the player has an ordinary suit hand to determine doubles to the ground score.

applyExtraPoints

private void applyExtraPoints()
Applies relevant extra points to the ground score of the ordinary suit hand.

applyDoubles

private void applyDoubles(Set[] exposedSets)
Determines and applies relevant doubles to the ground score of the ordinary suit hand.
Parameters:
exposedSets - - needed to determine if a further extra points should be added to the ground score before applying doubles.

checkSet

private boolean checkSet(Set anySet,
                         int checkID)
Checks if a given set meets a given check ID.
Parameters:
anySet - A given set.
checkID - The check to be made on the set.

setGameLimit

public void setGameLimit(int limit)
Sets the limit for the hand.
Parameters:
limit - The limit of the hand.

setUniqueWonder

public void setUniqueWonder(Tile[] concealedHand)
Sets that the hand is a Unique Wonder Special Hand.

setHeavensGrace

public void setHeavensGrace()
Sets that the hand is a Heaven's Grace Special Hand.

setGatesOfHeaven

public void setGatesOfHeaven(Tile[] concealedHand)
Sets that the hand is a Gates of Heaven Hand.

setWrigglySnake

public void setWrigglySnake(Tile[] concealedHand)
Sets that the hand is a Wriggly Snake Hand

setEarthsGrace

public void setEarthsGrace()
Sets that the hand is an Earths Grace

setWOR

public void setWOR(int windID)
Sets the current wind of the round.
Parameters:
windID - The current wind of the round.

setLastPickUp

public void setLastPickUp(int lastPickupID)
Sets the the ID of where the last pickup occurred in the game.
Parameters:
lastPickupID - The ID of where the last tile came from.

setLastTile

public void setLastTile(Tile finalTile)
Sets what the last tile to be picked up by the winner was.
Parameters:
finalTinal - The final tile to be picked up.

setStandingHand

public void setStandingHand()
Sets the fact that the player won with a standing hand.

setFirstDiscardBonus

public void setFirstDiscardBonus(boolean bonusVal)
Sets that the player earnt a first discard bonus by punging/konging the first discard made by the east wind player at the start of the hand.

setConcealedMahjong

public void setConcealedMahjong()
Sets that the player won with a concealed mahjong.

setPlayerInfo

public void setPlayerInfo(java.lang.String[] thePlayerNames,
                          int[] thePlayerWinds,
                          int theWinnersPos,
                          int theDiscardersPos)
Sets the info relating to all players.
Parameters:
thePlayerNames - The names of all players.
thePlayerWinds - The winds of all players.
theWinnersPos - The winners position in thePlayerNames and thePlayerWinds arrays.
theDiscardersPos - The discarders position in thePlayeNames and thePlayerWinds arrays.