Esempio n. 1
0
        public static void CalculerCycle()
        {
            //thread calcule old
            ArrayGPS.BackupTablesNumbers();
            //translate les tables utilises vers le haut
            ArrayGPS.CycleAdd();

            int tempSwap = IndexStorageSwapNew;

            IndexStorageSwapNew = IndexStorageSwapOld;
            IndexStorageSwapOld = IndexStorageSwapNow;
            IndexStorageSwapNow = tempSwap;

            _cycleStateAncient++;
            if (_cycleStateAncient == _memoryDistance)
            {
                ArrayGPS.pushAncient1();
                _cycleStateAncient = 0;
            }

            cycleSummary = 0;
            //calcule le nombre de cellule adjascent
            //divide by 4 thread
            tempTableauDeLaVieOld = TableauDeLaVie[ArrayGPS.SwapTablesOld];
            tempTableauDeLaVieNew = TableauDeLaVie[ArrayGPS.SwapTablesNew];

            for (int i = 0; i < threadNumber; i++)
            {
                threadArrayTable[i] = new Thread(CalculerCycleThread);
                threadArrayTable[i].Start(threadYCords[i]);
            }

            for (int i = 0; i < threadNumber; i++)
            {
                threadArrayTable[i].Join();
            }

            //set the cycle summaries in case there's a match
            cycleSummaries[ArrayGPS.SwapTablesNew] = cycleSummary;
        }
Esempio n. 2
0
        public static void GenerateNew(int memoryDistance = 1000, int nbAncientSummaries = 9, bool affichageChangement = false, double probabilite = 0.02, int tailleX = 800, int tailleY = 600, bool staleProof = false, bool verifyStale = false)
        {
            _verifyStale = verifyStale;

            if (nbAncientSummaries < 1)
            {
                nbAncientSummaries = 1;
            }
            _memoryDistance = memoryDistance;
            _cycleMemory    = nbAncientSummaries + 2;
            ArrayGPS.CycleReset(nbAncientSummaries + 2, nbAncientSummaries);
            AffichageChangement = affichageChangement;
            TableauDeLaVie      = new byte[nbAncientSummaries + 2][, ];
            for (int i = 0; i < nbAncientSummaries + 2; i++)
            {
                TableauDeLaVie[i] = new byte[tailleX, tailleY];
            }
            cycleMapTable1    = new int[tailleY][][];
            cycleSummaries    = new int[nbAncientSummaries + 2];
            cycleRowSummaries = new int[nbAncientSummaries + 2, tailleY];
            _tailleX          = tailleX;
            _tailleY          = tailleY;
            DonneeTables      = new Color[_tailleX * _tailleY];
            threadYCords      = new int[threadNumber][];
            threadArrayTable  = new Thread[threadNumber];
            //testcell threads math V2
            for (int i = 0, yRange = 0, memRange = 0; i < threadNumber; i++, yRange += (tailleY / threadNumber), memRange += (_cycleMemory / threadNumber))
            {
                threadYCords[i] = new int[5];

                threadYCords[i][0] = yRange;
                threadYCords[i][2] = yRange * _tailleX;
                threadYCords[i][3] = memRange;
                if (i == threadNumber - 1)
                {
                    threadYCords[i][1] = tailleY;
                    threadYCords[i][4] = _cycleMemory;
                }
                else
                {
                    threadYCords[i][1] = yRange + (tailleY / threadNumber);
                    threadYCords[i][4] = memRange + (_cycleMemory / threadNumber);
                }
            }

            tailleYMinus = _tailleY - 1;
            tailleXMinus = _tailleX - 1;
            Stale        = false;

            //instancie le tableau de valeurs
            for (int y = 0; y < tailleY; y++)
            {
                cycleMapTable1[y] = new int[tailleX][];
                for (int x = 0; x < tailleX; x++)
                {
                    cycleMapTable1[y][x] = new int[7];
                }
            }

            for (int y = 0; y < tailleY; y++)
            {
                for (int x = 0; x < tailleX; x++)
                {
                    bool yMax = y == tailleYMinus, xMax = x == tailleXMinus, yZero = y == 0, xZero = x == 0;
                    int  yMinus = y - 1, yPlus = y + 1, xMinus = x - 1, xPlus = x + 1;

                    cycleMapTable1[y][x][0] = xZero ? tailleXMinus : xMinus;
                    cycleMapTable1[y][x][1] = yZero ? tailleYMinus : yMinus;
                    cycleMapTable1[y][x][2] = xMax ? 0 : xPlus;
                    cycleMapTable1[y][x][3] = yMax ? 0 : yPlus;

                    if (structureNature)
                    {
                        bool   r = (generateur.NextDouble() <= 0.5);
                        int    direction = generateur.Next(0, 4);
                        double selectedIndex = ((double)generateur.Next(0, 100000)) / 100000, templatesSum = StructureMgr.StructureTemplatesNature.Sum(i => i.percentageChance);

                        if (selectedIndex < templatesSum)
                        {
                            double summaryT           = 0;
                            StructureTemplateNature i = null;

                            for (int g = 0; i == null && g < StructureMgr.StructureTemplatesNature.Count; g++)
                            {
                                summaryT += StructureMgr.StructureTemplatesNature[g].percentageChance;
                                if (summaryT > selectedIndex)
                                {
                                    i = StructureMgr.StructureTemplatesNature[g];
                                }
                            }

                            if (i != null && i.percentageChance > selectedIndex)
                            {
                                for (int f = 0; f < i.getHeight(direction); f++)
                                {
                                    for (int g = 0; g < i.getWidth(direction); g++)
                                    {
                                        if (i.getValue(direction, g, f, r) > 0)
                                        {
                                            setLife(g + x - i.getWidth(direction) / 2, f + y - i.getHeight(direction) / 2, i.getValue(direction, g, f, r) ?? 0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //todo
                    }
                }
            }

            //crée une copie initiale pour pas que l'affichage initial crée un erreur
            ArrayGPS.BackupTablesNumbers();
            generateImage();
        }