|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--au.com.solidsoftware.multimahjong.mmc.game.Hand
SRS - 4.3.1, 4.3.2, 4.3.4, 4.3.5, 4.3.6
The Hand class represents the full hand of a player(this
includes both concealed and exposed) in the Game of mahjong.
All functions that are necessary to maintain, observe and display the
hand will be contained in this class. The Hand is
re-initialised at the end of each round. After the Wall has
been retrieved by the Game, tiles are drawn and inserted
into the concealed hand.
During the move selection process a player's Hand will need to
be checked to see if it is possible that they can Chow, Pung, Kong or
Mahjong with the last discard. The Hand class will contain
all these checks, and if the move is determined to have the highest
priority it will need to update the hand according to the selection.
Whenever the player must discard, checks need to be made in the concealed
hand for the possibility of the DeclareKong or Pung2Kong. These are again
contained in the Hand class. Once the discard tile is chosen
it will need to be removed from the concealed hand and then will need to
check for a Fishing. The checks for both Mahjong and Fishing are conducted
by the CombList class. Whenever a new concealed hand is formed
the CombList is re-initialised, a new list of combinations
produced and the relevant checks made. The check for Mahjong is only
necessary at the start of the game(for the east Players initial
hand), and whenever a Player is Fishing. Special Mahjong hands
will also be included in the checks and if they conform to one of these
special types a flag is set in the Payout class.
| Field Summary | |
private boolean |
allDrawWall
Flag- True if all tiles except the last was drawn from Wall. |
private int[][] |
concealedHand
Concealed hand of a player. |
private Tile[] |
copyOfHand
Copy of the concealed hand of the player used by the PlayArea. |
private Set[] |
exposedHand
Exposed hand of a player. |
static int |
FISHING
|
private CombList |
handComb
Combination list for the concealed hand. |
private Tile |
lastDiscard
Lastdiscarded tile. |
static int |
MAHJONG
|
static int |
MAX_SETS
Maximum number of Sets expected to fill the exposed Hand. |
static int |
NEITHER_MAH_FISH
|
private Payout |
payout
Access to the Payout class. |
private boolean |
specialHand
Type of hand that the concealed hand forms. |
| Constructor Summary | |
Hand(Payout payout)
Constructs and initialises the player's concealed and exposed hands, and the payout. |
|
| Method Summary | |
private void |
addSet(Set[] hand,
Set aSet)
Adds a set to the end of the given hand. |
boolean |
canChow2Down(Tile lastDiscard)
Checks to see if the player can Chow with the current discard tile. |
boolean |
canChow2Sides(Tile lastDiscard)
Checks to see if the player can Chow with the current discard tile. |
boolean |
canChow2Up(Tile lastDiscard)
Checks to see if the player can Chow with the current discard tile. |
boolean |
canKong(Tile lastDiscard)
Checks to see if the player can Kong with the current discard tile. |
boolean |
canPung(Tile lastDiscard)
Checks to see if the player can Pung with the current discard tile. |
boolean |
checkFishing()
Checks a player's hand for ordinary and special fishing hands. |
boolean |
checkKong(Tile selectedTile)
Looks to see if the player can declare a concealed Kong with the selected tile. |
boolean |
checkMahjong(Tile lastPickUp)
Checks a player's hand for ordinary and special Mahjong hands. |
boolean |
checkPung2Kong(Tile selectedTile)
Checks the player's hand for an exposed Pung similar to the selected tile. |
void |
declareKong(Tile selectedTile)
Reveals a concealed Kong in the player's hand, using the selected tile. |
void |
discard(Tile lastDiscard)
Removes the given tile from the player's concealed hand. This function is called when the player discards a tile from their hand. |
boolean |
findKong()
Searches through the player's concealed hand to find any Kongs that may exist. |
boolean |
findPung2Kong()
Scans through all tiles in the concealed hand and then tries to match these tiles with the Set in the exposed
hand. |
Set[] |
getSet()
Returns players exposed hand to be displayed in the PlayArea. |
Tile[] |
getTiles()
Returns players concealed hand to be displayed in the PlayArea. |
void |
insertTile(Tile givenTile)
Inserts the given tile into the player's concealed hand. |
void |
mahjong(Game game)
Calculates the best form that the concealed hand of the winner can take. |
private void |
removeSet(Set[] hand,
Set aSet)
Searches for and removes a set from the given hand. |
void |
removeTile(int suit,
int tileNo)
This locates and removes a tile with the given tile number and suit from the concealed hand. |
void |
runChow(Tile lastDiscard,
int selection)
Exposes the Chow in the player's concealed hand with the given discard. |
void |
runKong(Tile lastDiscard)
Exposes a Kong in the player's hand with the given discard. |
void |
runMahjong(Tile lastDiscard)
This is run whenever a player has mahjong by using the last discarded tile. |
void |
runPung(Tile lastDiscard)
Exposes the Pung in the player's concealed hand with the given discard. |
void |
runPung2Kong(Tile selectedTile)
This function is run if the player has selected to and can successfully add a tile to an exposed Pung. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final int NEITHER_MAH_FISH
public static final int MAHJONG
public static final int FISHING
public static final int MAX_SETS
private boolean allDrawWall
private int[][] concealedHand
private Tile[] copyOfHand
private Set[] exposedHand
private boolean specialHand
private CombList handComb
private Payout payout
private Tile lastDiscard
| Constructor Detail |
public Hand(Payout payout)
payout - Reference to the Game's Payout.| Method Detail |
public void insertTile(Tile givenTile)
throws java.lang.ArrayIndexOutOfBoundsException
givenTile - Tile to insert into player's Hand.
public void discard(Tile lastDiscard)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
This function is called when the player discards a tile from their hand.
lastDiscard - Tile to remove.
public void removeTile(int suit,
int tileNo)
Set.
tileNo - Number of the tile to remove.suit - Suit of the tile to remove.
public void runChow(Tile lastDiscard,
int selection)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Chi2Sides, the tiles to either side of
the discard are removed from the concealed hand. If the selection was
Chi2Down, the two tiles below the discard are removed.
If the selection was Chi2Up, then the two above are
removed. A Chow is placed in the exposed hand, indicated by the first
tile in the Set.
void runChow(Tile lastDiscard, int selection) {
get suit of tile;
get tile number from tile;
if selection was CHOW2SIDES then {
remove the tile with the suit and tile number - 1 from the
concealedHand;
remove the tile with the suit and tile number + 1 from the
concealedHand;
create a new set;
initialise set to Chow, with location suit and tile number
- 1;
attach new set to end of exposedHand list;
}
if selection was CHOW2DOWN then {
remove the tile with the suit and tile number - 1 from the
concealedHand;
remove the tile with the suit and tile number - 2 from the
concealedHand;
create a new set;
initialise set to Chow, with the suit and tile number - 2;
attach new set to end of exposedHand list;
}
if selection was CHOW2UP then {
remove the tile with the suit and tile number + 1 from the
concealedHand;
remove the tile with the suit and tile number + 2 from the
concealedHand;
create a new set;
initialise set to Chow, with the suit and tile number;
attach new set to end of exposedHand list;
}
allDrawWall is false;
}
lastDiscard - Tile that will be used to make up the exposed Chow.selection - Which of the 3 Chow(chow2Down, chow2Up or chow2Sides) to
run.
public void runPung(Tile lastDiscard)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Set.
void runPung(Tile lastDiscard) {
get suit of tile;
get tile number from tile;
remove two of the tiles with the suit and tile number from the
concealedHand;
create a new set;
initialise set to Pung, with the suit and tile number;
attach new set to end of exposedHand list;
allDrawWall is false;
}
lastDiscard - Tile that will be used to make up the exposed Pung.public boolean findKong()
findKong() will return true.
boolean findKong() {
for all locations in the concealed hand {
if the location contains 4 tiles then
return true;
}
return false;
}
public boolean checkKong(Tile selectedTile)
boolean checkKong(Tile selectedTile) {
get suit of tile;
get tile number from tile;
if the location at suit and tile number in the concealed hand
contains four tiles then
return true;
else
return false;
}
selectedTile - Tile selected by the player.
public void runKong(Tile lastDiscard)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Set into the exposed hand.
void runKong(Tile lastDiscard) {
get suit of tile;
get tile number from tile;
remove three of the tiles with the suit and tile number from the
concealedHand;
create a new set;
initialise set to Kong, with the suit and tile number;
attach new set to end of exposedHand list;
allDrawWall is false;
}
lastDiscard - Tile that will be used to make up the exposed Kong.
public void declareKong(Tile selectedTile)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Set into the exposed
hand.
void declareKong(Tile selectedTile) {
get suit of tile;
get tile number from tile;
remove four of the tiles with the suit and tile number from the
concealedHand;
create a new set;
initialise set to declared Kong, with location suit and tile
number;
attach new set to end of exposedHand list;
}
selectedTile - Tiles selected to declare.public boolean findPung2Kong()
Set in the exposed
hand. If for any tile in the concealed hand, there is a matching
Set that is a Pung then the findPung2Kong()
will return true.
public void runPung2Kong(Tile selectedTile)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Set with the similar
starting tile to the selectedTile is changed from a Pung to a Kong.
void runPung2Kong(Tile selectedTile) {
get suit of tile;
get tile number from tile;
while searching through exposed hand and Pung not found {
if tile number of set = number of tile and suit of set = suit
of tile
found is true;
}
convert set to pung2Kong();
}
selectedTile - Tile to add to Pung.
public boolean checkPung2Kong(Tile selectedTile)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
boolean checkPung2Kong(Tile selectedTile) {
get suit of tile;
get tile number from tile;
for all locations in the exposed hand {
if the set's suit = the tile's suit and set's tile number =
the tile's number then {
if the set type is a Pung then
return true;
}
}
return false;
}
selectedTile - Tile to add to Pung.public void runMahjong(Tile lastDiscard)
lastDiscard - Tile used to go mahjong.
public void mahjong(Game game)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
Payout class and if a special
hand is not formed the different Mahjong combinations are sent to the
Payout class to determine which produces the highest
score.
public void mahjong() {
get suit of tile;
get tile number from tile;
payout.allDrawHand(allDrawHand);
if the hand is not a special hand then {
number of best combinations = extract best combinations out of
concealed hand;
initialise a list of temporary concealed hand Sets;
convert the best combinations into Sets;
for all combination Sets {
if the score is higher than the previous score then
best combination = this combination;
}
}>
}
lastTile - Tile with which the player's hand has won.
private void removeSet(Set[] hand,
Set aSet)
hand - List of sets.aSet - Set to remove.
private void addSet(Set[] hand,
Set aSet)
hand - List of sets.aSet - Set to remove.
public boolean checkMahjong(Tile lastPickUp)
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
uniqueWonder(), gatesOfHeaven() and ordinary Mahjong
checks. The copy is necessary, as tiles are removed in the ordinary
Mahjong check. A second copy is made to check for the
wrigglySnake(). The exposed tiles are added to the
concealed hand to run the check. Once the copies have been made the
lastPickUp tile is added to see if this will produce a
Mahjong hand. The checkMahjong() function is only run at
the beginning of the game, to check that East hasn't been dealt
a Mahjong hand, and when a player is fishing during the game.
boolean checkMahjong(Tile lastPickUp) {
get suit of tile;
get tile number from tile;
initialise two copies of the concealed hand;
copy concealed hand into both copies;
while there are still more sets in the exposed hand and a wriggly
snake is possible {
if set is a Chow then {
increment the first copy by one at the location of the sets
tile number and suit;
increment the first copy by one at the location of the sets
tile number + 1 and suit;
increment the first copy by one at the location of the sets
tile number + 2 and suit;
}
if set is a Pung then {
break. The wriggly snake isn't possible;
}
if set is a Kong then {
break. The wriggly snake isn't possible;
}
if set is a declared Kong then {
break. The wriggly snake isn't possible;
}
}
if the lastPickUp exists then {
increment both copies by one at the location of the tile's
number and suit;
}
if the hand is a uniquewonder- using the second copy then {
payout.uniqeWonder();
return true;
}
if the hand is a gatesOfHeaven- using the second copy then {
payout.gatesOfHeaven();
return true;
}
if a wriggly snake is possible and the hand is a wrigglySnake-
using the first copy then {
payout.wrigglySnake();
return true;
}
if the hand is an ordinary mahjong hand- using the second copy
then {
return true;
}
}
public boolean checkFishing()
throws java.lang.NullPointerException,
java.lang.ArrayIndexOutOfBoundsException
uniqueWonder(), gatesOfHeaven() and ordinary fishing
checks. The copy is necessary, as tiles are removed in the ordinary
fishing check. A second copy is made to check for the
wrigglySnake(). The exposed tiles are added to the
concealed hand to run the check. CheckFishing() is run
whenever a player removes a tile for a discard or pung2Kong, or when a
player reveals or declares a Kong.
boolean checkFishing() {
initialise two copies of the concealed hand;
copy concealed hand into both copies;
for all sets in the exposed hand {
if set is a Chow then {
increment the first copy by one at the location of the sets
tile number and suit;
increment the first copy by one at the location of the sets
tile number + 1and suit;
increment the first copy by one at the location of the sets
tile number +2 and suit;
}
if set is a Pung then {
break. The wriggly snake isn't possible;
}
if set is a Kong then {
break. The wriggly snake isn't possible;
}
if set is a declared Kong then {
break. The wriggly snake isn't possible;
}
if the hand is a fishing uniquewonder- using the second copy
then {
payout.uniqeWonder();
return true;
}
if the hand is a fishing gatesOfHeaven- using the second copy
then {
payout.gatesOfHeaven();
return true;
}
if a wriggly snake is possible and the hand is a fishing
wrigglySnake- using the first copy then {
payout.wrigglySnake();
return true;
}
if the hand is an ordinary fishing hand- using the second copy
then {
return true;
}
}
public boolean canChow2Sides(Tile lastDiscard)
lastDiscard then this function will
return true.
int canChow2Sides(Tile lastDiscard){
get suit of tile;
get tile number from tile;
if (the tileNumber - 1 >= 0 ) and (the tile's suit is not an honour
tile) and (the tileNumber + 1 <= MAX_TILENO) then {
if (the concealed hand at tile number - 1 and suit >= 1) and (
tileNumber + 1 and suit >= 1) then
return true;
}
return false;
}
lastDiscard - Last discarded tile.public boolean canChow2Down(Tile lastDiscard)
lastDiscard then this function will return true.
int canChow2Down(Tile lastDiscard) {
get suit of tile;
get tile number from tile;
if (the tileNumber-2 >= 0 ) and (the tiles suit is not an honour
tile) then {
if (the concealed hand at tile number - 2 and suit >= 1) and (
tileNumber - 1 and suit >= 1) then
return true;
}
return false;
}
lastDiscard - Last discarded tile.public boolean canChow2Up(Tile lastDiscard)
lastDiscard then this function will return true.
int canChow2Up(Tile lastDiscard) {
get suit of tile;
get tile number from tile;
if (the tiles suit is not an honour tile) and (the tileNumber + 2 <=
MAX_TILENO) then {
if (the concealed hand at tile number + 1 and suit >= 1) and
(tileNumber + 2 and suit >= 1) then
return true;
}
return false;
}
lastDiscard - Last discarded tile.public boolean canPung(Tile lastDiscard)
int canPung(Tile lastDiscard) {
get suit of tile;
get tile number from tile;
if (the concealed hand at tile number and suit >= 2) then
return true;
return false;
}
lastDiscard - Last discarded tile.public boolean canKong(Tile lastDiscard)
lastDiscard the this function will return true.lastDiscard - Last discarded tile.public Tile[] getTiles()
PlayArea.
public Set[] getSet()
PlayArea.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||