|
||||||||
| 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.Comb
The Comb class forms the storage for a single combination
extracted from the concealed hand.
As tiles are extracted from the hand, the class will insert the given tile
into the next available position in the tile number and suit arrays. All
inserting instructions will be made from the CombList class.
Comb will be instructed with how many spaces to insert into
and what to insert in it.
During the game a combination will need to be checked for fishing or
Mahjong. The Comb class makes these checks and returns
appropriate flags for each situation.
At the end of the round, the winning concealed hand will need to be
converted into Set. This class will have the responsibility
of running the conversion. The Sets are created and then
returned to the Hand class for Payout.
| Field Summary | |
static int |
EMPTY_SPACE
Signals empty space in the list. |
static int |
END_OF_LIST
Signals end of the list. |
static int |
MAX_TILES
The maximum number of tiles expected in an expanded combination. |
private int[] |
suit
List of suits corresponding to the tile numbers. |
private int[] |
tileNo
List of tile numbers in the combination. |
| Constructor Summary | |
Comb()
Class constructor- Initialises storage and the first position in the list. |
|
| Method Summary | |
void |
convertComb(Set[][] conHand,
Set[][] expHand,
Tile lastDiscard,
int insertLocation)
Converts the combination into Set when a player
has Mahjong at the end of the hand. |
void |
copyGroup(Comb original)
Copies the entire contents of one combination into the current combination. |
int |
getNumber(int location)
Returns the tile number at the given location. |
int |
getSuit(int location)
Returns the suit at the given location. |
void |
insertGroup(int height,
int curNum,
int curSuit,
int direction)
Inserts the given contents into the first available position in this combination. |
int |
isMahjong()
Searches through the combination to see if it is a fishing or Mahjong hand. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final int EMPTY_SPACE
public static final int END_OF_LIST
public static final int MAX_TILES
private int[] tileNo
private int[] suit
| Constructor Detail |
public Comb()
| Method Detail |
public int getNumber(int location)
location - Location of tile number to retrieve.public int getSuit(int location)
location - Location of suit to retrieve.public void copyGroup(Comb original)
void copyGroup(Comb original) {
while moving through the original combination {
copy the suit of the original into this combination;
copy the tile number into this combination;
}
insert end of combination flag into this combination;
}
original - The original combination to be copied from.
public void insertGroup(int height,
int curNum,
int curSuit,
int direction)
void insertGroup(int height, int curNum, int curSuit, int direction) {
while moving across current combination {
if the current tile matches any other inserted tile then {
add to count;
}
}
if the direction of inserting is across then {
for each item to be added {
add tile number;
add suit;
}
}
else {
for the next 3 spaces {
if height has been filled then {
insert EMPTY_SPACE flag into the space;
}
else {
add tile number;
add suit;
}
}
}
insert end of combination flag into this combination;
}
height - The amount of the given tiles to insert.curNum - The tile number to insert.curSuit - The suit of the tile.direction - The direction which the hand is being looked at.public int isMahjong()
int isMahjong(){
for all tiles in the combination {
if the tile space is not empty then{
add one to the count;
place the tile number into the corresponding position of its
set in a temporary array;
}
if the end of the set is reached(i.e. three spaces) then {
if the count is 3 then {
add to the three count;
}
if the count is 2 then {
if the first two items in the temporary array match
then {
add to the pair count;
}
else {
add to the two count;
}
}
if the count is 1 then {
add to the one count;
}
}
}
if one count == 0 and there is one pair and no twos then {
return 1;
}
if two count == 0 and one count == 1 and no pairs then {
return 2;
}
if one count == 0 and there are two pairs and no twos then {
return 2;
}
if one count == 0 and there is one pair and twos == 1 then {
return 2;
}
}
public void convertComb(Set[][] conHand,
Set[][] expHand,
Tile lastDiscard,
int insertLocation)
Set when a player
has Mahjong at the end of the hand. The function
traverses the tile and suit lists, but treats every three tiles as one
set. After three tiles have been traversed the type of Set
is determined. They fall into one of three categories: Chow, Pung or
Pair. The first two tiles are taken and compared. A Set is
a Chow if any two of the tiles are dissimilar. A Set is a
Pung if all tiles in the set are similar. Any Set with only
two tiles must be the pair. A new Set is created for every
three tiles and inserted into the next available position.
conHand - Storage for the sets.expHand - Sets to add to the exposed hand.lastDiscard - Last discarded tile.insertLocation - Location at which this combination must be
inserted into the newHand.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||