Bug 261

Summary: The ArrayList<Tile> tileSet is not sorted
Product: Group3 Mahjong Point Calculator Reporter: CHAN Cheuk Yin <raymondchan0105>
Component: SystemAssignee: kakityu6-c
Status: RESOLVED FIXED    
Severity: critical    
Priority: ---    
Version: 1.0   
Hardware: PC   
OS: Windows   

Description CHAN Cheuk Yin 2018-11-27 12:24:20 HKT
The bug appears in some of the checkPattern() functions of hand pattern which required to check for AllInTriplets. To check for AllInTriplets, the tileSet need to be sorted first, and then to count each type of tile and check whether it is in 2,3,3,3,3 structure. Therefore, if the tileSet is not sorted, the checking will go wrong.

The cause of this bug is that the tiles are stored in a HashSet. Since the HashSet use a hash function to compute an index into an array of buckets or slot, the element in the set will not be sorted.

To resolve this bug, it is suggested to use TreeSet to store the tiles, or to override the function of compare() of the class Tile so as to ensure the tiles in tileSet is in-order.
Comment 1 kakityu6-c 2018-11-27 12:59:18 HKT
Thank you for raising the problem again.

The bug in program is caused by HashSet<Tile>, and it can be resolved by using TreeSet<Tile> as it would not change the order of element while adding.

It will be included as a patch in release version 2.0, including other possible bug fixing solution.