Beispiel #1
0
    public void visualizedData(List <SetMap> setMaps)
    {
        List <IndexOfList2D> emptyToMine = new List <IndexOfList2D>();
        List <IndexOfList2D> mineToEmpty = new List <IndexOfList2D>();

        foreach (var setMap in setMaps)
        {
            List2DInt mineData = Singleton.MainData.mineDatas;
            if (mineData[setMap.pos] == -1 && setMap.value != -1)
            {
                mineToEmpty.Add(setMap.pos);
            }
            else if (mineData[setMap.pos] != -1 && setMap.value == -1)
            {
                emptyToMine.Add(setMap.pos);
            }
        }
        GameObject gb = GameObject.Find("ChangeMapResult");

        if (gb == null)
        {
            gb = new GameObject("ChangeMapResult");
        }
        ShowPositions sp = gb.GetComponent <ShowPositions>();

        if (sp == null)
        {
            sp = gb.AddComponent <ShowPositions>();
        }
        sp.positionsList.Clear();
        sp.positionsList.Add(new ShowPositions.PositionProperty(emptyToMine, Color.green));
        sp.positionsList.Add(new ShowPositions.PositionProperty(mineToEmpty, Color.red));
        return;
    }
Beispiel #2
0
    void Awake()
    {
        var md = GameObject.Find("MainData");

        mineDatas = md.GetComponent <MainData>().mineDatas;
        var gamePart = md.GetComponent <GamePart>();

        flipBoard            = gamePart.flipBoard;
        map                  = new List2DInt(mineDatas.XSize, mineDatas.YSize, -1);
        insideMap            = new List2DInt(mineDatas.XSize, mineDatas.YSize, -1);
        numberList           = new SmartList <HCArea>();
        unFlipAreaList       = new SmartList <HCArea>();
        unFlipAreaInsideList = new SmartList <IndexOfList2D>();
        for (int i = 0; i < map.XSize; i++)
        {
            for (int j = 0; j < map.YSize; j++)
            {
                insideMap[i, j] = unFlipAreaInsideList.Add(new IndexOfList2D(i, j));
            }
        }
        gamePart.flipAction += ChangeMapByFlip;

        GameObject debugWithMap = new GameObject("Map");

        debugWithMap.transform.parent = transform;
        debugWithMap.AddComponent(typeof(WatchList2DInScene));
        debugWithMap.GetComponent <WatchList2DInScene>().list = map;
        debugWithMap = new GameObject("InsideMap");
        debugWithMap.transform.parent = transform;
        debugWithMap.AddComponent(typeof(WatchList2DInScene));
        debugWithMap.GetComponent <WatchList2DInScene>().list = insideMap;
    }
Beispiel #3
0
    public void StepInit()
    {
        if (happyCheck == null)
        {
            happyCheck = transform.parent.GetComponentInChildren <HappyCheck>();
        }
        happyCheck.resetNumbersValue();
        ufaMap         = new List2DInt(happyCheck.mineDatas.XSize, happyCheck.mineDatas.YSize, -1);
        watchList.list = ufaMap;
        ufaIndexes     = new int[happyCheck.unFlipAreaList.Count];
        numberCount    = happyCheck.numberList.Count;
        int index = 0;

        foreach (var ufa in happyCheck.unFlipAreaList)
        {
            ufaIndexes[index] = happyCheck.map[ufa.pos];
            ufaMap[ufa.pos]   = 0;
            index++;
        }
        stack        = new List <int>();
        happyMap     = new int[happyCheck.unFlipAreaList.Count];
        checkResults = new List <List <int> >();
        isHappy      = false;
        GameObject[] resultGbs = new GameObject[transform.childCount];
        sortIndex = 0;
        for (int i = 0; i < transform.childCount; i++)
        {
            resultGbs[i] = transform.GetChild(i).gameObject;
        }
        foreach (var resultGb in resultGbs)
        {
            Destroy(resultGb);
        }
    }
Beispiel #4
0
 public ChangeMap(IndexOfList2D _clickPos, Dictionary<ConnectedAreas, SearchForCa> _sfcas, PrecacTableBase _tableBase) {
     //Debug.Assert(_sfcas.Count != 0);
     clickPos = _clickPos;
     sfcas = _sfcas;
     mineData = Singleton.MainData.mineDatas;
     flipBoard = Singleton.GamePart.flipBoard;
     tableBase = _tableBase;
 }
Beispiel #5
0
 public void SetOutsideResult(ConnectedAreas ca, List<IndexOfList2D> target) {
     List2DInt map = Singleton.CreateNewList2DInt();
     foreach(var pos in target) {
         map[pos] = -1;
     }
     foreach(var area in ca.outsides) {
         result.Add(new SetMap(area.pos,map[area.pos]));
     }
 }
Beispiel #6
0
 public int CalculateDifference(ConnectedAreas ca, List<IndexOfList2D> mines) {
     int result = 0;
     List2DInt map = Singleton.CreateNewList2DInt();
     foreach(var pos in mines) {
         map[pos] = -1;
     }
     foreach(var area in ca.outsides) {
         if((map[area.pos] == -1 && mineData[area.pos] != -1 ) || (map[area.pos] != -1 && mineData[area.pos] == -1)) {
             result++;
         }
     }
     return result;
 }
Beispiel #7
0
 public void ChangeMapByFlip(List <FlipNode> flipNodes)
 {
     flipBoard = Singleton.GamePart.flipBoard;
     foreach (var node in flipNodes)
     {
         if (map[node.x, node.y] != -1)
         {
             var ufa = GetHCArea(node.x, node.y);
             foreach (var aroundNumber in ufa.neighbours)
             {
                 aroundNumber.neighbours.Remove(ufa);
                 if (aroundNumber.neighbours.Count == 0)
                 {
                     RemoveNumber(aroundNumber);
                 }
             }
             RemoveUnflipArea(ufa);
         }
         else
         {
             unFlipAreaInsideList.RemoveAt(insideMap[node.x, node.y]);
             insideMap[node.x, node.y] = -1;
         }
         List <HCArea> aroundUfa = new List <HCArea>();
         HCArea        number    = new HCArea(mineDatas[node.x, node.y], new IndexOfList2D(node.x, node.y), aroundUfa);
         flipBoard.ChangeAround(node.x, node.y,
                                (int x, int y, int get) => {
             if (get == 0)
             {
                 HCArea ufa = GetHCArea(x, y);
                 if (ufa == null)
                 {
                     ufa = new HCArea(-1, new IndexOfList2D(x, y), new List <HCArea>());
                     unFlipAreaInsideList.RemoveAt(insideMap[ufa.pos]);
                     insideMap[ufa.pos] = -1;
                     AddUnflipArea(ufa);
                 }
                 ufa.neighbours.Add(number);
                 aroundUfa.Add(ufa);
             }
             return(get);
         }
                                );
         if (aroundUfa.Count > 0)
         {
             AddNumber(number);
         }
     }
 }
Beispiel #8
0
 public MainData(int x, int y, float _step, Transform _transform, MainDataMB _mb)
 {
     mb           = _mb;
     areaGbs      = new List2DGameObject(0, 0, null);
     transform    = _transform;
     XSize        = x;
     YSize        = y;
     mineDatas    = new List2DInt(x, y, 0);
     areaGbs      = new List2DGameObject(x, y, null);
     step         = _step;
     originPrefab = Resources.Load <GameObject> ("Origin");
     foreach (var pos in areaGbs.Positions())
     {
         CreateNewGb(pos);
     }
 }
Beispiel #9
0
    public void CheckDead()
    {
        List2DInt deadMap      = new List2DInt(Singleton.MainData.XSize, Singleton.MainData.YSize, 0);
        int       outsideCount = ca.outsides.Count;

        foreach (var keyAndValue in searchResults)
        {
            foreach (var positions in keyAndValue.Value)
            {
                foreach (var position in positions)
                {
                    if (deadMap[position] == 0)
                    {
                        deadMap[position] = 1;
                        outsideCount--;
                    }
                }
            }
        }
        isDead = outsideCount == 0;
    }
Beispiel #10
0
    void Init()
    {
        var areaGbs = Singleton.MainData.areaGbs;

        flipBoard = new List2DInt(areaGbs.XSize, areaGbs.YSize, 0);
        areaViews = new List2D <AreaView>(areaGbs.XSize, areaGbs.YSize, null);
        for (int i = 0; i < areaGbs.XSize; i++)
        {
            for (int j = 0; j < areaGbs.YSize; j++)
            {
                areaViews[i, j] = areaGbs[i, j].GetComponentInChildren <AreaView>();
            }
        }
        beforesList = new List <List <AreaView> >();
        aftersList  = new List <List <AreaView> >();
        GameValid   = true;
        flipMine    = false;
        if (initAction != null)
        {
            initAction();
        }
    }
Beispiel #11
0
 public List2DInt(List2DInt otherList) : base(otherList)
 {
 }
Beispiel #12
0
    public void changeMineDataForHappy(IndexOfList2D clickPos)
    {
        List2DInt map = new List2DInt(Singleton.MainData.XSize, Singleton.MainData.YSize, 0);

        outsideUfas = new List <IndexOfList2D>();
        insideUfas  = new List <IndexOfList2D>();
        foreach (var ufa in happyCheck.unFlipAreaList)
        {
            outsideUfas.Add(ufa.pos);
        }
        foreach (var pos in happyCheck.unFlipAreaInsideList)
        {
            if (pos.x != clickPos.x || pos.y != clickPos.y)
            {
                insideUfas.Add(pos);
            }
        }
        List <int> trueResult       = null;
        var        results          = happyCheckStep.checkResults;
        int        needPutMineCount = 0;

        if (map[clickPos] != -1)
        {
            if (results.Count > 0)
            {
                for (int i = 0; i < results.Count; i++)
                {
                    needPutMineCount = Singleton.MainData.mineCount - results[i].Count;
                    if (needPutMineCount <= insideUfas.Count)
                    {
                        trueResult = results[i];
                        break;
                    }
                }
            }
            else
            {
                trueResult       = new List <int>();
                needPutMineCount = Singleton.MainData.mineCount;
            }
        }
        else
        {
            for (int i = 0; i < results.Count; i++)
            {
                var  result = results[i];
                bool flag   = true;
                foreach (int index in result)
                {
                    var ufa = happyCheckStep.GetUfa(index);
                    if (ufa.pos.x == clickPos.x && ufa.pos.y == clickPos.y)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    trueResult = result;
                }
            }
        }
        if (trueResult == null)
        {
            return;
        }
        foreach (int index in trueResult)
        {
            var ufa = happyCheckStep.GetUfa(index);
            map[ufa.pos] = -1;
        }
        for (int i = 0; i < needPutMineCount; i++)
        {
            IndexOfList2D pos = insideUfas[(int)(Random.Range(0, insideUfas.Count))];
            insideUfas.Remove(pos);
            map[pos] = -1;
        }
        watchList.list = map;
        var mainData = Singleton.MainData;

        foreach (var ufa in happyCheck.unFlipAreaList)
        {
            mainData.SetMineData(ufa.pos.x, ufa.pos.y, map[ufa.pos]);
        }
        foreach (var pos in happyCheck.unFlipAreaInsideList)
        {
            mainData.SetMineData(pos.x, pos.y, map[pos]);
        }
    }
Beispiel #13
0
 // Use this for initialization
 void Start()
 {
     flagMap = Singleton.CreateNewList2DInt();
     flagGbs = new List2DGameObject(Singleton.MainData.XSize, Singleton.MainData.YSize, null);
 }