//是否有连组合结构 private bool IsHasChainForUnit(int col, int row) { ElimateType unittype = ArrayUnit[col, row].Type; int horilen = 1; for (int i = col - 1; i >= 0 && ArrayUnit[i, row] != null && ArrayUnit[i, row].Type == unittype; i--, horilen++) { ; } for (int i = col + 1; i < Col_Max && ArrayUnit[i, row] != null && ArrayUnit[i, row].Type == unittype; i++, horilen++) { ; } if (horilen >= Min_Chain_Len) { return(true); } int vertlen = 1; for (int i = row - 1; i >= 0 && ArrayUnit[col, i] != null && ArrayUnit[col, i].Type == unittype; i--, vertlen++) { ; } for (int i = row + 1; i < Row_Max && ArrayUnit[col, i] != null && ArrayUnit[col, i].Type == unittype; i++, vertlen++) { ; } return(vertlen >= Min_Chain_Len); }
private ElimateUnit CreateElimateUnit(int col, int row, ElimateType etype) { ElimateUnit unit = new ElimateUnit(); unit.Type = etype; unit.Column = col; unit.Row = row; ArrayUnit[col, row] = unit; return(unit); }
public List <List <ElimateUnit> > TopElimateUnits() { List <List <ElimateUnit> > unitColumns = new List <List <ElimateUnit> >(); ElimateType et = ElimateType.ET_1; for (int col = 0; col < Col_Max; col++) { List <ElimateUnit> lis = null; for (int row = Row_Max - 1; row >= 0 && ArrayUnit[col, row] == null; row--) { if (ArrayTile[col, row] != null) { ElimateType newt; do { newt = ElimateUnit.RandomType(); }while (newt == et); //随机的类型 et = newt; //新单元 ElimateUnit unit = CreateElimateUnit(col, row, et); if (lis == null) { lis = new List <ElimateUnit>(); unitColumns.Add(lis); } lis.Add(unit); } } } return(unitColumns); }
private HashSet <ElimateChain> FindVerticalMatches() { HashSet <ElimateChain> chainset = new HashSet <ElimateChain>(); for (int col = 0; col < Col_Max; col++) { for (int row = 0; row < Row_Max; row++) { if (ArrayUnit[col, row] != null) { ElimateType matchtype = ArrayUnit[col, row].Type; if (ArrayUnit[col, row + 1] != null && ArrayUnit[col, row + 1].Type == matchtype && ArrayUnit[col, row + 2] != null && ArrayUnit[col, row + 2].Type == matchtype) { ElimateChain chain = new ElimateChain(); chain.ChainType = ElimateChainType.ECT_Vertical; do { chain.AddElimateUnit(ArrayUnit[col, row]); row += 1; }while (row < Row_Max && ArrayUnit[col, row] != null && ArrayUnit[col, row].Type == matchtype); chainset.Add(chain); continue; } row += 1; } } } return(chainset); }