예제 #1
0
 public Individual(int numberOfDays, int numberOfBlocks, int numberOfCourses, int numberOfLecturers, int numberOfRooms, int numberOfGroups)
 {
     Courses = InitializeChromosome(numberOfCourses, numberOfDays, numberOfBlocks);
     Lecturers = InitializeChromosome(numberOfLecturers, numberOfDays, numberOfBlocks);
     Rooms = InitializeChromosome(numberOfRooms, numberOfDays, numberOfBlocks);
     Groups = InitializeChromosome(numberOfGroups, numberOfDays, numberOfBlocks);
 }
예제 #2
0
        public override TimeSpan AccessRandom()
        {
            _storage = null;
            _storage = new int[DimensionSize, DimensionSize, DimensionSize];
            int dimensionMinusOne = DimensionSize - 1;

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            int counter = 0;
            bool bSwitch = false;
            for (int x = 0; x < DimensionSize; x++)
            {
                for (int y = 0; y < DimensionSize; y++)
                {
                    for (int z = 0; z < DimensionSize; z++)
                    {
                        if (bSwitch)
                        {
                            _storage[x, y, z] = counter;
                        }
                        else
                        {
                            _storage[dimensionMinusOne - x, dimensionMinusOne - y, dimensionMinusOne - z] = counter;
                        }
                        counter++;
                        bSwitch = !bSwitch;
                    }
                }
            }

            stopwatch.Stop();
            return stopwatch.Elapsed;
        }
예제 #3
0
파일: BlobData.cs 프로젝트: Zulban/viroid
 public int[,,] getMapData()
 {
     if (mapData != null)
         return mapData;
     mapData = genMapData ();
     return mapData;
 }
예제 #4
0
 //Create a map descriptor from a finished array of tile data
 public MapDescriptor(string mapID, int[,,] tiledata, int width, int height, int layers, double tileSize, double offsetX, double offsetY, string tileset)
     : this(mapID, width, height, layers, tileSize, offsetX, offsetY, tileset)
 {
     MapID = mapID;
     tiles = (int[,,])tiledata.Clone();
     Objects = new List<MapDescriptor.MapObject>();
 }
예제 #5
0
파일: World.cs 프로젝트: Reafexus/MapMaker
        public void ChangeWorldSize(int x, int y, int z)
        {
            width = x;
            height = y;
            depth = z;

            int[, ,] temp = new int[z, x, y];

            for (int i = 0; i < z && i < RoomInput.GetLength(0); i++)
            {
                for (int j = 0; j < x && j < RoomInput.GetLength(1); j++)
                {
                    for (int k = 0; k < y && k < RoomInput.GetLength(2); k++)
                    {
                        if (i < z && j < x && k < y)
                            temp[i, j, k] = RoomInput[i, j, k];
                        else
                            temp[i, j, k] = 0;

                    }
                }
            }

            RoomInput = temp;
        }
예제 #6
0
파일: Place.cs 프로젝트: dperetin/ProRa
 public Raspored(Raspored r)
 {
     sobe = (int[,,])r.sobe.Clone();
     profesori = (int[, ,])r.profesori.Clone();
     kolegiji = (int[, ,])r.kolegiji.Clone();
     grupe = (int[, ,])r.grupe.Clone();
     eventi = (int[, ])r.eventi.Clone();
     //kolegiji = (int[,])r.eventi.Clone();
     score = r.score;
     view = r.view;
 }
예제 #7
0
 public void init()
 {
     initialised=false;
     reductionFactor_x=1;
     reductionFactor_y=1;
     image=null;
     width=0;
     height=0;
     rotationLookup=null;
     OptimalNoOfFeatures=0;
     topFeature=null;
     currPolarRadius=0;
     polarLookup=null;
 }
        public void SetImageArray(object imageArray, int imageWidth, int imageHeight, SensorType sensorType)
        {
            this.imageArray = imageArray;
            this.imageWidth = imageWidth;
            this.imageHeight = imageHeight;
            this.sensorType = sensorType;

            objPixelArray = null;
            intPixelArray = null;
            intColourPixelArray = null;
            objColourPixelArray = null;

            if (sensorType == SensorType.Monochrome)
            {
                if (imageArray is int[,])
                {
                    intPixelArray = (int[,])imageArray;
                    isColumnMajor = intPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = intPixelArray.GetLength(0) == imageHeight;
                    return;
                }
                else if (imageArray is object[,])
                {
                    objPixelArray = (object[,])imageArray;
                    isColumnMajor = objPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = objPixelArray.GetLength(0) == imageHeight;
                    return;
                }
            }
            else
            {
                // Color sensor type is represented as 3-dimentional array that can be either: [3, height, width], [width, height, 3]
                if (imageArray is int[, ,])
                {
                    intColourPixelArray = (int[, ,])imageArray;
                    isColumnMajor = intColourPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = intColourPixelArray.GetLength(0) == 3;
                    return;
                }
                else if (imageArray is object[, ,])
                {
                    objColourPixelArray = (object[, ,])imageArray;
                    isColumnMajor = objColourPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = objColourPixelArray.GetLength(0) == 3;
                    return;
                }
            }

            throw new ArgumentException();
        }
예제 #9
0
        public RecognitionDataPacket()
        {
            rawDepthImage = null;
            correctedDepthImage = null;
            TableObjects = new List<TableObject>();
            HandObj = null;
            objectmap = null;
            neighbourmap = null;

            bmpCorrectedDepth = null;
            bmpRawDepth = null;
            bmpVideoFrame = null;

            RecognitionDuration = 0;
        }
예제 #10
0
        public override TimeSpan AccessSequental()
        {
            _storage = null;
            _storage = new int[DimensionSize, DimensionSize, DimensionSize];

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            int counter = 0;
            for (int x = 0; x < DimensionSize; x++)
            {
                for (int y = 0; y < DimensionSize; y++)
                {
                    for (int z = 0; z < DimensionSize; z++)
                    {
                        _storage[x, y, z] = counter;
                        counter++;
                    }
                }
            }

            stopwatch.Stop();
            return stopwatch.Elapsed;
        }
예제 #11
0
 public void SetDrops(int[,,] _drops)
 {
     drops = _drops;
 }
예제 #12
0
 public void SetMoves(int[,,] _moves)
 {
     moves = _moves;
 }
예제 #13
0
        static void Main(string[] args)
        {
            ThreeDimensionalArray tda = new ThreeDimensionalArray();

            int[,,] arr1 = tda.GenerationArray(); //Генерация первого массива
            int[,,] arr2 = tda.GenerationArray(); //Генерация второго массива
            int[,,] resArr;                       //Массив с резульатат

            Console.WriteLine("------------------------------------------------------------------------------");
            tda.WriteArray(arr1);
            Console.WriteLine("------------------------------------------------------------------------------");
            tda.WriteArray(arr2);
            Console.WriteLine("------------------------------------------------------------------------------");
            Console.WriteLine("Напиши число какое действие сделать с двумя рандомными массивами\n1) Сложить массивы\n2) Вычесть массивы\n3) Умножить массивы на число\n4) Опрелелить сумма какого массива больше");
            int value = Convert.ToInt16(Console.ReadLine());

            switch (value)
            {
            case 1:
                resArr = tda.SumArray(arr1, arr2);
                tda.WriteArray(resArr);
                break;

            case 2:
                Console.WriteLine("Введите число из какого массива вычитать другой массив\n 1) 1 - 2\n 2) 2 - 1");
                value = Convert.ToInt16(Console.ReadLine());
                if (value == 1)
                {
                    resArr = tda.DifferenceArrays(arr1, arr2);
                    tda.WriteArray(resArr);
                }
                else if (value == 2)
                {
                    resArr = tda.DifferenceArrays(arr2, arr1);
                    tda.WriteArray(resArr);
                }
                else
                {
                    Console.WriteLine("Не выбрана цифра");
                }
                break;

            case 3:
                Console.WriteLine("Введите массив который будет умножатся на число\n 1) 1 \n 2) 2 ");
                value = Convert.ToInt16(Console.ReadLine());
                if (value == 1)
                {
                    Console.WriteLine("Введите число для умножения");
                    int num = Convert.ToInt16(Console.ReadLine());
                    resArr = tda.MultiplicationArray(arr1, num);
                    tda.WriteArray(resArr);
                }
                else if (value == 2)
                {
                    Console.WriteLine("Введите число для умножения");
                    int num = Convert.ToInt16(Console.ReadLine());
                    resArr = tda.MultiplicationArray(arr2, num);
                    tda.WriteArray(resArr);
                }
                else
                {
                    Console.WriteLine("Не выбрана цифра");
                }
                break;

            case 4:
                int res1 = tda.ComparisonArrays(arr1);
                int res2 = tda.ComparisonArrays(arr2);
                if (res1 > res2)
                {
                    Console.WriteLine($"Сумма первого массива больше {res1} > {res2}");
                }
                else if (res2 < res1)
                {
                    Console.WriteLine($"Сумма второго массива больше {res2} < {res1}");
                }
                else if (res1 == res2)
                {
                    Console.WriteLine($"Сумма массивов равна {res1} = {res2}");
                }
                else
                {
                    Console.WriteLine("Ошибка!");
                }
                break;

            default:
                Console.WriteLine("Вы ввели число не от 1 до 4!");
                break;
            }
            Console.ReadLine();
        }
예제 #14
0
 public XBitmap(Bitmap _b)
 {
     bitarr = getImgArrFromBitmap(_b);
     Width = _b.Width;
     Height = _b.Height;
 }
예제 #15
0
 private static string RowOrderJoin(int[,,] array) => string.Join(", ", array.Cast <int> ());
예제 #16
0
 private void SetArray(int[,,] array, int index1, int index2, int index3, int value)
 {
     array[index1, index2, index3] = value;
     array[index3, index2, index1] = value;
 }
예제 #17
0
        // Generate point
        private void GeneratePoints()
        {
            int width = pointsPanel.ClientRectangle.Width;
            int height = pointsPanel.ClientRectangle.Height;
            int diameter = groupRadius * 2;

            // generate groups of ten points
            for (int i = 0; i < pointsCount; )
            {
                int cx = rand.Next(width);
                int cy = rand.Next(height);

                // generate group
                for (int j = 0; (i < pointsCount) && (j < 10); )
                {
                    int x = cx + rand.Next(diameter) - groupRadius;
                    int y = cy + rand.Next(diameter) - groupRadius;

                    // check if wee are not out
                    if ((x < 0) || (y < 0) || (x >= width) || (y >= height))
                    {
                        continue;
                    }

                    // add point
                    points[i, 0] = x;
                    points[i, 1] = y;

                    j++;
                    i++;
                }
            }

            map = null;
            pointsPanel.Invalidate();
            mapPanel.Invalidate();
        }
예제 #18
0
    private void setStart()
    {
        //only one collisionManager should be in progress at the same time for the whole scene
        isStarted = true;

        blobs = new ArrayList ();

        if (blobName1 == "main blob")
            blobName1 = worldManager.getMainBlobName ();
        blob1 = (BlobManager)worldManager.blobs [blobName1];
        blob2 = (BlobManager)worldManager.blobs [blobName2];

        blob1.setName (true);
        blob2.setName (true);
        if (newBlobManager != null)
            newBlobManager.setName (true);

        blobs.Add (blob2);

        if (isBlob2InsideBlob1) {
            //case: when blob2 collided with blob1, it was completely within blob1 bounds
            //Debug.Log ("inside collision");
            newBlobManager = blob1;

            iterPrism = blob2.genPrism ();
            combinedPrism = blob1.getPrism ();

            iterOffset = new IntVector3 (iterPrism.x - combinedPrism.x, iterPrism.y - combinedPrism.y, iterPrism.z - combinedPrism.z);

            //ZTools.show ("combinedPrism ", combinedPrism);
            newMapData = blob1.mapData;
            newVoxelGrid = blob1.voxels;
            newContagiousList = blob1.getContagiousList ();
        } else {
            //case: blob2 hit the outside of blob1. newblob bounds must become larger
            //Debug.Log ("outside collision");
            blobs.Add (blob1);
            iterPrism = getPrismFromBlobs (blob1, blob2);
            iterOffset = new IntVector3 (0, 0, 0);

            combinedPrism = iterPrism;
            newMapData = new int[iterPrism.width, iterPrism.height, iterPrism.depth];
            newVoxelGrid = new GameObject[iterPrism.width, iterPrism.height, iterPrism.depth];
            newContagiousList = new ArrayList ();
            newBlobManager.gameObject.transform.position = new Vector3 (iterPrism.x, iterPrism.y, iterPrism.z);
        }
        //ZTools.show("combined prism",combinedPrism);
    }
예제 #19
0
파일: Chunk.cs 프로젝트: nedearb/Laser
 private bool loadFromBytes(byte[] bytes)
 {
     TagCompound c = (TagCompound)TagBase.load(bytes);
     blockArray = ((Tag3dIntArray)c.data["blocks"]).data;
     return true;
 }
예제 #20
0
 //constructor
 public GameOfLife()
 {
     grid = CreateGrid();
 }
예제 #21
0
        public void Save(int worldNum, int situation = 0)
        {
            if (situation == 1)
            {
                level = Global.world;
                forceSave = true;
            }
            FileStream fs = new FileStream(Global.saveLoc + "World" + worldNum.ToString() + ".wld", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);

            for (int fsY = 0; fsY < Global.SIZE_Y; fsY++)
            {
                for (int fsX = 0; fsX < Global.SIZE_X; fsX++)
                {
                    if (fsX != Global.SIZE_X - 1)
                    {
                        sw.Write(level[fsX, fsY, 0] + ",");
                    }
                    else
                    {
                        sw.Write(level[fsX, fsY, 0]);
                    }
                }
                sw.WriteLine();
            }
            sw.WriteLine("---");
            // write all sorts of information
            // hp
            // difference.x
            // difference.y
            // smalldifference.x
            // smalldifference.y
            // inventory array
            try
            {
                sw.WriteLine(player.hitPoints);
            }
            catch
            {
                if (!forceSave)
                {
                    int temp = -1;
                    sw.WriteLine(temp);

                    sw.Close();
                    fs.Close();
                    return;
                }
                forceSave = false;
            }
            if (situation == 0)
            {
                Vector2 spawn = CalculateSpawn();

                spawn.X -= 30;
                spawn.Y -= 26;

                sw.WriteLine(spawn.X);
                sw.WriteLine(spawn.Y);
            }
            else
            {
                sw.WriteLine(area.difference.X);
                sw.WriteLine(area.difference.Y);
            }

            sw.WriteLine(area.smallDifference.X);
            sw.WriteLine(area.smallDifference.Y);

            for (int fsY = 0; fsY < 2; fsY++)
            {
                for (int fsX = 0; fsX < 18; fsX++)
                {
                    if (fsX != 18 - 1)
                    {
                        sw.Write(player.Inv[fsX, fsY] + ",");
                    }
                    else
                    {
                        sw.Write(player.Inv[fsX, fsY]);
                    }
                }
                sw.WriteLine();
            }

            sw.Close();
            fs.Close();
        }
 void initializeClasses()
 {
     _gridClass = transform.GetComponent<Gridmap>();
     _gridMap = _gridClass.gridMap;
 }
예제 #23
0
    public static void nextLevel()
    {

        stage++;
        numbers = MapDataArray.getData()[level - 1][stage - 1];
        if (numbers == null)
        {
            level++;
            stage = 0;
            numbers = MapDataArray.getData()[level - 1][stage - 1];
        }
    }
예제 #24
0
    // For demonstration purposes.
    public bool createShape()
    {
        // Add here shape creation code.
        cam.takeSnap();

        //call c++ code
        int hello = main ();
        int count = 0;
        string legoCode;
        while (hello == 1 && count < 4){
            print ("entering loop");

            cam.takeSnap();

            hello = main ();
            legoCode = Load("/Users/guyhowcroft/Documents/gameImages/result.txt");

            if(!checkString(legoCode)){
                print ("format is wrong");
                count ++;
                hello = 1;

                //waring SOUND plays when the piece is missread
                StartCoroutine(Wait2(1));
            }else{
                shape4 = getShapeArray(legoCode);

                //			shape4=getShapeArray("1.1.1.1.");
                //
                if(!checkPieces(shape4) && hello == 0){
                    print ("wrong shape oops");
                    count ++;
                    hello = 1;
                    StartCoroutine(Wait2(1));

                }
            }

        }

        //	StartCoroutine(Wait2(3));
        legoCode = Load("/Users/guyhowcroft/Documents/gameImages/result.txt");

        if(!checkString(legoCode)){
            print ("lego code before wrong = " + legoCode);
            print ("format is wrong");
            return false;
        }else{
            //	StartCoroutine(Wait2(1));
            print (legoCode);
            shape4 = getShapeArray(legoCode);   //If you're using the webcams to get the shape

            if(!checkPieces(shape4)){
                print ("wrong shape");
                print (xTime);
                return false;
            }else{
                print("right shape");
                xTime = 0;
                createShape(shape4);
            }
        }

        return true;

        //	shape4 = getShapeArray();   //If your using a hardcoded shape
        //		createShape(shape4);
        //	return true;
    }
예제 #25
0
        ////////////////
        //GAME DISPLAY//
        ////////////////

        public static void printTable(int[,,] table, Player player)
        {
            var title = new[]
            {
                @"      $$$$$$$\            $$\                                                                   $$\   $$\     ",
                @"      $$  __$$\           \__|                                                                  $$ |  $$ |    ",
                @"      $$ |  $$ |$$\   $$\ $$\  $$$$$$$\  $$$$$$$\  $$$$$$\  $$$$$$$\   $$$$$$$\  $$$$$$\        $$ |  $$ |    ",
                @"      $$$$$$$  |$$ |  $$ |$$ |$$_____  |$$_____|   \____$$\ $$  __$$\ $$  _____ |$$ __$$\       $$$$$$$$ |    ",
                @"      $$  ____ /$$ |  $$ |$$ |\$$$$$$\  \$$$$$$\   $$$$$$$ |$$ |  $$ |$$ /      $$$$$$$$ |      \_____$$ |    ",
                @"      $$ |      $$ |  $$ |$$ | \____$$\  \____$$\ $$  __$$ |$$ |  $$ |$$ |      $$   ____|            $$ |    ",
                @"      $$ |      \$$$$$$  |$$ |$$$$$$$  |$$$$$$$  |\$$$$$$$ |$$ |  $$ |\$$$$$$$\ \$$$$$$$\             $$ |    ",
                @"      \__|       \______/ \__|\_______/ \_______/  \_______|\__|  \__| \_______| \_______|            \__|    ",
                @"                                                                                                              ",
            };

            Console.SetCursorPosition(5, 0);
            Console.WindowWidth  = 110;
            Console.WindowHeight = 40;
            Console.WriteLine("\n\n");
            foreach (string line in title)
            {
                Console.WriteLine(line);
            }

            if (player.whichPlayer == "playerOne")
            {
                Console.SetCursorPosition(45, 12);
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write("PLAYER ONE TURN");
                Console.ResetColor();
            }
            else if (player.whichPlayer == "playerTwo")
            {
                Console.SetCursorPosition(45, 12);
                Console.BackgroundColor = ConsoleColor.Red;
                Console.Write("PLAYER TWO TURN");
                Console.ResetColor();
            }


            int counter = 14;

            for (int i = 0; i < table.GetLength(0); i++)
            {
                Console.SetCursorPosition(20, counter);
                for (int j = 0; j < table.GetLength(1); j++)
                {
                    if (table[i, j, 1] == 1)
                    {
                        Console.BackgroundColor = ConsoleColor.Blue;
                        Console.Write("|       |");
                        Console.ResetColor();
                    }
                    else if (table[i, j, 1] == -1)
                    {
                        Console.BackgroundColor = ConsoleColor.Red;
                        Console.Write("|       |");
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.Write("|       |", table[i, j, 0]);
                    }
                }
                counter += 4;
            }
        }
예제 #26
0
    // =====================================================================
    public void NewObjectMatrix()
    {
        // -----------------------------------------------------------------
        string _SIDE = OBJECT_SIDES[_GetRandom(0, 3)];
        string _TYPE = OBJECT_TYPES[_GetRandom(0, 7)];

        ObjMatrix = _Object.GetMatrixObject(_TYPE, _SIDE);
        // -----------------------------------------------------------------
    }
예제 #27
0
        /// <summary>
        /// Recreates a new grid array for the map at a new size.
        /// </summary>
        public void RebuildArray(Engine engine, Vector3 NewSize, Vector3 Shift)
        {
            foreach (Cube cube in engine.cubeManager.CubeList)
            {
                cube.AllPosition = cube.GridPosition + Shift;
            }

            int[, ,] _newArray = new int[(int)NewSize.X, (int)NewSize.Y, (int)NewSize.Z];

            int XM = Math.Min((int)NewSize.X, (int)Shift.X + Width);
            int YM = Math.Min((int)NewSize.Y, (int)Shift.Y + Depth);
            int ZM = Math.Min((int)NewSize.Z, (int)Shift.Z + Height);

            int XS = Math.Max((int)Shift.X, 0);
            int YS = Math.Max((int)Shift.Y, 0);
            int ZS = Math.Max((int)Shift.Z, 0);

            int xS = (int)Shift.X;
            int yS = (int)Shift.Y;
            int zS = (int)Shift.Z;

            for (int xx = XS; xx < XM; xx++)
            {
                for (int yy = YS; yy < YM; yy++)
                {
                    for (int zz = ZS; zz < ZM; zz++)
                    {
                        _newArray[xx, yy, zz] = GridArray[xx - xS, yy - yS, zz - zS];
                    }
                }
            }

            GridArray = _newArray;
            Width = (int)NewSize.X;
            Depth = (int)NewSize.Y;
            Height = (int)NewSize.Z;
        }
예제 #28
0
        public bool ReadData(string fileName)
        {
            m_hdfOperator.Close();
            m_L1file = fileName;
            m_hdfOperator.Open(fileName);

            m_EVInfo = m_hdfOperator.GetDatasetInfo("EV_RefSB", "/");
            m_EV = ReadEV();

            m_lonInfo = m_hdfOperator.GetDatasetInfo("Longitude", "/");
            m_lon = ReadLon();

            m_latInfo = m_hdfOperator.GetDatasetInfo("Latitude", "/");
            m_lat = ReadLat();

            m_calcoef = ReadCalcoefAttr();

            this.Update();

            return true;
        }
예제 #29
0
	/*
		    Any live cell with fewer than two live neighbours dies, as if caused by under-population.
			Any live cell with two or three live neighbours lives on to the next generation.
			Any live cell with more than three live neighbours dies, as if by over-population.
			Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction
	*/
	public virtual void updateLife() {
		counter = counter + 1;
		if (counter % timeDelay != 0) {
			return;
		}
		int numAliveNeighbors;
		int[,,] lifeFlagNew = (int[,,]) lifeFlag.Clone();

		for (int i = 0; i < numQuad; i++) {
			for (int j = 0; j < numQuad; j++) {
				for (int side = 0; side < numSide; side++) {
					numAliveNeighbors = getNumAliveNeighbors2(i,j,side);

					// set life flags
					if (numAliveNeighbors < 2) {
						lifeFlagNew [i, j, side] = 0;
					} else if (lifeFlag [i, j,side] == 1 & numAliveNeighbors > 3) {
						lifeFlagNew [i, j, side] = 0;
					} else if (lifeFlag [i, j,side] == 0 & numAliveNeighbors == 3) {
						lifeFlagNew [i, j,side] = 1;
					}
				}
			}
		}
		lifeFlag = lifeFlagNew;
	}
예제 #30
0
 public static void Main()
 {
     int[,,] i = { { { 0, 0, 0 }, { 1, 1, 1 } },
                   { {2 }, { 3, 3, 3 } } };
 }
예제 #31
0
    void InitPattern()
    {
        patterns           = new int[8, 6, 2];
        patterns [0, 0, 0] = 0;
        patterns [0, 0, 1] = 1;
        patterns [0, 1, 0] = 1;
        patterns [0, 1, 1] = 3;
        patterns [0, 2, 0] = 2;
        patterns [0, 2, 1] = 0;
        patterns [0, 3, 0] = 2;
        patterns [0, 3, 1] = 4;
        patterns [0, 4, 0] = 3;
        patterns [0, 4, 1] = 2;
        patterns [0, 5, 0] = 4;
        patterns [0, 5, 1] = 4;

        patterns [1, 0, 0] = 0;
        patterns [1, 0, 1] = 2;
        patterns [1, 1, 0] = 1;
        patterns [1, 1, 1] = 4;
        patterns [1, 2, 0] = 2;
        patterns [1, 2, 1] = 3;
        patterns [1, 3, 0] = 3;
        patterns [1, 3, 1] = 2;
        patterns [1, 4, 0] = 4;
        patterns [1, 4, 1] = 2;
        patterns [1, 5, 0] = 4;
        patterns [1, 5, 1] = 4;

        patterns [2, 0, 0] = 0;
        patterns [2, 0, 1] = 0;
        patterns [2, 1, 0] = 0;
        patterns [2, 1, 1] = 2;
        patterns [2, 2, 0] = 2;
        patterns [2, 2, 1] = 2;
        patterns [2, 3, 0] = 2;
        patterns [2, 3, 1] = 4;
        patterns [2, 4, 0] = 3;
        patterns [2, 4, 1] = 1;
        patterns [2, 5, 0] = 4;
        patterns [2, 5, 1] = 3;

        patterns [3, 0, 0] = 0;
        patterns [3, 0, 1] = 3;
        patterns [3, 1, 0] = 1;
        patterns [3, 1, 1] = 0;
        patterns [3, 2, 0] = 1;
        patterns [3, 2, 1] = 2;
        patterns [3, 3, 0] = 2;
        patterns [3, 3, 1] = 3;
        patterns [3, 4, 0] = 3;
        patterns [3, 4, 1] = 1;
        patterns [3, 5, 0] = 4;
        patterns [3, 5, 1] = 2;

        patterns [4, 0, 0] = 0;
        patterns [4, 0, 1] = 4;
        patterns [4, 1, 0] = 1;
        patterns [4, 1, 1] = 1;
        patterns [4, 2, 0] = 2;
        patterns [4, 2, 1] = 0;
        patterns [4, 3, 0] = 3;
        patterns [4, 3, 1] = 1;
        patterns [4, 4, 0] = 3;
        patterns [4, 4, 1] = 3;
        patterns [4, 5, 0] = 4;
        patterns [4, 5, 1] = 3;

        patterns [5, 0, 0] = 1;
        patterns [5, 0, 1] = 1;
        patterns [5, 1, 0] = 1;
        patterns [5, 1, 1] = 4;
        patterns [5, 2, 0] = 2;
        patterns [5, 2, 1] = 0;
        patterns [5, 3, 0] = 3;
        patterns [5, 3, 1] = 1;
        patterns [5, 4, 0] = 3;
        patterns [5, 4, 1] = 3;
        patterns [5, 5, 0] = 4;
        patterns [5, 5, 1] = 0;

        patterns [6, 0, 0] = 0;
        patterns [6, 0, 1] = 3;
        patterns [6, 1, 0] = 1;
        patterns [6, 1, 1] = 1;
        patterns [6, 2, 0] = 2;
        patterns [6, 2, 1] = 4;
        patterns [6, 3, 0] = 3;
        patterns [6, 3, 1] = 0;
        patterns [6, 4, 0] = 3;
        patterns [6, 4, 1] = 2;
        patterns [6, 5, 0] = 4;
        patterns [6, 5, 1] = 4;

        patterns [7, 0, 0] = 0;
        patterns [7, 0, 1] = 0;
        patterns [7, 1, 0] = 1;
        patterns [7, 1, 1] = 2;
        patterns [7, 2, 0] = 2;
        patterns [7, 2, 1] = 0;
        patterns [7, 3, 0] = 2;
        patterns [7, 3, 1] = 4;
        patterns [7, 4, 0] = 3;
        patterns [7, 4, 1] = 1;
        patterns [7, 5, 0] = 4;
        patterns [7, 5, 1] = 3;
    }
예제 #32
0
        private int AlgorithmSub(int[] boxes, int former, int latter, int repetition, int[,,] dp)
        {
            int originLatter = latter;

            for (; former < latter && boxes[latter] == boxes[latter - 1]; repetition++, latter--)
            {
                ;
            }
            int group = 0;

            if (latter - 1 >= 0)
            {
                if (dp[former, latter - 1, 0] > 0)
                {
                    group = dp[former, latter - 1, 0];
                }
                else if (former == latter - 1)
                {
                    group = 1;
                }
                else if (former < latter - 1)
                {
                    group = AlgorithmSub(boxes, former, latter - 1, 0, dp);
                }
            }

            int maxScore = (repetition + 1) * (repetition + 1) + group;

            for (int i = former; i < latter; i++)
            {
                circulateCount++;          //累计遍历次数
                if (boxes[i] == boxes[latter])
                {
                    int groupFormer = 0;
                    if (dp[former, i, repetition + 1] > 0)
                    {
                        groupFormer = dp[former, i, repetition + 1];
                    }
                    else if (former == i)
                    {
                        groupFormer = (repetition + 2) * (repetition + 2);
                    }
                    else if (former < i)
                    {
                        groupFormer = AlgorithmSub(boxes, former, i, repetition + 1, dp);
                    }
                    int groupLatter = 0;
                    if (dp[i + 1, latter - 1, 0] > 0)
                    {
                        groupLatter = dp[i + 1, latter - 1, 0];
                    }
                    else if (i + 1 == latter - 1)
                    {
                        groupLatter = 1;
                    }
                    else if (i + 1 < latter - 1)
                    {
                        groupLatter = AlgorithmSub(boxes, i + 1, latter - 1, 0, dp);
                    }

                    maxScore = Math.Max(maxScore, groupFormer + groupLatter);
                }
            }
            dp[former, latter, repetition] = maxScore;
            for (int i = latter + 1; i <= originLatter; i++)
            {
                dp[former, i, repetition + latter - i] = maxScore;
            }
            return(maxScore);
        }
예제 #33
0
 /// <summary>
 /// Метод для вывода на экран консоли значение элемента массива
 /// </summary>
 /// <param name="x">Строка</param>
 /// <param name="y">Столбец</param>
 /// <param name="z">Номер записи</param>
 /// <param name="array">Трехмерный массив</param>
 private static void ShowValArray(int x, int y, int z, int[,,] array)
 {
     Console.Write($"{array[x, y, z]} ");
 }
 public AbstractMapDrawer(int[,,] mMatrix)
 {
     Matrix = mMatrix;
 }
예제 #35
0
        /********************************************************************************************
         * 機能
         * 乱数で7種類のテトリスミノのうち何を発生させるか決めて、タイマが発生するたびに
         * ミノを一つ下げる
         *******************************************************************************************/
        public void MyClock(object sender, EventArgs e)
        {
            CchangeScreen screen = new CchangeScreen();
            CDrawFigure   figure = new CDrawFigure();
            CdeleteBlock  delete = new CdeleteBlock();

            /*if (MinoPos == 0 && flag ==false)
             * {
             *  screen.setScreen(CONST.START_MINO_POS, tempMinoPos, var_sell_status, temp_mino, temp_minoNumber);
             *  return;
             * }*/
            if (MinoPos_y != 0)
            {
                screen.deleteScreen(MinoPos_x, MinoPos_y - 1, var_sell_status, temp_mino, direction);
            }
            //1~7の乱数発生
            Random random = new System.Random();

            if (MinoPos_y == 0)
            {
                MinoPos_x = CONST.START_MINO_POS;
                minoNo    = random.Next(1, 8); //1から7の乱数を発生して、表示させるミノを決める
                //temp_minoNumber = minoNo;
                CLoad_block block = new CLoad_block();
                if (minoNo == 1)
                {
                    tetoris_mino = block.getTetorisMino1();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 2)
                {
                    tetoris_mino = block.getTetorisMino2();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 3)
                {
                    tetoris_mino = block.getTetorisMino3();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 4)
                {
                    tetoris_mino = block.getTetorisMino4();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 5)
                {
                    tetoris_mino = block.getTetorisMino5();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 6)
                {
                    tetoris_mino = block.getTetorisMino6();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 7)
                {
                    tetoris_mino = block.getTetorisMino7();
                    temp_mino    = new int[4, 4, 4];
                }
                else
                {
                    MessageBox.Show("何か想定外の数値が入力されました MyClock");
                    return;
                }
            }
            //MessageBox.Show(minoNo.ToString());

            //ミノが動けるとき画面を表示
            if (screen.checkBlockIsMove(MinoPos_x, MinoPos_y, var_sell_status, tetoris_mino, direction))
            {
                //ミノの画面への状態をセット
                screen.setScreen(MinoPos_x, MinoPos_y, var_sell_status, tetoris_mino, direction);

                //ミノが移動できるのでミノを描写する
                figure.DrawBlock(timer_graphics, var_sell_status);
                //前の画面の状態を保持
                this.setPreviousScreen(tetoris_mino, temp_mino, direction);
                tempMinoPos = MinoPos_y;
                MinoPos_y++;
            }
            else
            {
                //ミノが動けない、以前のミノを表示する
                screen.setScreen(MinoPos_x, MinoPos_y - 1, var_sell_status, tetoris_mino, direction);
                figure.DrawBlock(timer_graphics, var_sell_status);
                //ここに一行そろっていたら消す処理を入れる
                delete.deleteBlock(timer_graphics, var_sell_status);
                MinoPos_y = 0;
            }
        }
예제 #36
0
    static bool IsValid(Vector3 candidate, Vector3 sampleRegionSize, float cellSize, float radius, List <Vector3> points, int[,,] grid)
    {
        if (candidate.x >= 0 && candidate.x < sampleRegionSize.x && candidate.y >= 0 && candidate.y < sampleRegionSize.y && candidate.z >= 0 && candidate.z < sampleRegionSize.z)
        {
            int cellX = (int)(candidate.x / cellSize);
            int cellY = (int)(candidate.y / cellSize);
            int cellZ = (int)(candidate.z / cellSize);

            int searchStartX = Mathf.Max(0, cellX - 2);
            int searchEndX   = Mathf.Min(cellX + 2, grid.GetLength(0) - 1);

            int searchStartY = Mathf.Max(0, cellY - 2);
            int searchEndY   = Mathf.Min(cellY + 2, grid.GetLength(1) - 1);

            int searchStartZ = Mathf.Max(0, cellZ - 2);
            int searchEndZ   = Mathf.Min(cellZ + 2, grid.GetLength(2) - 1);

            for (int x = searchStartX; x <= searchEndX; x++)
            {
                for (int y = searchStartY; y <= searchEndY; y++)
                {
                    for (int z = searchStartZ; z <= searchEndZ; z++)
                    {
                        int pointIndex = grid[x, y, z] - 1;
                        if (pointIndex != -1)
                        {
                            float sqrDist = (candidate - points[pointIndex]).sqrMagnitude;
                            if (sqrDist < radius * radius)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        return(false);
    }
예제 #37
0
 private void button_decrypt_Click(object sender, EventArgs e)
 {
     int[,,] rgb             = GetRGBData(img);
     textBox_encryption.Text = decryption.process(rgb, img.Width, img.Height);
 }
예제 #38
0
 public void SetAttacks(int[,,] _attacks)
 {
     attacks = _attacks;
 }
예제 #39
0
    // Update is called once per frame
    void Update()
    {
        //rotate head :D
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            head.transform.Rotate(0, -0.5f, 0);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            head.transform.Rotate(0, 0.5f, 0);
        }
        if (Input.GetKey(KeyCode.UpArrow) && (head.transform.eulerAngles.x > 270 || head.transform.eulerAngles.x < 10))
        {
            head.transform.Rotate(-0.5f, 0, 0);
        }
        if (Input.GetKey(KeyCode.DownArrow) && (head.transform.eulerAngles.x >= 260 && head.transform.eulerAngles.x < 360))
        {
            head.transform.Rotate(0.5f, 0, 0);
        }

        //set init
        if (isDone == true)
        {
            dots[init_x, init_y, init_z].GetComponent <DotManage>().dotGenerate();
            dots[init_x, init_y, init_z].GetComponent <DotManage>().state = init;
            alives.Add(dots[init_x, init_y, init_z]);

            switch (dots[init_x, init_y, init_z].GetComponent <DotManage>().state)
            {
            case 0:
                dots[init_x, init_y, init_z].GetComponent <DotManage>().dotDestroy();
                deads.Add(dots[init_x, init_y, init_z]);
                break;

            case 1:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.red;
                break;

            case 2:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(1f, 0.64f, 0f);
                break;

            case 3:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.yellow;
                break;

            case 4:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.green;
                break;

            case 5:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.cyan;
                break;

            case 6:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(0.5f, 0f, 0.5f);
                break;

            default:
                dots[init_x, init_y, init_z].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(0, 0, 0);
                break;
            }

            isDone = false;
        }

        bar  = 4f / (bpm / 60f);
        beat = 1f / ((bpm / 60f) * 2f);

        if (isRun)
        {
            if (sequential)
            {
                follower.GetComponent <Renderer>().enabled = true;
            }
            else
            {
                follower.GetComponent <Renderer>().enabled = false;
            }

            //timeRecent += Time.deltaTime;
            timeRecent2 += Time.deltaTime;

            if (timeRecent == 0)
            {
                timeRecent++;

                cp_dots = new int[n, n, n];

                foreach (GameObject e in alives)
                {
                    DotManage temp = e.GetComponent <DotManage>();

                    if (temp.state < 6)
                    {
                        cp_dots[temp.x, temp.y, temp.z] += temp.state;
                    }

                    if (temp.state >= 6)
                    {
                        cp_dots[temp.x, temp.y, temp.z] += (temp.state - 6);
                        if (temp.x + 1 < n)
                        {
                            cp_dots[temp.x + 1, temp.y, temp.z]++;
                        }
                        if (temp.y + 1 < n)
                        {
                            cp_dots[temp.x, temp.y + 1, temp.z]++;
                        }
                        if (temp.z + 1 < n)
                        {
                            cp_dots[temp.x, temp.y, temp.z + 1]++;
                        }
                        if (temp.x - 1 >= 0)
                        {
                            cp_dots[temp.x - 1, temp.y, temp.z]++;
                        }
                        if (temp.y - 1 >= 0)
                        {
                            cp_dots[temp.x, temp.y - 1, temp.z]++;
                        }
                        if (temp.z - 1 >= 0)
                        {
                            cp_dots[temp.x, temp.y, temp.z - 1]++;
                        }
                    }
                }

                alives.Clear();

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        for (int k = 0; k < n; k++)
                        {
                            dots[i, j, k].GetComponent <DotManage>().state = cp_dots[i, j, k];

                            if (dots[i, j, k].GetComponent <DotManage>().state >= 0)
                            {
                                dots[i, j, k].GetComponent <DotManage>().dotGenerate();
                                alives.Add(dots[i, j, k]);

                                switch (dots[i, j, k].GetComponent <DotManage>().state)
                                {
                                case 0:
                                    dots[i, j, k].GetComponent <DotManage>().dotDestroy();
                                    deads.Add(dots[i, j, k]);
                                    break;

                                case 1:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.red;
                                    break;

                                case 2:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(1f, 0.64f, 0f);
                                    break;

                                case 3:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.yellow;
                                    break;

                                case 4:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.green;
                                    break;

                                case 5:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = Color.cyan;
                                    break;

                                case 6:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(0.5f, 0f, 0.5f);
                                    break;

                                default:
                                    dots[i, j, k].transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = new Color(0, 0, 0);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            //matlab_sound
            if (timeRecent2 >= beat && sequential)
            {
                time = time % n;

                if (time == 0)
                {
                    timeRecent = 0;
                }

                timeRecent2 = 0;

                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        int l;

                        //please dont change this part...
                        if (dots[j, k, time].GetComponent <DotManage>().isAlive)
                        {
                            switch (dots[j, k, time].GetComponent <DotManage>().state)
                            {
                            case 1:
                                l = 1;
                                break;

                            case 2:
                                l = 2;
                                break;

                            case 3:
                                l = 3;
                                break;

                            case 4:
                                l = 4;
                                break;

                            case 5:
                                l = 5;
                                break;

                            case 6:
                                l = 6;
                                break;

                            default:
                                l = 6;
                                break;
                            }

                            dots[j, k, time].GetComponent <AudioSource>().clip = sounds_matlab[j, k, time, l - 1];
                            dots[j, k, time].GetComponent <AudioSource>().Play();
                        }
                    }
                }

                //please dont change this part...
                follower.transform.localPosition = new Vector3(follower.transform.localPosition.x, follower.transform.localPosition.y, dots[0, 0, time].transform.localPosition.z);
                time++;
            }

            if (timeRecent2 >= (bar / 4.0) && !sequential)
            {
                timeRecent  = 0;
                timeRecent2 = 0;

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        for (int k = 0; k < n; k++)
                        {
                            int l;

                            if (dots[j, i, k].GetComponent <DotManage>().isAlive)
                            {
                                switch (dots[j, k, time].GetComponent <DotManage>().state)
                                {
                                case 1:
                                    l = 1;
                                    break;

                                case 2:
                                    l = 2;
                                    break;

                                case 3:
                                    l = 3;
                                    break;

                                case 4:
                                    l = 4;
                                    break;

                                case 5:
                                    l = 5;
                                    break;

                                case 6:
                                    l = 6;
                                    break;

                                default:
                                    l = 6;
                                    break;
                                }

                                dots[j, i, k].GetComponent <AudioSource>().clip = sounds_matlab[j, i, k, l - 1];
                                dots[j, i, k].GetComponent <AudioSource>().Play();
                            }
                        }
                    }
                }
            }
        }
        else
        {
            follower.GetComponent <Renderer>().enabled = false;
        }
    }
예제 #40
0
 public void setMap(int[,,] map)
 {
     levelTiles = map;
 }
예제 #41
0
        //绘图总调度
        public void DrawControl()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            设置ToolStripMenuItem.Enabled             = false; //绘图过程中不可修改参数
            开始ToolStripMenuItem.Enabled             = false;
            MaximizeBox = false;                             //绘图过程不可最大化
            labelTime.ResetText();

            pictureBox.Width  = imageWidth;
            pictureBox.Height = imageHeight;

            //调整横纵比例
            YminTemp = (Ymin + Ymax) / 2 - (Xmax - Xmin) * ((decimal)imageHeight / (decimal)imageWidth) / 2;
            YmaxTemp = (Ymin + Ymax) / 2 + (Xmax - Xmin) * ((decimal)imageHeight / (decimal)imageWidth) / 2;
            Ymin     = YminTemp;
            Ymax     = YmaxTemp;

            Creat_colorRound_table();                         //初始化“首尾相接”的色环数组!此色环非一般色环

            bitWidth  = (decimal)(Xmax - Xmin) / imageWidth;  //计算每个像素点所占实轴宽度
            bitHeight = (decimal)(Ymax - Ymin) / imageHeight; //计算每个像素点所占虚轴宽度

            bitmap = new Bitmap(imageWidth, imageHeight);     //构造像素矩阵

            DrawMandelbrot[] drawThreads = new DrawMandelbrot[threadTotal];
            Thread[]         threads     = new Thread[threadTotal];
            bitmapArray = new int[imageWidth, imageHeight, 3];

            threadLeft = threadTotal;


            System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间

            for (int i = 0; i < threadTotal; i++)
            {
                drawThreads[i]  = new DrawMandelbrot(i);
                threads[i]      = new Thread(drawThreads[i].ThreadProc);
                threads[i].Name = "绘图线程" + Convert.ToString(i);
                threads[i].Start();
            }

            while (threadLeft != 0)
            {
                Control.CheckForIllegalCrossThreadCalls = false;
                progressBar.Value = (progressBarValue * 100 / imageWidth) % 100;
            }

            for (int i = 0; i < MainForm.imageWidth; i++)
            {
                for (int j = 0; j < MainForm.imageHeight; j++)
                {
                    Color bitColor = Color.FromArgb(MainForm.bitmapArray[i, j, 0], MainForm.bitmapArray[i, j, 1], MainForm.bitmapArray[i, j, 2]);
                    MainForm.bitmap.SetPixel(i, j, bitColor);//这是最关键的函数,画点!
                }
            }

            pictureBox.Image = MainForm.bitmap;

            //提示音!!!!
            System.Media.SystemSounds.Asterisk.Play();

            //刷新放大倍数和参数窗口位置
            StatusLabel_mag.Text = "放大倍数:" + Convert.ToString((decimal)4.00 / ((MainForm.Xmax - MainForm.Xmin)));
            //滚动条归位
            progressBarValue  = 0;
            progressBar.Value = 0;

            设置ToolStripMenuItem.Enabled = true;
            MaximizeBox = true;
            开始ToolStripMenuItem.Enabled = true;


            stopwatch.Stop();                          //  停止监视
            TimeSpan timespan = stopwatch.Elapsed;     //  获取当前实例测量得出的总时间
            double   seconds  = timespan.TotalSeconds; //  总秒数

            labelTime.Text = "耗时" + Convert.ToString((int)(seconds)) + "秒";

            return;
        }
예제 #42
0
 // cref=”Espacio.Clase.Metodo(System.Int32, System.Int32@,
 // System.Int32*, System.Int32@,
 // System.Int32[][], System.Int32[0:, 0:, 0:])”
 int Metodo(int a, out int b, int *c, ref d, int[][] e, int[,,] f)
 {
     return(1);
 }
예제 #43
0
파일: Glue.cs 프로젝트: Civa/Zenith
 static Glue()
 {
     var parser = new GlueSettingsParser();
     glueTypes = parser.GetGlueTypes();
     glueRules = parser.GetGlueRules();
 }
예제 #44
0
 /// <summary>
 /// Метод присваивающий элементу трехмерного массива случайно целое число от -10 до 10
 /// </summary>
 /// <param name="x">Строка</param>
 /// <param name="y">Столбец</param>
 /// <param name="z">Номер записи</param>
 /// <param name="array">Трехмерный массив</param>
 private static void PutValueInItemArray(int x, int y, int z, int[,,] array)
 {
     array[x, y, z] = random.Next(-10, 10);
 }
예제 #45
0
파일: CubeController.cs 프로젝트: Cyua/Cubo
    void Start()
    {
        //initial Text Area
        audioCtrl = this.GetComponent<AudioSource> ();
        oriAttemptText = remAttemptText.text;
        remAttemptText.text = oriAttemptText + remAttempt;

        // load textures;
        for (int i = 0; i <= 9; i++)
            for (int j = 0; j <= 2; j++)
                hintTex[i, j] = LoadTex(i, j);

        initial_rotation = transform.rotation;
        levelNum = PlayerPrefs.GetInt ("level");

        string levelStr = "level" + levelNum;
        currentLevelText.text += levelNum;

        readInput (levelStr);
        current = shape;
        mx = returnMiddle (l)-1;  //calculate the middle point
        my = returnMiddle (h);
        mz = returnMiddle (w)-1;

        px = transform.position.x;  //parent's position
        py = transform.position.y;
        pz = transform.position.z;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int k = 0; k < l; k++) {
                    if (shape[i,j,k] == 1) {
                        cubes = Instantiate (instantiate, transform.position, transform.rotation) as GameObject;
                        cubes.transform.SetParent(this.transform,true);
                        cubes.transform.position = new Vector3(k-mx+px, h-i-my+py, j-mz+pz);
                        cubes.GetComponent<SingleCube>().SetHint(TransformHint(hintHL[i, k]),
                                                                 TransformHint(hintHW[i, j]),
                                                                 TransformHint(hintWL[j, k]));
                    }
                }
            }
        }
    }
예제 #46
0
 public void setTempMino(int[,,] temp_mino)
 {
     this.temp_mino = temp_mino;
 }
예제 #47
0
    void smoothLevel()
    {
        int[,,] gridCopy = new int[levelWidth, levelHeight, levelDepth];
        for (int width = 1; width < levelWidth - 1; width++)
        {
            for (int height = 1; height < levelHeight - 1; height++)
            {
                for (int depth = 1; depth < levelDepth - 1; depth++)
                {
                    int counter = 0;
                    if (grid[width, height, depth] > 0)
                    {
                        gridCopy[width, height, depth] = grid[width, height, depth];
                        if (grid[width + 1, height, depth] > 0)
                        {
                            counter++;
                        }
                        if (grid[width - 1, height, depth] > 0)
                        {
                            counter++;
                        }
                        if (grid[width, height + 1, depth] > 0)
                        {
                            counter++;
                        }
                        if (grid[width, height - 1, depth] > 0)
                        {
                            counter++;
                        }
                        if (grid[width, height, depth + 1] > 0)
                        {
                            counter++;
                        }
                        if (grid[width, height, depth - 1] > 0)
                        {
                            counter++;
                        }

                        if (counter <= 1)
                        {
                            gridCopy[width, height, depth] = 0;
                        }
                    }
                }
            }
        }

        for (int width = 1; width < levelWidth - 1; width++)
        {
            for (int height = 1; height < levelHeight - 1; height++)
            {
                for (int depth = 1; depth < levelDepth - 1; depth++)
                {
                    int        counter = 0;
                    List <int> blockt  = new List <int>();
                    blockt.Add(0); blockt.Add(0); blockt.Add(0); blockt.Add(0);
                    if (grid[width, height, depth] == 0)
                    {
                        if (grid[width + 1, height, depth] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width + 1, height, depth] - 1] += 1;
                        }
                        if (grid[width - 1, height, depth] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width - 1, height, depth] - 1] += 1;
                        }
                        if (grid[width, height + 1, depth] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width, height + 1, depth] - 1] += 1;
                        }
                        if (grid[width, height - 1, depth] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width, height - 1, depth] - 1] += 1;
                        }
                        if (grid[width, height, depth + 1] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width, height, depth + 1] - 1] += 1;
                        }
                        if (grid[width, height, depth - 1] > 0)
                        {
                            counter += ratio;
                            blockt[grid[width, height, depth - 1] - 1] += 1;
                        }
                        if (grid[width + 1, height + 1, depth] > 0)
                        {
                            counter++;
                            blockt[grid[width + 1, height + 1, depth] - 1] += 1;
                        }
                        if (grid[width + 1, height - 1, depth] > 0)
                        {
                            counter++;
                            blockt[grid[width + 1, height - 1, depth] - 1] += 1;
                        }
                        if (grid[width - 1, height + 1, depth] > 0)
                        {
                            counter++;
                            blockt[grid[width - 1, height + 1, depth] - 1] += 1;
                        }
                        if (grid[width - 1, height - 1, depth] > 0)
                        {
                            counter++;
                            blockt[grid[width - 1, height - 1, depth] - 1] += 1;
                        }
                        if (grid[width + 1, height, depth + 1] > 0)
                        {
                            counter++;
                            blockt[grid[width + 1, height, depth + 1] - 1] += 1;
                        }
                        if (grid[width + 1, height, depth - 1] > 0)
                        {
                            counter++;
                            blockt[grid[width + 1, height, depth - 1] - 1] += 1;
                        }
                        if (grid[width - 1, height, depth + 1] > 0)
                        {
                            counter++;
                            blockt[grid[width - 1, height, depth + 1] - 1] += 1;
                        }
                        if (grid[width - 1, height, depth - 1] > 0)
                        {
                            counter++;
                            blockt[grid[width - 1, height, depth - 1] - 1] += 1;
                        }
                        if (grid[width, height + 1, depth + 1] > 0)
                        {
                            counter++;
                            blockt[grid[width, height + 1, depth + 1] - 1] += 1;
                        }
                        if (grid[width, height + 1, depth - 1] > 0)
                        {
                            counter++;
                            blockt[grid[width, height + 1, depth - 1] - 1] += 1;
                        }
                        if (grid[width, height - 1, depth + 1] > 0)
                        {
                            counter++;
                            blockt[grid[width, height - 1, depth + 1] - 1] += 1;
                        }
                        if (grid[width, height - 1, depth - 1] > 0)
                        {
                            counter++;
                            blockt[grid[width, height - 1, depth - 1] - 1] += 1;
                        }

                        if (counter >= 60)
                        {
                            gridCopy[width, height, depth] = 1;
                            if (blockt[1] > blockt[0])
                            {
                                gridCopy[width, height, depth] = 2;
                            }
                            if (blockt[2] > blockt[0] && blockt[2] > blockt[1])
                            {
                                gridCopy[width, height, depth] = 3;
                            }
                            if (blockt[3] > blockt[2] && blockt[3] > blockt[1] && blockt[3] > blockt[0])
                            {
                                gridCopy[width, height, depth] = 4;
                            }
                        }
                    }
                }
            }
        }
        grid = gridCopy;
    }
예제 #48
0
        private void result_rgb_picture()
        {
            int[,,] rgb = GetRGBData(img);
            int[] result_r = new int[256];
            int[] result_g = new int[256];
            int[] result_b = new int[256];

            label_result_image_pixel.Text = img.Width + "x" + img.Height;
            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    result_r[rgb[x, y, 0]]++;
                    result_g[rgb[x, y, 1]]++;
                    result_b[rgb[x, y, 2]]++;
                }
            }
            int max_times = 0; //RGB最多次數

            for (int i = 0; i < 256; i++)
            {
                if (max_times < result_r[i])
                {
                    max_times = result_r[i];
                }
                if (max_times < result_g[i])
                {
                    max_times = result_g[i];
                }
                if (max_times < result_b[i])
                {
                    max_times = result_b[i];
                }
            }

            Bitmap img1 = new Bitmap(256, 100);
            Bitmap img2 = new Bitmap(256, 100);
            Bitmap img3 = new Bitmap(256, 100);

            for (int x = 0; x < img1.Width; x++)
            {
                for (int y = 0; y < (int)((result_r[x] / (float)max_times) * 100); y++)
                {
                    img1.SetPixel(x, img1.Height - 1 - y, Color.FromArgb(255, 0, 0));
                }
            }

            for (int x = 0; x < img2.Width; x++)
            {
                for (int y = 0; y < (int)((result_g[x] / (float)max_times) * 100); y++)
                {
                    img2.SetPixel(x, img2.Height - 1 - y, Color.FromArgb(0, 255, 0));
                }
            }

            for (int x = 0; x < img3.Width; x++)
            {
                for (int y = 0; y < (int)((result_b[x] / (float)max_times) * 100); y++)
                {
                    img3.SetPixel(x, img3.Height - 1 - y, Color.FromArgb(0, 0, 255));
                }
            }

            pictureBox_result_r.Image = img1;
            pictureBox_result_g.Image = img2;
            pictureBox_result_b.Image = img3;


            label_logcat.Text           = logcat_text;
            label_logcat.SelectionStart = label_logcat.Text.Length;
            label_logcat.ScrollToCaret();
        }
예제 #49
0
 private static unsafe extern int tecnod110(int[,,] nodelist);
예제 #50
0
파일: AStar.cs 프로젝트: haZya/8-Puzzle
        /// <summary>
        /// Expands a node
        /// </summary>
        /// <param name="square"></param>
        /// <param name="tempSquare"></param>
        /// <returns></returns>
        private int Expand(int[,] square, ref int[,,] tempSquare)
        {
            int b = -1, col = -1, row = -1, i, j, k;

            #region Create a three dimentional array capable of storing up to four expanded nodes
            // (Upto 4, due to the maximum amount of possible moves that can be made at once is 4)
            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < Puzzle.NUM_ROW; j++)
                {
                    for (k = 0; k < Puzzle.NUM_COL; k++)
                    {
                        // Add value of each position four times
                        tempSquare[i, j, k] = square[j, k];
                    }
                }
            }
            #endregion

            #region Find the row and column of the empty position
            for (i = 0; i < Puzzle.NUM_ROW; i++)
            {
                for (j = 0; j < Puzzle.NUM_COL; j++)
                {
                    if (square[i, j] == 0)
                    {
                        // Empty position
                        row = i;
                        col = j;
                        break;
                    }
                }
            }
            #endregion

            #region Expand the possible nodes, depending on the position of the empty piece
            if (row == 0 && col == 0)
            {
                #region Expand Position 1 (row = 0, col = 0), since it contains the empty piece
                // Expand to position 2 (row = 0, col = 1)
                tempSquare[0, 0, 0] = tempSquare[0, 0, 1];
                tempSquare[0, 0, 1] = 0;

                // Expand to position 4 (row = 1, col = 0)
                tempSquare[1, 0, 0] = tempSquare[1, 1, 0];
                tempSquare[1, 1, 0] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 2;
            }
            else if (row == 0 && col == 1)
            {
                #region Expand Position 2 (row = 0, col = 1), since it contains the empty piece
                // Expand to position 1 (row = 0, col = 0)
                tempSquare[0, 0, 1] = tempSquare[0, 0, 0];
                tempSquare[0, 0, 0] = 0;

                // Expand to position 5 (row = 1, col = 1)
                tempSquare[1, 0, 1] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;

                // Expand to position 3 (row = 0, col = 2)
                tempSquare[2, 0, 1] = tempSquare[2, 0, 2];
                tempSquare[2, 0, 2] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 3;
            }
            else if (row == 0 && col == 2)
            {
                #region Expand Position 3 (row = 0, col = 2), since it contains the empty piece
                // Expand to position 2 (row = 0, col = 1)
                tempSquare[0, 0, 2] = tempSquare[0, 0, 1];
                tempSquare[0, 0, 1] = 0;

                // Expand to position 6 (row = 1, col = 2)
                tempSquare[1, 0, 2] = tempSquare[1, 1, 2];
                tempSquare[1, 1, 2] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 2;
            }
            else if (row == 1 && col == 0)
            {
                #region Expand Position 4 (row = 1, col = 0), since it contains the empty piece
                // Expand to position 1 (row = 0, col = 0)
                tempSquare[0, 1, 0] = tempSquare[0, 0, 0];
                tempSquare[0, 0, 0] = 0;

                // Expand to position 5 (row = 1, col = 1)
                tempSquare[1, 1, 0] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;

                // Expand to position 7 (row = 2, col = 0)
                tempSquare[2, 1, 0] = tempSquare[2, 2, 0];
                tempSquare[2, 2, 0] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 3;
            }
            else if (row == 1 && col == 1)
            {
                #region Expand Position 5 (row = 1, col = 1), since it contains the empty piece
                // Expand to position 4 (row = 1, col = 0)
                tempSquare[0, 1, 1] = tempSquare[0, 1, 0];
                tempSquare[0, 1, 0] = 0;

                // Expand to position 2 (row = 0, col = 1)
                tempSquare[1, 1, 1] = tempSquare[1, 0, 1];
                tempSquare[1, 0, 1] = 0;

                // Expand to position 6 (row = 1, col = 2)
                tempSquare[2, 1, 1] = tempSquare[2, 1, 2];
                tempSquare[2, 1, 2] = 0;

                // Expand to position 8 (row = 2, col = 1)
                tempSquare[3, 1, 1] = tempSquare[3, 2, 1];
                tempSquare[3, 2, 1] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 4;
            }
            else if (row == 1 && col == 2)
            {
                #region Expand Position 6 (row = 1, col = 2), since it contains the empty piece
                // Expand to position 3 (row = 0, col = 2)
                tempSquare[0, 1, 2] = tempSquare[0, 0, 2];
                tempSquare[0, 0, 2] = 0;

                // Expand to position 5 (row = 1, col = 1)
                tempSquare[1, 1, 2] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;

                // Expand to position 9 (row = 2, col = 2)
                tempSquare[2, 1, 2] = tempSquare[2, 2, 2];
                tempSquare[2, 2, 2] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 3;
            }
            else if (row == 2 && col == 0)
            {
                #region Expand Position 7 (row = 2, col = 0), since it contains the empty piece
                // Expand to position 4 (row = 1, col = 0)
                tempSquare[0, 2, 0] = tempSquare[0, 1, 0];
                tempSquare[0, 1, 0] = 0;

                // Expand to position 8 (row = 2, col = 1)
                tempSquare[1, 2, 0] = tempSquare[1, 2, 1];
                tempSquare[1, 2, 1] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 2;
            }
            else if (row == 2 && col == 1)
            {
                #region Expand Position 8 (row = 2, col = 1), since it contains the empty piece
                // Expand to position 7 (row = 2, col = 0)
                tempSquare[0, 2, 1] = tempSquare[0, 2, 0];
                tempSquare[0, 2, 0] = 0;

                // Expand to position 5 (row = 1, col = 1)
                tempSquare[1, 2, 1] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;

                // Expand to position 9 (row = 2, col = 2)
                tempSquare[2, 2, 1] = tempSquare[2, 2, 2];
                tempSquare[2, 2, 2] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 3;
            }
            else if (row == 2 && col == 2)
            {
                #region Expand Position 9 (row = 2, col = 2), since it contains the empty piece
                // Expand to position 8 (row = 2, col = 1)
                tempSquare[0, 2, 2] = tempSquare[0, 2, 1];
                tempSquare[0, 2, 1] = 0;

                // Expand to position 6 (row = 1, col = 2)
                tempSquare[1, 2, 2] = tempSquare[1, 1, 2];
                tempSquare[1, 1, 2] = 0;
                #endregion

                // Set the number of nodes expanded
                b = 2;
            }
            #endregion

            return(b);
        }
예제 #51
0
    int[,,] generateMazeWithRecursiveDivision(int[,,] sectionedMaze, int startRowIndex, int endRowIndex, int startColIndex, int endColIndex)
    {
        //Recursive division
        //Random row and column for a wall
        //Put a hole in the wall for each and call function again on the smaller chambers
        if (startRowIndex + 1 >= endRowIndex || startColIndex + 1 >= endColIndex)
        {
            return(sectionedMaze);
        }
        if (startRowIndex + offset >= endRowIndex || startColIndex + offset >= endColIndex)
        {
            int randColWall1 = Random.Range(startColIndex, endColIndex - 1);
            int randRowWall1 = Random.Range(startRowIndex, endRowIndex - 1);

            for (int i = startColIndex; i < endColIndex + 1; i++)
            {
                sectionedMaze [randRowWall1, i, 2]     = 1;
                sectionedMaze [randRowWall1 + 1, i, 0] = 1;
            }
            for (int i = startRowIndex; i < endRowIndex + 1; i++)
            {
                sectionedMaze [i, randColWall1, 1]     = 1;
                sectionedMaze [i, randColWall1 + 1, 3] = 1;
            }
            int randColSlit1 = Random.Range(startColIndex, endColIndex);
            while (randColSlit1 == randRowWall1)
            {
                randColSlit1 = Random.Range(startColIndex, endColIndex);
            }
            sectionedMaze [randRowWall1, randColSlit1, 2]     = 0;
            sectionedMaze [randRowWall1 + 1, randColSlit1, 0] = 0;

            //2nd slit
            int randRowSlit1 = Random.Range(startRowIndex, endRowIndex);
            while (randRowSlit1 == randColWall1)
            {
                randRowSlit1 = Random.Range(startRowIndex, endRowIndex);
            }
            sectionedMaze [randRowSlit1, randColWall1, 1]     = 0;
            sectionedMaze [randRowSlit1, randColWall1 + 1, 3] = 0;

            //Getting 3rd slit
            if (Random.Range(0, 1) == 0)
            {
                if (randColSlit1 > randColWall1)
                {
                    int thirdSlit = Random.Range(startColIndex, randColWall1 - 1);
                    sectionedMaze [randRowWall1, thirdSlit, 2]     = 0;
                    sectionedMaze [randRowWall1 + 1, thirdSlit, 0] = 0;
                }
                else
                {
                    int thirdSlit = Random.Range(randColWall1 + 1, endColIndex + 1);
                    sectionedMaze [randRowWall1, thirdSlit, 2]     = 0;
                    sectionedMaze [randRowWall1 + 1, thirdSlit, 0] = 0;
                }
            }
            else
            {
                if (randRowSlit1 > randRowWall1)
                {
                    int thirdSlit = Random.Range(startRowIndex, randRowWall1 - 1);
                    sectionedMaze [thirdSlit, randColWall1, 1]     = 0;
                    sectionedMaze [thirdSlit, randColWall1 + 1, 3] = 0;
                }
                else
                {
                    int thirdSlit = Random.Range(randRowWall1 + 1, endRowIndex + 1);
                    sectionedMaze [thirdSlit, randColWall1, 1]     = 0;
                    sectionedMaze [thirdSlit, randColWall1 + 1, 3] = 0;
                }
            }

            return(sectionedMaze);
        }
        int randColWall = Random.Range(startColIndex + offset, endColIndex - 1 - offset);          //Put wall right of this column
        //		print("randColWall " + randColWall);
        int randRowWall = Random.Range(startRowIndex + offset, endRowIndex - 1 - offset);          //Put wall below this column

        //		print("randRowWall " + randRowWall);

        for (int i = startColIndex; i < endColIndex + 1; i++)
        {
            sectionedMaze [randRowWall, i, 2]     = 1;
            sectionedMaze [randRowWall + 1, i, 0] = 1;
        }
        for (int i = startRowIndex; i < endRowIndex + 1; i++)
        {
            sectionedMaze [i, randColWall, 1]     = 1;
            sectionedMaze [i, randColWall + 1, 3] = 1;
        }
        //1st slit
        int randColSlit = Random.Range(startColIndex, endColIndex);

        while (randColSlit == randRowWall)
        {
            randColSlit = Random.Range(startColIndex, endColIndex);
        }
        sectionedMaze [randRowWall, randColSlit, 2]     = 0;
        sectionedMaze [randRowWall + 1, randColSlit, 0] = 0;

        //2nd slit
        int randRowSlit = Random.Range(startRowIndex, endRowIndex);

        while (randRowSlit == randColWall)
        {
            randRowSlit = Random.Range(startRowIndex, endRowIndex);
        }
        sectionedMaze [randRowSlit, randColWall, 1]     = 0;
        sectionedMaze [randRowSlit, randColWall + 1, 3] = 0;

        //Getting 3rd slit
        if (Random.Range(0, 1) == 0)
        {
            if (randColSlit > randColWall)
            {
                int thirdSlit = Random.Range(startColIndex, randColWall - 1);
                sectionedMaze [randRowWall, thirdSlit, 2]     = 0;
                sectionedMaze [randRowWall + 1, thirdSlit, 0] = 0;
            }
            else
            {
                int thirdSlit = Random.Range(randColWall + 1, endColIndex + 1);
                sectionedMaze [randRowWall, thirdSlit, 2]     = 0;
                sectionedMaze [randRowWall + 1, thirdSlit, 0] = 0;
            }
        }
        else
        {
            if (randRowSlit > randRowWall)
            {
                int thirdSlit = Random.Range(startRowIndex, randRowWall - 1);
                sectionedMaze [thirdSlit, randColWall, 1]     = 0;
                sectionedMaze [thirdSlit, randColWall + 1, 3] = 0;
            }
            else
            {
                int thirdSlit = Random.Range(randRowWall + 1, endRowIndex + 1);
                sectionedMaze [thirdSlit, randColWall, 1]     = 0;
                sectionedMaze [thirdSlit, randColWall + 1, 3] = 0;
            }
        }
        sectionedMaze = generateMazeWithRecursiveDivision(sectionedMaze, startRowIndex, randRowWall, startColIndex, randColWall);
        sectionedMaze = generateMazeWithRecursiveDivision(sectionedMaze, randRowWall, endRowIndex, startColIndex, randColWall);
        sectionedMaze = generateMazeWithRecursiveDivision(sectionedMaze, startRowIndex, randRowWall, randColWall, endColIndex);
        sectionedMaze = generateMazeWithRecursiveDivision(sectionedMaze, randRowWall, endRowIndex, randColWall, endColIndex);
        return(sectionedMaze);
    }
예제 #52
0
 /// <summary>
 /// ぷよ種別を判定する
 /// </summary>
 /// <param name="ba">判定元画像のアクセサ</param>
 /// <param name="rect">判定に使用する範囲</param>
 /// <returns>判定されたぷよ種別</returns>
 public PuyoType Detect(RapidBitmapAccessor ba, Rectangle rect)
 {
     int[,,] pattern = GetPattern(ba, rect);
     return(GetPuyoType(pattern));
 }
    public override int NeighbourhoodCount(int[,,] currentCells)
    {
        int aliveNeighbours = 0;

        for (int row = -Order + SelectedRow; row <= SelectedRow + Order; row++)
        {
            for (int col = -Order + SelectedCol; col <= SelectedCol + Order; col++)
            {
                // ***** Non-Periodic Check *****
                if (!Periodic && row >= 0 && row < NumRows && col >= 0 && col < NumCols &&
                    Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    if (row == SelectedRow && col == SelectedCol)
                    {
                        if (CentreChecking)
                        {
                            if (currentCells[row, col, 0] == 1)
                            {
                                aliveNeighbours++;
                            }
                        }
                    }
                    else if (currentCells[row, col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // ***** Periodic Check *****
                // Periodic cases:
                // 1. Outside left side
                if (Periodic && row >= 0 && row < NumRows && col >= 0 && col < NumCols &&
                    Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    if (row == SelectedRow && col == SelectedCol)
                    {
                        if (CentreChecking)
                        {
                            if (currentCells[row, col, 0] == 1)
                            {
                                aliveNeighbours++;
                            }
                        }
                    }
                    else if (currentCells[row, col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }
                else if (Periodic && col < 0 && col < NumCols && row >= 0 && row < NumRows &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check cell that is x cells to the left from the right side of the grid
                    // NOTE: col will be a negative number
                    if (currentCells[row, NumCols + col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 2. Outside right side
                else if (Periodic && col >= NumCols && row >= 0 && row < NumRows &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check cell that is x cells to the left from the left side of the grid
                    if (currentCells[row, col - NumCols, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 3. Outside top side
                else if (Periodic && col >= 0 && col < NumCols && row >= 0 && row >= NumRows &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check cell that is x cells from the bottom of the grid
                    if (currentCells[row - NumRows, col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 4. Outside bottom side
                else if (Periodic && col >= 0 && col < NumCols && row < 0 &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check cell that is x cells from the top of the grid
                    // NOTE: row will be a negative number
                    if (currentCells[NumRows + row, col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 5. Outside top left corner
                else if (Periodic && col < 0 && row >= NumRows &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check bottom right corresponding cell based on location
                    // NOTE: col will be a negative number
                    if (currentCells[row - NumRows, NumCols + col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 6. Outside top right corner
                else if (Periodic && col >= NumCols && row >= NumRows &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check bottom right corresponding cell based on location
                    if (currentCells[row - NumRows, col - NumCols, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 7. Outside bottom left corner
                else if (Periodic && col < 0 && row < 0 &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check bottom right corresponding cell based on location
                    // NOTE: row and col will be negative numbers
                    if (currentCells[NumRows + row, NumCols + col, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }

                // 8. Outside bottom right corner
                else if (Periodic && col >= NumCols && row < 0 &&
                         Math.Abs(row - SelectedRow) + Math.Abs(col - SelectedCol) <= Order)
                {
                    // check bottom right corresponding cell based on location
                    // NOTE: row will be a negative number
                    if (currentCells[NumRows + row, col - NumCols, 0] == 1)
                    {
                        aliveNeighbours++;
                    }
                }
            }
        }

        return(aliveNeighbours);
    }
		// Generate point
		private void GeneratePoints( )
		{
			map = null;
		    mapPanel.BackgroundImage = null;
			mapPanel.Invalidate( );
		}
예제 #55
0
    //3 DIMENSIONS FUNCTIONS
    public static Queue<Point> Solve(int[,,] board, int x, int y, int z, int offset)
    {
        int height = board.GetLength(0);
        int width = board.GetLength(1);
        int length = board.GetLength(2);
        Queue<Point> output = new Queue<Point>();

        // Start = -1, Exit = -2, walls = -10

        int weight;
        Point coordinates;
        Queue<Point> next = new Queue<Point>();
        next.Enqueue(new Point(x, y, z));
        while (board[x, y, z] != -2)
        {
            coordinates = next.Dequeue();
            x = coordinates.x;
            y = coordinates.y;
            z = coordinates.z;

            if (board[x, y, z] != -10 && board[x, y, z] != -2)
            {
                weight = (board[x, y, z] == -1 ? 0 : board[x, y, z]);

                for (int i = -1; i < 2; i += 2)
                {
                    if (x + i >= 0 && x + i < height && board[x + i, y, z] <= 0)
                    {
                        next.Enqueue(new Point(x + i, y, z));
                        if (board[x + i, y, z] == 0)
                            board[x + i, y, z] = weight + 1;
                    }
                }

                for (int j = -1; j < 2; j += 2)
                {
                    if (y + j >= 0 && y + j < height && board[x, y + j, z] <= 0)
                    {
                        next.Enqueue(new Point(x, y + j, z));
                        if (board[x, y + j, z] == 0)
                            board[x, y + j, z] = weight + 1;
                    }
                }

                for (int k = -1; k < 2; k += 2)
                {
                    if (z + k >= 0 && z + k < length && board[x, y, z + k] <= 0)
                    {
                        next.Enqueue(new Point(x, y, z + k));
                        if (board[x, y, z + k] == 0)
                            board[x, y, z + k] = weight + 1;
                    }
                }

            }

            if (next.Count == 0)
                throw new ArgumentException("board has no solution");
        }

        //PrintArray(board);
        //Console.WriteLine();

        coordinates = new Point(x, y, z);

        while (board[x, y, z] != -1)
        {
            for (int i = -1; i < 2; i += 2)
            {
                if (x + i >= 0 && x + i < height)
                {
                    if (board[x + i, y, z] > 0 && board[x, y, z] == -2)
                        coordinates = new Point(x + i, y, z);
                    else if (board[x + i, y, z] > 0 && board[x + i, y, z] < board[coordinates.x, coordinates.y, coordinates.z])
                        coordinates = new Point(x + i, y, z);
                }
            }

            for (int j = -1; j < 2; j += 2)
            {
                if (y + j >= 0 && y + j < height)
                {
                    if (board[x, y + j, z] > 0 && board[x, y, z] == -2)
                        coordinates = new Point(x, y + j, z);
                    else if (board[x, y + j, z] > 0 && board[x, y + j, z] < board[coordinates.x, coordinates.y, coordinates.z])
                        coordinates = new Point(x, y + j, z);
                }
            }

            for (int k = -1; k < 2; k += 2)
            {
                if (z + k >= 0 && z + k < height)
                {
                    if (board[x, y, z + k] > 0 && board[x, y, z] == -2)
                        coordinates = new Point(x, y, z + k);
                    else if (board[x, y, z + k] > 0 && board[x, y, z + k] < board[coordinates.x, coordinates.y, coordinates.z])
                        coordinates = new Point(x, y, z + k);
                }
            }

            board[x, y, z] = -1;

            output.Enqueue(new Point(x - offset, y - offset, z - offset));

            x = coordinates.x;
            y = coordinates.y;
            z = coordinates.z;
        }

        //PrintArray(board);

        return output;
    }
예제 #56
0
        private int expand(int[, ,] tempSquare)
        {
            int b = -1, col = -1, i, j, k, row = -1;

            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < 4; j++)
                {
                    for (k = 0; k < 4; k++)
                    {
                        tempSquare[i, j, k] = square[j, k];
                    }
                }
            }
            for (i = 0; i < 4; i++)
            {
                for (j = 0; j < 4; j++)
                {
                    if (square[i, j] == 0)
                    {
                        row = i;
                        col = j;
                        break;
                    }
                }
            }
            if (row == 0 && col == 0)
            {
                tempSquare[0, 0, 0] = tempSquare[0, 0, 1];
                tempSquare[0, 0, 1] = 0;
                tempSquare[1, 0, 0] = tempSquare[1, 1, 0];
                tempSquare[1, 1, 0] = 0;
                b = 2;
            }
            else if (row == 0 && col == 1)
            {
                tempSquare[0, 0, 1] = tempSquare[0, 0, 0];
                tempSquare[0, 0, 0] = 0;
                tempSquare[1, 0, 1] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;
                tempSquare[2, 0, 1] = tempSquare[2, 0, 2];
                tempSquare[2, 0, 2] = 0;
                b = 3;
            }
            else if (row == 0 && col == 2)
            {
                tempSquare[0, 0, 2] = tempSquare[0, 0, 1];
                tempSquare[0, 0, 1] = 0;
                tempSquare[1, 0, 2] = tempSquare[1, 1, 2];
                tempSquare[1, 1, 2] = 0;
                tempSquare[2, 0, 2] = tempSquare[2, 0, 3];
                tempSquare[2, 0, 3] = 0;
                b = 3;
            }
            else if (row == 0 && col == 3)
            {
                tempSquare[0, 0, 3] = tempSquare[0, 0, 2];
                tempSquare[0, 0, 2] = 0;
                tempSquare[1, 0, 3] = tempSquare[1, 1, 3];
                tempSquare[1, 1, 3] = 0;
                b = 2;
            }
            else if (row == 1 && col == 0)
            {
                tempSquare[0, 1, 0] = tempSquare[0, 0, 0];
                tempSquare[0, 0, 0] = 0;
                tempSquare[1, 1, 0] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;
                tempSquare[2, 1, 0] = tempSquare[2, 2, 0];
                tempSquare[2, 2, 0] = 0;
                b = 3;
            }
            else if (row == 1 && col == 1)
            {
                tempSquare[0, 1, 1] = tempSquare[0, 1, 0];
                tempSquare[0, 1, 0] = 0;
                tempSquare[1, 1, 1] = tempSquare[1, 0, 1];
                tempSquare[1, 0, 1] = 0;
                tempSquare[2, 1, 1] = tempSquare[2, 1, 2];
                tempSquare[2, 1, 2] = 0;
                tempSquare[3, 1, 1] = tempSquare[3, 2, 1];
                tempSquare[3, 2, 1] = 0;
                b = 4;
            }
            else if (row == 1 && col == 2)
            {
                tempSquare[0, 1, 2] = tempSquare[0, 0, 2];
                tempSquare[0, 0, 2] = 0;
                tempSquare[1, 1, 2] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;
                tempSquare[2, 1, 2] = tempSquare[2, 2, 2];
                tempSquare[2, 2, 2] = 0;
                tempSquare[3, 1, 2] = tempSquare[3, 1, 3];
                tempSquare[3, 1, 3] = 0;
                b = 4;
            }
            else if (row == 1 && col == 3)
            {
                tempSquare[0, 1, 3] = tempSquare[0, 0, 3];
                tempSquare[0, 0, 3] = 0;
                tempSquare[1, 1, 3] = tempSquare[1, 1, 2];
                tempSquare[1, 1, 2] = 0;
                tempSquare[2, 1, 3] = tempSquare[2, 2, 3];
                tempSquare[2, 2, 3] = 0;
                b = 4;
            }
            else if (row == 2 && col == 0)
            {
                tempSquare[0, 2, 0] = tempSquare[0, 1, 0];
                tempSquare[0, 1, 0] = 0;
                tempSquare[1, 2, 0] = tempSquare[1, 2, 1];
                tempSquare[1, 2, 1] = 0;
                tempSquare[2, 2, 0] = tempSquare[2, 3, 0];
                tempSquare[2, 3, 0] = 0;
                b = 3;
            }
            else if (row == 2 && col == 1)
            {
                tempSquare[0, 2, 1] = tempSquare[0, 2, 0];
                tempSquare[0, 2, 0] = 0;
                tempSquare[1, 2, 1] = tempSquare[1, 1, 1];
                tempSquare[1, 1, 1] = 0;
                tempSquare[2, 2, 1] = tempSquare[2, 2, 2];
                tempSquare[2, 2, 2] = 0;
                tempSquare[3, 2, 1] = tempSquare[3, 3, 1];
                tempSquare[3, 3, 1] = 0;
                b = 4;
            }
            else if (row == 2 && col == 2)
            {
                tempSquare[0, 2, 2] = tempSquare[0, 2, 1];
                tempSquare[0, 2, 1] = 0;
                tempSquare[1, 2, 2] = tempSquare[1, 1, 2];
                tempSquare[1, 1, 2] = 0;
                tempSquare[2, 2, 2] = tempSquare[2, 2, 3];
                tempSquare[2, 2, 3] = 0;
                tempSquare[3, 2, 2] = tempSquare[3, 3, 2];
                tempSquare[3, 3, 2] = 0;
                b = 4;
            }
            else if (row == 2 && col == 3)
            {
                tempSquare[0, 2, 3] = tempSquare[0, 1, 3];
                tempSquare[0, 1, 3] = 0;
                tempSquare[1, 2, 3] = tempSquare[1, 2, 2];
                tempSquare[1, 2, 2] = 0;
                tempSquare[2, 2, 3] = tempSquare[2, 3, 3];
                tempSquare[2, 3, 3] = 0;
                b = 3;
            }
            else if (row == 3 && col == 0)
            {
                tempSquare[0, 3, 0] = tempSquare[0, 2, 0];
                tempSquare[0, 2, 0] = 0;
                tempSquare[1, 3, 0] = tempSquare[1, 3, 1];
                tempSquare[1, 3, 1] = 0;
                b = 2;
            }
            else if (row == 3 && col == 1)
            {
                tempSquare[0, 3, 1] = tempSquare[0, 2, 1];
                tempSquare[0, 2, 1] = 0;
                tempSquare[1, 3, 1] = tempSquare[1, 3, 0];
                tempSquare[1, 3, 0] = 0;
                tempSquare[2, 3, 1] = tempSquare[2, 3, 2];
                tempSquare[2, 3, 2] = 0;
                b = 3;
            }
            else if (row == 3 && col == 2)
            {
                tempSquare[0, 3, 2] = tempSquare[0, 2, 2];
                tempSquare[0, 2, 2] = 0;
                tempSquare[1, 3, 2] = tempSquare[1, 3, 1];
                tempSquare[1, 3, 1] = 0;
                tempSquare[2, 3, 2] = tempSquare[2, 3, 3];
                tempSquare[2, 3, 3] = 0;
                b = 3;
            }
            else if (row == 3 && col == 3)
            {
                tempSquare[0, 3, 3] = tempSquare[0, 2, 3];
                tempSquare[0, 2, 3] = 0;
                tempSquare[1, 3, 3] = tempSquare[1, 3, 2];
                tempSquare[1, 3, 2] = 0;
                b = 2;
            }
            return(b);
        }
예제 #57
0
 internal void Clear()
 {
     Courses = InitializeChromosome(Courses.GetLength(0), Courses.GetLength(1), Courses.GetLength(2));
     Lecturers = InitializeChromosome(Lecturers.GetLength(0), Courses.GetLength(1), Courses.GetLength(2));
     Rooms = InitializeChromosome(Rooms.GetLength(0), Courses.GetLength(1), Courses.GetLength(2));
     Groups = InitializeChromosome(Groups.GetLength(0), Courses.GetLength(1), Courses.GetLength(2));
 }