package org.mahjong4j.yaku.yakuman;

import org.mahjong4j.hands.Kantsu;
import org.mahjong4j.hands.Kotsu;
import org.mahjong4j.hands.MentsuComp;

import static org.mahjong4j.yaku.yakuman.MahjongYakumanEnum.CHINROTO;

/**
 * 清老頭判定クラス
 * 手牌全体が老頭牌（一九牌）だけの場合成立
 *
 * @author yu1ro
 */
public class ChinrohtohResolver implements YakumanResolver {
    private MentsuComp comp;

    public ChinrohtohResolver(MentsuComp comp) {
        this.comp = comp;
    }

    public MahjongYakumanEnum getYakuman() {
        return CHINROTO;
    }

    /**
     * 違うものが見つかったらfalseを返す方針です
     *
     * @return 清老頭かどうか
     */
    public boolean isMatch() {
        int total = comp.getKotsuCount() + comp.getKantsuCount();
        if (total != 4) {
            return false;
        }

        int tileNum = comp.getToitsuList().get(0).getTile().getNumber();
        if (tileNum != 1 && tileNum != 9) {
            return false;
        }

        //刻子が全て一九牌か
        for (Kotsu kotsu : comp.getKotsuList()) {
            tileNum = kotsu.getTile().getNumber();
            if (tileNum != 1 && tileNum != 9) {
                return false;
            }
        }

        //槓子が全て一九牌か
        for (Kantsu kantsu : comp.getKantsuList()) {
            tileNum = kantsu.getTile().getNumber();
            if (tileNum != 1 && tileNum != 9) {
                return false;
            }
        }

        //ここまできたら見つかっている
        return true;
    }
}

@@ -34,43 +34,8 @@
 n;%0A%0A
-import org.mahjong4j.hands.Kantsu;%0A
 impo
@@ -102,16 +102,75 @@
 tsuComp;
+%0Aimport org.mahjong4j.hands.Toitsu;%0A%0Aimport java.util.List;
 %0A%0Aimport
@@ -375,99 +375,288 @@
 ate 
-MentsuComp comp;%0A%0A    public ChinrohtohResolver(MentsuComp comp) %7B%0A        this.comp = comp
+int totalKotsuKantsu;%0A    private List%3CKotsu%3E kotsuList;%0A    private Toitsu janto;%0A%0A    public ChinrohtohResolver(MentsuComp comp) %7B%0A        totalKotsuKantsu = comp.getKotsuCount() + comp.getKantsuCount();%0A        kotsuList = comp.getKotsuKantsu();%0A        janto = comp.getJanto()
 ;%0A  
@@ -858,82 +858,27 @@
    i
-nt 
+f (
 total
- = comp.getKotsuCount() + comp.getKantsuCount();%0A        if (total
+KotsuKantsu
  != 
@@ -945,35 +945,13 @@
 m = 
-comp.getToitsuList().get(0)
+janto
 .get
@@ -1102,25 +1102,17 @@
 u : 
-comp.getK
+k
 otsuList
 ()) 
@@ -1103,26 +1103,24 @@
  : kotsuList
-()
 ) %7B%0A        
@@ -1269,236 +1269,8 @@
  %7D%0A%0A
-        //%E6%A7%93%E5%AD%90%E3%81%8C%E5%85%A8%E3%81%A6%E4%B8%80%E4%B9%9D%E7%89%8C%E3%81%8B%0A        for (Kantsu kantsu : comp.getKantsuList()) %7B%0A            tileNum = kantsu.getTile().getNumber();%0A            if (tileNum != 1 && tileNum != 9) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A
     

refactor ChinrotoResolver