package org.mahjong4j.yaku.normals;

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

import java.util.List;

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

/**
 * 三色同順判定クラス
 * 萬子・索子・筒子それぞれの色で同じ並びの順子を作ったときに成立
 *
 * @author yu1ro
 */
public class SanshokudohjunResolver implements NormalYakuResolver {
    private MahjongYakuEnum yakuEnum = SANSHOKUDOHJUN;
    private int shuntsuCount;
    private List<Shuntsu> shuntsuList;

    public SanshokudohjunResolver(MentsuComp comp) {
        shuntsuCount = comp.getShuntsuCount();
        shuntsuList = comp.getShuntsuList();
    }

    public MahjongYakuEnum getNormalYaku() {
        return yakuEnum;
    }

    public boolean isMatch() {
        if (shuntsuCount < 3) {
            return false;
        }
        boolean manzu = false;
        boolean pinzu = false;
        boolean sohzu = false;

        for (Shuntsu shuntsu : shuntsuList) {
            MahjongTileType shuntsuType = shuntsu.getTile().getType();
            if (shuntsuType == MahjongTileType.MANZU) {
                manzu = true;
            } else if (shuntsuType == MahjongTileType.PINZU){
                pinzu = true;
            } else if (shuntsuType == MahjongTileType.SOHZU){
                sohzu = true;
            }
        }
        return manzu && pinzu && sohzu;
    }
}

@@ -173,16 +173,68 @@
 .List;%0A%0A
+import static org.mahjong4j.tile.MahjongTileType.*;%0A
 import s
@@ -568,16 +568,123 @@
 uList;%0A%0A
+    private boolean manzu = false;%0A    private boolean pinzu = false;%0A    private boolean sohzu = false;%0A%0A%0A
     publ
@@ -1003,24 +1003,25 @@
       %7D%0A
+%0A
         
 boolean 
@@ -1016,91 +1016,32 @@
     
-boolean manzu = false;%0A        boolean pinzu = false;%0A        boolean sohzu = false
+Shuntsu candidate = null
 ;%0A%0A 
@@ -1173,47 +1173,89 @@
    i
-f (
+nt 
 shuntsu
-Type == MahjongTileType.MANZU
+Num = shuntsu.getTile().getNumber();%0A%0A            if (candidate == null
 ) %7B%0A
@@ -1274,269 +1274,632 @@
     
-manzu = true;%0A            %7D else if (shuntsuType == MahjongTileType.PINZU)%7B%0A                pinzu = true;%0A            %7D else if (shuntsuType == MahjongTileType.SOHZU)%7B%0A                sohzu = true;%0A            %7D%0A        %7D%0A        return manzu && pinzu && sohzu;
+candidate = shuntsu;%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 = shuntsu;%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            pinzu = true;%0A        %7D else if (shuntsuType == SOHZU) %7B%0A            sohzu = true;%0A        %7D
 %0A   

fix sanshokudohjun resolver