package org.mahjong4j.yaku.normals;


import org.mahjong4j.hands.*;
import org.mahjong4j.tile.MahjongTileType;

import java.util.List;

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

/**
 * 混一色判定クラス
 * 萬子、索子、筒子のどれか一種と、字牌のみで構成される場合成立
 *
 * @author yu1ro
 */
public class HonitsuResolver implements NormalYakuResolver {
    final int HAN = HONITSU.getHan();

    private List<Toitsu> toitsuList;
    private List<Shuntsu> shuntsuList;
    private List<Kotsu> kotsuList;
    private List<Kantsu> kantsuList;

    private boolean hasJihai = false;
    private MahjongTileType type = null;

    public HonitsuResolver(MentsuComp comp) {
        toitsuList = comp.getToitsuList();
        shuntsuList = comp.getShuntsuList();
        kotsuList = comp.getKotsuList();
        kantsuList = comp.getKantsuList();
    }

    public int getHan() {
        return HAN;
    }

    public MahjongYakuEnum getNormalYaku() {
        return HONITSU;
    }

    public boolean isMatch() {

        for (Toitsu toitsu : toitsuList) {
            if (!hasOnlyOneType(toitsu)) {
                return false;
            }
        }

        for (Shuntsu shuntsu : shuntsuList) {
            if (!hasOnlyOneType(shuntsu)) {
                return false;
            }
        }

        for (Kotsu kotsu : kotsuList) {
            if (!hasOnlyOneType(kotsu)) {
                return false;
            }
        }

        for (Kantsu kantsu : kantsuList) {
            if (!hasOnlyOneType(kantsu)) {
                return false;
            }
        }

        return hasJihai;
    }

    private boolean hasOnlyOneType(MahjongMentsu mentsu) {
        if (mentsu.getTile().getNumber() == 0) {
            hasJihai = true;
        } else if (type == null) {
            type = mentsu.getTile().getType();
        } else if (type != mentsu.getTile().getType()) {
            return false;
        }
        return true;
    }
}

@@ -58,17 +58,68 @@
 j.hands.
-*
+MahjongMentsu;%0Aimport org.mahjong4j.hands.MentsuComp
 ;%0Aimport
@@ -442,137 +442,32 @@
 ist%3C
-Toitsu%3E toitsuList;%0A    private List%3CShuntsu%3E shuntsuList;%0A    private List%3CKotsu%3E kotsuList;%0A    private List%3CKantsu%3E kantsuList
+MahjongMentsu%3E allMentsu
 ;%0A%0A 
@@ -603,168 +603,37 @@
     
-toitsuList = comp.getToitsuList();%0A        shuntsuList = comp.getShuntsuList();%0A        kotsuList = comp.getKotsuList();%0A        kantsuList = comp.getKantsuList
+allMentsu = comp.getAllMentsu
 ();%0A
@@ -817,457 +817,40 @@
 or (
-Toitsu toitsu : toitsuList) %7B%0A            if (!hasOnlyOneType(toitsu)) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        for (Shuntsu shuntsu : shuntsuList) %7B%0A            if (!hasOnlyOneType(shuntsu)) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        for (Kotsu kotsu : kotsuList) %7B%0A            if (!hasOnlyOneType(kotsu)) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        for (Kantsu kantsu : kantsuList
+MahjongMentsu mentsu : allMentsu
 ) %7B%0A
@@ -881,18 +881,18 @@
 OneType(
-ka
+me
 ntsu)) %7B

refactor HonitsuResolver