package org.mahjong4j.yaku.normals;

import org.mahjong4j.hands.Kotsu;
import org.mahjong4j.hands.MentsuComp;
import org.mahjong4j.tile.MahjongTileType;

import java.util.List;

import static org.mahjong4j.yaku.normals.MahjongYakuEnum.SANSHOKUDOHKO;

/**
 * 三色同刻判定クラス
 * 萬子・索子・筒子それぞれの色で同じ数字の刻子（槓子も含む）を作ったときに成立
 *
 * @author yu1ro
 */
public class SanshokudohkoResolver implements NormalYakuResolver {
    private MahjongYakuEnum yakuEnum = SANSHOKUDOHKO;
    private int kotsuCount;
    private List<Kotsu> kotsuList;

    public SanshokudohkoResolver(MentsuComp comp) {
        kotsuCount = comp.getKotsuCount() + comp.getKantsuCount();
        kotsuList = comp.getKotsuKantsu();
    }

    public MahjongYakuEnum getNormalYaku() {
        return yakuEnum;
    }

    public boolean isMatch() {
        if (kotsuCount < 3) {
            return false;
        }

        boolean manzu = false;
        boolean pinzu = false;
        boolean sohzu = false;
        for (Kotsu kotsu : kotsuList) {
            MahjongTileType kotsuType = kotsu.getTile().getType();
            if (kotsuType == MahjongTileType.MANZU) {
                manzu = true;
            } else if (kotsuType == MahjongTileType.PINZU) {
                pinzu = true;
            } else if (kotsuType == MahjongTileType.SOHZU) {
                sohzu = true;
            }
        }
        return manzu && pinzu && sohzu;
    }
}

@@ -171,16 +171,184 @@
 .List;%0A%0A
+import static org.mahjong4j.tile.MahjongTileType.MANZU;%0Aimport static org.mahjong4j.tile.MahjongTileType.PINZU;%0Aimport static org.mahjong4j.tile.MahjongTileType.SOHZU;%0A
 import s
@@ -680,16 +680,122 @@
 uList;%0A%0A
+    private boolean manzu = false;%0A    private boolean pinzu = false;%0A    private boolean sohzu = false;%0A%0A
     publ
@@ -1142,91 +1142,30 @@
     
-boolean manzu = false;%0A        boolean pinzu = false;%0A        boolean sohzu = false
+Kotsu candidate = null
 ;%0A  
@@ -1230,18 +1230,20 @@
 ileType 
-ko
+shun
 tsuType 
@@ -1288,45 +1288,87 @@
    i
-f (kotsuType == MahjongTileType.MANZU
+nt shuntsuNum = kotsu.getTile().getNumber();%0A%0A            if (candidate == null
 ) %7B%0A
@@ -1387,267 +1387,628 @@
     
-manzu = true;%0A            %7D else if (kotsuType == MahjongTileType.PINZU) %7B%0A                pinzu = true;%0A            %7D else if (kotsuType == MahjongTileType.SOHZU) %7B%0A                sohzu = true;%0A            %7D%0A  
+candidate = kotsu;%0A                continue;%0A            %7D%0A%0A            if (candidate.getTile().getNumber() == shuntsuNum) %7B%0A                detectType(shuntsuType);%0A                detectType(candidate.getTile().getType());%0A            %7D else %7B%0A                candidate = kotsu;%0A            %7D%0A        %7D%0A        return manzu && pinzu && sohzu;%0A    %7D%0A%0A    private void detectType(MahjongTileType shuntsuType) %7B%0A        if (shuntsuType == MANZU) %7B%0A            manzu = true;%0A        %7D else if (shuntsuType == PINZU) %7B%0A
       
-%7D%0A
       
-  return manzu && pinzu && sohzu;
+pinzu = true;%0A        %7D else if (shuntsuType == SOHZU) %7B%0A            sohzu = true;%0A        %7D
 %0A   

fix sanshokudohko resolver