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

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

public class Comb
extends java.lang.Object

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.

Author:
Dean Cortinovis

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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EMPTY_SPACE

public static final int EMPTY_SPACE
Signals empty space in the list.

END_OF_LIST

public static final int END_OF_LIST
Signals end of the list.

MAX_TILES

public static final int MAX_TILES
The maximum number of tiles expected in an expanded combination.

tileNo

private int[] tileNo
List of tile numbers in the combination.

suit

private int[] suit
List of suits corresponding to the tile numbers.
Constructor Detail

Comb

public Comb()
Class constructor- Initialises storage and the first position in the list.
Method Detail

getNumber

public int getNumber(int location)
Returns the tile number at the given location.

Parameters:
location - Location of tile number to retrieve.
Returns:
Tile number.

getSuit

public int getSuit(int location)
Returns the suit at the given location.

Parameters:
location - Location of suit to retrieve.
Returns:
Suit of the tile.

copyGroup

public void copyGroup(Comb original)
Copies the entire contents of one combination into the current combination. Beginning with the first tile in the original combination the function traverses the array and copies the tile number and suit into this combination. The copying continues for all entries in the 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;
 }

Parameters:
original - The original combination to be copied from.

insertGroup

public void insertGroup(int height,
                        int curNum,
                        int curSuit,
                        int direction)
Inserts the given contents into the first available position in this combination. The tile array is traversed until the last filled position is reached. If the direction of grouping is across, then the next "height" spaces are filled with the given tile number and suit. If however the direction of inserting is up, then the next height spaces are filled with the given tile number and suit, and the remaining 3 - height spaces with blanks. After the tiles have been inserted, the end of list marker is placed in the next available position. This will mark a location for the next entry.

 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;
 }

Parameters:
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.
Returns:
Number of tiles inserted into the combination.

isMahjong

public int isMahjong()
Searches through the combination to see if it is a fishing or Mahjong hand. The function traverses the tile and suit lists, and treats every three tiles as one set. After three tiles have been traversed the type of set is determined. They fall into one of four categories: three(Chow or Pung), two(incomplete set), pair or one(single tile). The number of each set in the combination are then counted. Once the entire combination has been traversed the totals are then used to determine if it is fishing or Mahjong.

 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; } }

Returns:
0- Neither mahjong or fishing.
1- Mahjong.
2- Fishing.

convertComb

public 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. 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.

Parameters:
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.