package org.mahjong4j.yaku.normals;


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

import static org.mahjong4j.tile.MahjongTileType.FONPAI;
import static org.mahjong4j.tile.MahjongTileType.SANGEN;

/**
 * 清一色判定クラス
 * 萬子、索子、筒子のどれか一種の牌だけで構成された場合成立
 *
 * @author yu1ro
 */
public class ChinitsuResolver implements NormalYakuResolver {
    final int HAN = MahjongYakuEnum.CHINITSU.getHan();
    private MentsuComp mentsuComp;

    public ChinitsuResolver(MentsuComp mentsuComp) {
        this.mentsuComp = mentsuComp;
    }

    public int getHan() {
        return HAN;
    }

    public MahjongYakuEnum getNormalYaku() {
        return MahjongYakuEnum.CHINITSU;
    }

    public boolean isMatch() {
        MahjongTileType type = null;
        for (Toitsu toitsu : mentsuComp.getToitsuList()) {
            MahjongTileType toitsuType = toitsu.getTile().getType();
            if (toitsuType == FONPAI || toitsuType == SANGEN) {
                return false;
            }
            if (type == null) {
                type = toitsuType;
            }

            if (type != toitsuType) {
                return false;
            }
        }

        //順子がこれまでのTypeと違う場合false
        for (Shuntsu shuntsu : mentsuComp.getShuntsuList()) {
            if (type != shuntsu.getTile().getType()) {
                return false;
            }
        }

        //刻子がこれまでのTypeと違う場合false
        for (Kotsu kotsu : mentsuComp.getKotsuList()) {
            if (type != kotsu.getTile().getType()) {
                return false;
            }
        }

        //槓子がこれまでのTypeと違う場合false
        for (Kantsu kantsu : mentsuComp.getKantsuList()) {
            if (type != kantsu.getTile().getType()) {
                return false;
            }
        }

        return true;
    }
}

@@ -105,16 +105,40 @@
 eType;%0A%0A
+import java.util.List;%0A%0A
 import s
@@ -456,23 +456,17 @@
 tsuComp 
-mentsuC
+c
 omp;%0A%0A  
@@ -502,23 +502,17 @@
 tsuComp 
-mentsuC
+c
 omp) %7B%0A 
@@ -527,28 +527,16 @@
 his.
-mentsuComp = mentsuC
+comp = c
 omp;
@@ -732,100 +732,61 @@
     
+List%3C
 Mahjong
-TileType type = null;%0A        for (Toitsu toitsu : mentsuComp.getToitsuList()) %7B%0A    
+Mentsu%3E allMentsu = comp.getAllMentsu();%0A
     
@@ -809,27 +809,35 @@
 ype 
-toitsu
+first
 Type
- 
 = 
-toitsu
+allMentsu.get(0)
 .get
@@ -862,24 +862,29 @@
         
+%0A    
     if (
 toitsuTy
@@ -875,22 +875,21 @@
     if (
-toitsu
+first
 Type == 
@@ -898,22 +898,21 @@
 NPAI %7C%7C 
-toitsu
+first
 Type == 
@@ -925,36 +925,32 @@
 ) %7B%0A            
-    
 return false;%0A  
@@ -959,735 +959,167 @@
     
- 
-   %7D%0A            if (type == null) %7B%0A                type = toitsuType;%0A            %7D%0A%0A            if (type != toitsuType) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        //%E9%A0%86%E5%AD%90%E3%81%8C%E3%81%93%E3%82%8C%E3%81%BE%E3%81%A7%E3%81%AEType%E3%81%A8%E9%81%95%E3%81%86%E5%A0%B4%E5%90%88false%0A        for (Shu
+%7D%0A%0A        for (MahjongMe
 ntsu 
-shu
+me
 ntsu : 
-m
+allM
 entsu
-Comp.getShuntsuList()) %7B%0A            if (type != shuntsu.getTile().getType()) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        //%E5%88%BB%E5%AD%90%E3%81%8C%E3%81%93%E3%82%8C%E3%81%BE%E3%81%A7%E3%81%AEType%E3%81%A8%E9%81%95%E3%81%86%E5%A0%B4%E5%90%88false%0A        for (Kotsu kotsu : mentsuComp.getKotsuList()) %7B%0A            if (type != kotsu.getTile().getType()) %7B%0A                return false;%0A            %7D%0A        %7D%0A%0A        //%E6%A7%93%E5%AD%90%E3%81%8C%E3%81%93%E3%82%8C%E3%81%BE%E3%81%A7%E3%81%AEType%E3%81%A8%E9%81%95%E3%81%86%E5%A0%B4%E5%90%88false%0A        for (Kantsu kantsu : mentsuComp.getKantsuList()) %7B%0A            if (type != kantsu.getTile().getType()) 
+) %7B%0A            MahjongTileType checkType = mentsu.getTile().getType();%0A            if (firstType != checkType)
 %7B%0A  

refactor chinitsu resolver