// This is executed by the Unity main thread when the job is finished
 protected override void OnFinished()
 {
     OutData = htmap;
     //Debug.Log("tileCreationThread.OutData: " + OutData.GetValue(0, 0));
     OutTileID = tileX.ToString() + ":" + tileZ.ToString();
     OutTerrainClassification = outTerrainClassification;
 }
    public void BuildLevel(Board board)
    {
        var children = new List<GameObject>();
        foreach (Transform child in transform)
            children.Add(child.gameObject);
        children.ForEach(child => Destroy(child));

        originalMatrix = board.Grid;
        matrix = PrepareMatrix(originalMatrix);
        int n = board.NoRooms;
        floors = new Floor[matrix.GetLength(0)-2,matrix.GetLength(1)-2];
        walls = new Wall[matrix.GetLength(0)-1, matrix.GetLength(1)-1];
        Rooms = new Room[n];
        graph = new Graph();
        for (int i = 0; i < n; ++i)
        {
            Rooms[i] = new Room(i+1, DefaultFloorMaterial);
        }
        RoomPropertiesPanel.InitializePanel(n);
        Vector3 shift = new Vector3(((matrix.GetLength(1) - 2) * unit) / 2, 0f, ((matrix.GetLength(0) - 2) * -unit) / 2);
        this.transform.position = shift;
        SpawnWalls();
        SpawnFloors();
        SpawnDoors();
        foreach (var room in Rooms)
        {
            room.SetRoomMaterial();
        }
        isSaved = false;
    }
        public void AddPlayer(TcpClient client)
        {
            //Caso já se tenha 02 jogadores, não pode mais entrar no servidor.
            if (ready)
                DisconnectPlayer(client);

            //Identificador do cliente
            int id = NextID();
            Console.WriteLine("Novo cliente entrou: " + id);

            //Cria Thread para cuidar do cliente.
            players[id] = new ClientProcessor(this, id, client);
            Thread thread = new Thread(players[id].Run);
            thread.Start();

            if (id + 1 >= MAX_PLAYERS)
            {
                ready = true;
                //Cria o contorno da parede e envia aos clientes.
                matrizJogo =  wall.CreateWallPhase01(matrizJogo);
                wall.SendToCLient(players, matrizJogo);

                // Cria a 1ª posicao da comida e envia ao cliente.
                matrizJogo = food.NewPosition(matrizJogo);
                food.SendToClient(matrizJogo, players);
            }
        }
        public Tetrominoe()
        {
            Random rnd = new Random();
            shape = tetrominoes[rnd.Next(0, 7)];
            for (int i = 23; i < 33; ++i)
            {
                for (int j = 3; j < 10; j++)
                {
                    Console.SetCursorPosition(i,j);
                    Console.Write("  ");
                }

            }
            Program.drawBorder();
            for (int i = 0; i < shape.GetLength(0); i++)
            {
                for (int j = 0; j < shape.GetLength(1); j++)
                {
                    if (shape[i, j] == 1)
                    {
                        Console.SetCursorPosition(((10 - shape.GetLength(1)) / 2 + j)*2+20, i+5);
                        Console.Write(Program.sqr);
                    }
                }
            }
        }
        private int _refresherY; //HAND coordinate

        #endregion Fields

        #region Constructors

        public Radar(Image imageBox)
        {
            ImageBox = imageBox;

            _bitmapWidth = (int)imageBox.Width;
            _bitmapHeight = (int)imageBox.Height;

            _offset = (_bitmapWidth - Constans.RADAR_WIDTH) / 2;

            //create Bitmap
            Bmp = new Bitmap(_bitmapHeight, _bitmapWidth);

            //center
            _centerX = (int)imageBox.Height / 2;
            _centerY = (int)imageBox.Width / 2;

            //initial degree of HAND
            _currentDegree = 0;

            //timer
            _timer.Interval = 1; //in millisecond
            _timer.Tick += ReloadRadar;

            _landscape = LandscapeProvider.CreateLandscape();

            //Draw start position of radar
            ReloadRadar(null, null);
        }
示例#6
0
 /// <summary>
 /// Oblicza ścieżkę dla obiektu.
 /// </summary>
 /// <param name="start">Punkt początkowy ścieżki</param>
 /// <param name="goal">Puntk docelowy</param>
 /// <param name="objectRadius">Promień kuli, która jest w stanie objąć cały obiekt</param>
 /// <param name="controllable">Obiekt, dla którego obliczana jest ścieżka</param>
 /// <param name="gameObjects">Lista wszystkich obiektów na planszy</param>
 public void FindPath(Point start, Point goal, int objectRadius, IControllable controllable, IEnumerable<GameObject> gameObjects)
 {
     msg = "";
     DateTime dateTime = DateTime.Now;
     if(!radiuses.Contains(objectRadius))
     {
         curProcessed = ProcessMap(map, objectRadius, out curAvgDifficulty);
         lastRadius = objectRadius;
         lock (maps)
         {
             radiuses.Add(lastRadius);
             avgDifficulties.Add(curAvgDifficulty);
             maps.Add(curProcessed);
         }
     }
     else
     {
         lastRadius = objectRadius;
         curProcessed = maps[radiuses.IndexOf(objectRadius)];
         curAvgDifficulty = avgDifficulties[radiuses.IndexOf(objectRadius)];
     }
     msg += (DateTime.Now - dateTime).ToString() + "\r\n";
     Thread th = new Thread(new ParameterizedThreadStart(AStar));
     pathTime = DateTime.Now;
     th.Start(new AStarArg(start,goal,controllable, gameObjects));
     //AStar(start, goal, out path);
 }
示例#7
0
    public void GameOfLife(int[,] board)
    {
        Board board2 = new Board (board);
        int row = board.GetLength (0);
        int col = board.GetLength (1);
        int[,] temp=new int[board.GetLength(0),board.GetLength(1)];

        for (int i=0; i<row; i++)
        for (int j=0; j<col; j++) {
            temp[i,j]=board[i,j];
        }
        for (int i=0; i<row; i++)
        for (int j=0; j<col; j++) {
            int count=board2.GetAdjacentPointCount(i,j);
            if(board[i,j]==1){
                if(count<2){//0 or 1
                    temp[i,j]=0;
                }
                else if(count<4){//2 or 3
                    temp[i,j]=1;
                }
                else if(count>3){//3,4,5,6,7,8
                    temp[i,j]=0;
                }
            }
            else if(count ==3){
                temp[i,j]=1;
            }
        }
        board = temp;
        b = temp;
    }
示例#8
0
 // Use this for initialization
 void Start()
 {
     maze = new int[height, width];
     maze = generateMaze();
     correctMaze();
     render();
 }
示例#9
0
        public Enemy(SpriteBatch _s, GraphicsDevice _g, int _enemyNo, int mapno,int _chUP)
        {
            s = _s;
            g = _g;
            //map = _map;

            HP = enemystat[_enemyNo, 0] * _chUP;
            ATC = enemystat[_enemyNo, 1];
            SPD = enemystat[_enemyNo, 2];
            DRP = enemystat[_enemyNo, 3];
            No = enemystat[_enemyNo, 4];
            DEF = enemystat[_enemyNo, 5];

            FileStream stream = File.OpenRead("Content/images/enemy" + No + ".png");
            imgEnemy = Texture2D.FromStream(_g, stream);

            switch (mapno)
            {
                case 0:
                    pos.X = mapStartpos0[1];
                    pos.Y = mapStartpos0[2];
                    map = mapEnemyRoute0;
                    break;
                case 1:
                    pos.X = mapStartpos1[1];
                    pos.Y = mapStartpos1[2];
                    map = mapEnemyRoute1;
                    break;
                case 2:
                    pos.X = mapStartpos2[1];
                    pos.Y = mapStartpos2[2];
                    map = mapEnemyRoute2;
                    break;
                case 3:
                    pos.X = mapStartpos3[1];
                    pos.Y = mapStartpos3[2];
                    map = mapEnemyRoute3;
                    break;
                case 4:
                    pos.X = mapStartpos4[1];
                    pos.Y = mapStartpos4[2];
                    map = mapEnemyRoute4;
                    break;
                case 5:
                    pos.X = mapStartpos5[1];
                    pos.Y = mapStartpos5[2];
                    map = mapEnemyRoute5;
                    break;
                case 6:
                    pos.X = mapStartpos6[1];
                    pos.Y = mapStartpos6[2];
                    map = mapEnemyRoute6;
                    break;
                case 7:
                    pos.X = mapStartpos7[1];
                    pos.Y = mapStartpos7[2];
                    map = mapEnemyRoute7;
                    break;
            }
        }
示例#10
0
    public void CalculateGameOfLife(int[,] array)
    {
        board = new Board (array);
        row = array.GetLength (0);
        col = array.GetLength (1);
        int[,] temp=new int[array.GetLength(0),array.GetLength(1)];

        for (int i=0; i<row; i++)
        for (int j=0; j<col; j++) {
            temp[i,j]=array[i,j];
        }
        for (int i=0; i<row; i++)
        for (int j=0; j<col; j++) {
            int count=board.GetAdjacentPointCount(i,j);
            if(array[i,j]==1){
                if(count<2){//0 or 1
                    temp[i,j]=0;
                }
                else if(count<4){//2 or 3
                    temp[i,j]=1;
                }
                else if(count>3){//3,4,5,6,7,8
                    temp[i,j]=0;
                }
            }
            else if(count ==3){
                temp[i,j]=1;
            }
        }
        array = temp;
        mArray = temp;
    }
示例#11
0
    public Matrix(int[,] matrixToInitialize)
    {
        rowsCount = matrixToInitialize.GetLength(0);
        colsCount = matrixToInitialize.GetLength(1);

        matrix = (int[,]) matrixToInitialize.Clone();
    }
    public void multiply(Matrix multipliedMatrix)
    {
        if (multipliedMatrix.getLength(0) != matrix.GetLength(1))
        {
            throw new IndexOutOfRangeException();
        }

        Matrix newMatrix = new Matrix(matrix.GetLength(0), multipliedMatrix.getLength(1));

        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < multipliedMatrix.getLength(1); col++)
            {
                int result = 0;
                for (int multipliedRow = 0; multipliedRow < matrix.GetLength(1); multipliedRow++)
                {
                    result += matrix[row, multipliedRow] * multipliedMatrix.get(multipliedRow, col);
                }

                newMatrix.set(row, col, result);
            }
        }

        matrix = newMatrix.getMatrix();
    }
示例#13
0
 public void Setup()
 {
     problem = new Problem11();
     pattern = new[,]
                   {
                       {08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08},
                       {49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00},
                       {81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65},
                       {52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91},
                       {22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80},
                       {24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50},
                       {32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70},
                       {67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21},
                       {24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72},
                       {21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95},
                       {78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92},
                       {16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57},
                       {86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58},
                       {19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40},
                       {04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66},
                       {88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69},
                       {04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36},
                       {20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16},
                       {20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54},
                       {01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48}
                   };
 }
示例#14
0
文件: Level.cs 项目: endy/OgmoXNA
 public Level(OgmoLevel level)
 {
     // Get the loaded grid data and use it for a collision layer.
     collisionGrid = level.GetLayer<OgmoGridLayer>("floors").RawData;
     // Create tiles from some tile layer data.
     foreach (OgmoTile tile in level.GetLayer<OgmoTileLayer>("tiles_bg").Tiles)
         tiles.Add(new Tile(tile, false));
     // Create more tiles from some more tile layer data.
     foreach (OgmoTile tile in level.GetLayer<OgmoTileLayer>("tiles_floors").Tiles)
         tiles.Add(new Tile(tile, true));
     // Create our objects from the object layer data.
     foreach (OgmoObject obj in level.GetLayer<OgmoObjectLayer>("objects").Objects)
     {
         if (obj.Name.Equals("ogmo"))
         {
             Ogmo ogmo = new Ogmo(obj, this);
             ogmo.Destroy += new EventHandler(ogmo_Destroy);
             allObjects.Add(ogmo);
             this.ogmo = ogmo;
         }
         if (obj.Name.Equals("chest"))
         {
             Chest chest = new Chest(obj, this);
             chest.Destroy += new EventHandler(DoDestroy);
             allObjects.Add(chest);
         }
         if (obj.Name.Equals("moving_platform"))
             allObjects.Add(new MovingPlatform(obj, this));
         if (obj.Name.StartsWith("spike"))
             allObjects.Add(new Spike(obj, this));
     }
 }
示例#15
0
        // Geneartes the whole floor but calls on the generate room method to actually place the individual tiles.
        public void generateFloor()
        {
            currentMinimap = gameMap.getMap();
            for (int y = 0; y < gameMap.maxHeight; y++)
            {
                int yMod = 1;
                int xMod = 1;

                for (int x = 0; x < gameMap.maxWidth; x++)
                {
                    switch(currentMinimap[x, y])
                    {
                        case 0:
                            generateBlankRoom(xMod, yMod);
                            break;
                        case 1:
                            GenerateRoom(xMod, yMod);
                            break;
                        default:
                            // Generate Blank stuff shaded red
                            break;
                    }
                    xMod++;
                }
                yMod++;
            }
        }
示例#16
0
        //Ajoute un sommet isolé
        public void addEdge(char Edge)
        {
            int[,] newtab;

            if (this.info.IndexOf(Edge) == -1)
            {
                newtab = new int[taille + 1, taille + 1];

                for (int ligne = 0; ligne < this.taille; ligne++)
                {
                    for (int colonne = 0; colonne < this.taille; colonne++)
                    {
                        newtab[ligne, colonne] = this.tab[ligne, colonne];
                    }
                }

                for (int i = 0; i < this.taille + 1; i++)
                {
                    newtab[this.taille, i] = 0;
                    newtab[i, this.taille] = 0;
                }

                this.taille = this.taille + 1;
                this.tab = newtab;
                this.info.Add(Edge);
            }
            else { Console.WriteLine("Impossible d'ajouter " + Edge + ", un sommet du même nom existe déjà !"); }
        }
示例#17
0
        internal static List<Actor> mapLoad(string toLoad)
        {
            switch (toLoad)
            {
                case "test": default:
                    int[,] temp = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                                    {0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 },
                                    {0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
                                    {0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
                                    {0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0 },
                                    {0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0 },
                                    {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
                                    {0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
                                    {0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
                                    {0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
                                    {0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
                                    {0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0 },
                                    {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 },
                                    {0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0 },
                                    {0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0 },
                                    {0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
                                    {0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
                                    {0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 10, 1, 0 },
                                    {0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
                                    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};

                    map = temp;
                    break;
            }

            return generateModels();
        }
示例#18
0
        public Mapa()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            paintTablero = new GrupoPaint(new PintaEventHandler[] {
                PintarTableroPart1,
                PintarTableroPart2,
                PintarTableroPart3,
                PintarTableroPart4,
                PintarFichas
            }){ Dock = DockStyle.Fill };
            for (int i = 0; i < 4; i++) {
                paintTablero.Controls[i].Dock = DockStyle.None;
                paintTablero.Controls[i].Size = new Size(Width / 2, Height / 2);
            }
            paintTablero.Controls[0].Location = new Point(0, 0);
            paintTablero.Controls[1].Location = new Point(Width / 2, 0);
            paintTablero.Controls[2].Location = new Point(0, Height / 2);
            paintTablero.Controls[3].Location = new Point(Width / 2, Height / 2);
            mapaAPintar = ZinLock.TableroZinLock.MAPAVACIO;
            ResetPosiciones();
            Controls.Add(paintTablero);
            paintTablero.RefreshAll();
            paintTablero.MouseClick += ClickEvent;
            paintTablero.BringToFront();
        }
        public FiguresExtractor(Bitmap bunarizeImage)
        {
            _pixelArray = new Core.BitImage(bunarizeImage).PixelArray;

            _lines = HoughTransform.GetLines(_pixelArray);
            _circles = HoughTransform.GetCircles(_pixelArray);
        }
示例#20
0
文件: Map.cs 项目: Woktopus/Acllacuna
 public void LoadContent(ContentManager Content,World world)
 {
     pars.LoadContent(Content);
     map = pars.tabMap();
     for (int i = 0; i <= map.GetLength(0)-1; i++)
     {
         for (int j = 0; j <= map.GetLength(1)-1; j++)
         {
             if (map[i,j] < 0)
             {                        
                     Block b = new Block();
                     b.LoadContent(world, new Vector2(2, 2), new Vector2((i * 2) + 1, (j * 2) + 1), Content, mondico[Math.Abs(map[i, j])], false);
                     listBlock.Add(b);
             } else if (map[i, j] > 0) {
                 if (map[i, j] >=3 && map[i, j]<=6)
                 {
                     Spike s = new Spike();
                     s.LoadContent(Content, world, new Vector2(1.50f, 1.50f), new Vector2((i * 2) + 1, (j * 2) + 1), mondico[Math.Abs(map[i, j])]);
                     listSpike.Add(s);
                 }
                 else
                 {
                     Block b = new Block();
                     b.LoadContent(world, new Vector2(2, 2), new Vector2((i * 2) + 1, (j * 2) + 1), Content, mondico[Math.Abs(map[i, j])], true);
                     listBlock.Add(b);
                 }
             }
         }
     }
 }
    //Populates the floor with enemies
    public void populateFloor()
    {
        tileMap = GameObject.FindGameObjectWithTag("TileMap").GetComponent<TileMap>();
        rooms = tileMap.getRooms();

        //Try to spawn enemies in each room
        for (int i = 0; i < 7; i++)
        {
            for(int j = 0; j < 7; j++)
            {
                if(rooms[i,j] == 1)
                {
                    int spawnCheck = Random.Range(0, 2);
                    if(spawnCheck == 0)
                    {
                        float spawnX = transform.position.x + i * 5 + 2;
                        float spawnZ = transform.position.z + j * 5 + 2;

                        GameObject tempEnemyRef = (GameObject)GameObject.Instantiate(enemy, new Vector3(spawnX, 1, spawnZ), Quaternion.identity);
                        Enemy tempEnemy = enemyList[Mathf.FloorToInt(Random.value * enemyList.Count)];
                        tempEnemyRef.GetComponent<Enemy>().setStats(tempEnemy.charName, tempEnemy.health, tempEnemy.strength,
                                                                    tempEnemy.endurance, tempEnemy.agility,tempEnemy.magicSkill,
                                                                    tempEnemy.luck, tempEnemy.range, tempEnemy.drop, tempEnemy.image);

                        GameObject tempPrefab = Instantiate(Resources.Load<GameObject>("Enemy_Prefabs/" + tempEnemy.image));
                        tempPrefab.transform.position = tempEnemyRef.transform.position;
                        tempPrefab.transform.SetParent(tempEnemyRef.transform);
                    }
                }
            }
        }
    }
示例#22
0
    static void Main()
    {
        Console.WriteLine(@"Problem 7.* Largest area in matrix
Write a program that finds the largest area of equal neighbour elements in a 
rectangular matrix and prints its size.
Example:
matrix						result
1	3	2	2	2	4		
3	3	3	2	4	4
4	3	1	2	3	3		13
4	3	1	3	3	1
4	3	3	3	1	1
-------------------------------------------------------------------------------
Solution:

");
	
	
		matrix = new[,]
		{
			{ 1, 3, 2, 2, 2, 4 },
			{ 3, 3, 3, 2, 4, 4 },
			{ 4, 3, 1, 2, 3, 3 },
			{ 4, 3, 1, 3, 3, 1 },
			{ 4, 3, 3, 3, 1, 1 }
		};

		PrintMatrix(matrix);
		FindBestAreaLength(matrix);
	}
示例#23
0
        public IA(Labyrinthe labyrinthe, Point position_joueur, Viewport vp)
        {
            laby = labyrinthe;
            taille = new Point(laby.Size.X, laby.Size.Y);
            carte_ia = new int[taille.X, taille.Y];
            pos_prec = new Stack<Point>();

            pos_ia = position_joueur;
            carte_ia[pos_ia.X, pos_ia.Y] = 0;
            pos_prec.Push(pos_ia);

            carte_ia = GenLabyIA(pos_ia, carte_ia, laby);

            EspaceTexte = 35;
            BordGaucheIA = vp.Width / 2 - (EspaceTexte * laby.Size.X) / 2;
            BordHautIA = vp.Height / 2 - (EspaceTexte * laby.Size.Y) / 2;

            idmax = 0;
            carte_ia_acces = new bool[Config.largeur_labyrinthe, Config.hauteur_labyrinthe];

            carte_ia_inter = new bool[taille.X, taille.Y];
            carte_direct = new int[taille.X, taille.Y];
            nb_chemin = new int[taille.X, taille.Y];
            carte_ia2 = new int[taille.X, taille.Y];
            carte_impasse = new bool[taille.X, taille.Y];
        }
示例#24
0
    public void instantiateBoard()
    {
        sudokuBoard = SudokuModel.generateBoard();

        Apartments = new Residence[9, 9];
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                GameObject apartment = GameObject.Instantiate(AptPrefab);
                apartment.transform.SetParent(this.transform);
                apartment.transform.localPosition = new Vector2(i * aptWidth, j * -aptHeight);
                Apartments[i, j] = apartment.GetComponent<Residence>();

                apartment.GetComponent<Residence>().happiness = sudokuBoard[i, j];
                apartment.GetComponent<Residence>().row = i;
                apartment.GetComponent<Residence>().col = j;
            }
        }

        modifiers = new List<int>[9, 9];
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                modifiers[i, j] = new List<int>();
            }
        }
    }
示例#25
0
 /// <summary>
 /// Release the unmanaged memory associated to this object
 /// </summary>
 protected override void DisposeObject()
 {
    CvInvoke.cvReleaseStructuringElement(ref _ptr);
    if (_handle.IsAllocated)
       _handle.Free();
    _values = null;
 }
示例#26
0
 static void Main(string[] args)
 {
     N = int.Parse(Console.ReadLine());
     S = 0;
     M = Spirall(N);
     PrintArray(M);
 }
示例#27
0
文件: State.cs 项目: paiston/oldcrap
 /// <summary>
 /// New state base on old state
 /// </summary>
 /// <param name="original"></param>
 public State(State original)
 {
     Values = (int[,])original.Values.Clone();
     RowCount = (int[])original.RowCount.Clone();
     Turn = original.Turn;
     MoveCount = original.MoveCount;
 }
示例#28
0
 public EditableImage(EditableImage image)
 {
     this.colors = image.colors.Clone() as int[,];
     this.PixelFormat = image.PixelFormat;
     this.Stride = image.Stride;
     this.Palette = image.Palette;
 }
示例#29
0
	// end of main program
	// ============= subroutines ============
	void MakeBlocks() {
		
		Maze = new int[width, height];
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++)  {
				Maze[x, y] = 1;
			}
		}
		CurrentTile = Vector2.one;
		_tiletoTry.Push(CurrentTile);
		Maze = CreateMaze();  // generate the maze in Maze Array.
		//GameObject ptype = null;
		for (int i = 0; i <= Maze.GetUpperBound(0); i++)  {
			for (int j = 0; j <= Maze.GetUpperBound(1); j++) {
				if (Maze[i, j] == 1)  {
					MazeString=MazeString+"X";  // added to create String
					//ptype = GameObject.CreatePrimitive(PrimitiveType.Cube);
					//ptype.transform.position = new Vector3(i * ptype.transform.localScale.x, 0, j * ptype.transform.localScale.z);
					
					//if (brick != null)  { ptype.GetComponent<Renderer>().material = brick; }
					//ptype.transform.parent = transform;
				}
				else if (Maze[i, j] == 0) {
					MazeString=MazeString+"."; // added to create String
				}
			}
			MazeString=MazeString+"\n";  // added to create String
		}
		print (MazeString);  // added to create String
	}
示例#30
0
        /**
         * Constructor
         */
        public BatchMemSchedHelper(BatchMemSched sched)
        {
            //pertaining to AbstractMemSched
            bank_max = sched.bank_max;

            bank = sched.bank;
            buf = sched.buf;
            buf_load = sched.buf_load;

            cur_load_per_proc = sched.cur_load_per_proc;
            cur_load_per_procbank = sched.cur_load_per_procbank;

            cur_max_load_per_proc = sched.cur_max_load_per_proc;

            //pertaining to BatchMemSched
            rank_to_proc = sched.rank_to_proc;
            proc_to_rank = sched.proc_to_rank;

            cur_marked_per_proc = sched.cur_marked_per_proc;
            //cur_period_marked_per_proc = sched.cur_period_marked_per_proc;

            cur_marked_per_procbank = sched.cur_marked_per_procbank;
            //cur_period_marked_per_procbank = sched.cur_period_marked_per_procbank;

            RBA_max = new int[Config.N];
            RBA_total = new int[Config.N];
            cur_bankproc = new int[bank_max];
            block_req_per_bank = new int[bank_max];

            //misc.
            virtual_marked_per_procbank = new int[Config.N, bank_max];
            completion_time = new int[Config.N];
        }
示例#31
0
        /*
         * ========================================
         *              Modify Menu
         * ========================================
         */
        /**
         * Modify menu loop
         */
        private void loopMenuModify()
        {
            int  selItem;
            Menu menu = new Menu(MenuData.MODIFY_TITLE, MenuData.MODIFY_CONTENT, this);

            do
            {
                selItem = menu.getItem();
                switch (selItem)
                {
                case MenuData.MODIFY_SET_CELL:
                    trackPuzzleUndo();
                    setCell();
                    break;

                case MenuData.MODIFY_ROTATE_CLOCK_WISE:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.rotateClockWise(puzzle);
                    break;

                case MenuData.MODIFY_ROTATE_COUNTER_CLOCK_WISE:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.rotateCounterclockWise(puzzle);
                    break;

                case MenuData.MODIFY_TRANSPOSE_TL_BR:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.transposeTlBr(puzzle);
                    break;

                case MenuData.MODIFY_TRANSPOSE_TR_BL:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.transposeTrBl(puzzle);
                    break;

                case MenuData.MODIFY_REFLECT_HORIZ:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.reflectHorizontally(puzzle);
                    break;

                case MenuData.MODIFY_REFLECT_VERT:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.reflectVertically(puzzle);
                    break;

                case MenuData.MODIFY_SWAP_COL_SEGMENTS:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.swapColSegmentsRandomly(puzzle);
                    break;

                case MenuData.MODIFY_SWAP_ROW_SEGMENTS:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.swapRowSegmentsRandomly(puzzle);
                    break;

                case MenuData.MODIFY_SWAP_COLS_IN_SEGMENTS:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.swapColsInSegmentRandomly(puzzle);
                    break;

                case MenuData.MODIFY_SWAP_ROWS_IN_SEGMENTS:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.swapRowsInSegmentRandomly(puzzle);
                    break;

                case MenuData.MODIFY_PERMUTE:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.permuteBoard(puzzle);
                    break;

                case MenuData.MODIFY_RANDOM_TRANSF_ONE:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.randomBoardTransf(puzzle);
                    break;

                case MenuData.MODIFY_RANDOM_TRANSF_SEQ:
                    trackPuzzleUndo();
                    puzzle = SudokuStore.seqOfRandomBoardTransf(puzzle);
                    break;

                case MenuData.UNDO:
                    performPuzzleUndo();
                    break;

                case MenuData.REDO:
                    performPuzzleRedo();
                    break;

                default: incorrectSelection(); break;
                }
            } while (selItem != MenuData.RETURN);
        }
示例#32
0
 public static int[,] GetSortedPermutationsArray(int[,] hpermutations, double[] hresults)
 {
     int[][] hpermutationsJagged = ToJagged <int>(hpermutations);
     Array.Sort(hresults, hpermutationsJagged);
     return(ToRectangular <int>(hpermutationsJagged));
 }
示例#33
0
        public static void perform(CallbackFields callback)
        {
            try
            {
                clear();
                Console.WriteLine("Running algorithm with parameters:");
                Console.WriteLine("\tIterations: " + ITERATIONS_NUM);
                Console.WriteLine("\tBees: " + N_BEES);
                Console.WriteLine("\tBest: " + N_BEST_SOLUTIONS);
                Console.WriteLine("\tElite: " + N_ELITE);
                Console.WriteLine("\tBest neighbourhood: " + BEST_NEIGHBOURHOOD_SIZE);
                Console.WriteLine("\tElite neighbourhood: " + ELITE_NEIGHBOURHOOD_SIZE);
                Console.WriteLine("\tSeed: " + seed);

                CudafyModule km = CudafyTranslator.Cudafy();

                GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
                gpu.LoadModule(km);

                ReadValuesFromFile("QAPexample2.txt");

                double[,] dweights   = gpu.Allocate <double>(PROBLEM_SIZE, PROBLEM_SIZE);
                double[,] ddistances = gpu.Allocate <double>(PROBLEM_SIZE, PROBLEM_SIZE);
                int[,] dpermutations = gpu.Allocate <int>(N_BEES, PROBLEM_SIZE);
                double[] dresults = gpu.Allocate <double>(N_BEES);

                int NEIGHBOURHOOD_BEES = N_ELITE * ELITE_NEIGHBOURHOOD_SIZE + N_BEST_SOLUTIONS * BEST_NEIGHBOURHOOD_SIZE;
                hneighbourhoods        = new int[NEIGHBOURHOOD_BEES, PROBLEM_SIZE];
                hnresults              = new double[NEIGHBOURHOOD_BEES];
                int[,] dneighbourhoods = gpu.Allocate <int>(NEIGHBOURHOOD_BEES, PROBLEM_SIZE);
                double[] dnresults = gpu.Allocate <double>(NEIGHBOURHOOD_BEES);

                gpu.CopyToDevice(hweights, dweights);
                gpu.CopyToDevice(hdistances, ddistances);

                //losowa inicjalizacja populacji
                GenerateRandomPermutations(0, N_BEES);

                for (int iteration = 0; iteration < ITERATIONS_NUM; iteration++)
                {
                    gpu.CopyToDevice(hpermutations, dpermutations);
                    gpu.Launch(N_BEES, 1).calcCosts(dweights, ddistances, dpermutations, dresults);
                    gpu.CopyFromDevice(dresults, hresults);

                    //posortowanie permutacji wedlug kosztow
                    hpermutations = GetSortedPermutationsArray(hpermutations, hresults);

                    maxOfIteration[iteration] = hresults[0];

                    if (bestVal > hresults[0])
                    {
                        //zapamietanie najlepszego rozwiazania
                        bestVal = hresults[0];
                        for (int i = 0; i < PROBLEM_SIZE; i++)
                        {
                            bestPerm[i] = hpermutations[0, i];
                        }
                        PrintResult("New best");
                    }

                    bestFitnesses[iteration] = bestVal;

                    //przygotowanie danych do generowania sasiedztwa elity
                    for (int i = 0; i < N_ELITE; i++)
                    {
                        for (int j = 0; j < ELITE_NEIGHBOURHOOD_SIZE; j++)
                        {
                            int row_nr = i * ELITE_NEIGHBOURHOOD_SIZE + j;
                            Array.Copy(hpermutations, i * PROBLEM_SIZE, hneighbourhoods, row_nr * PROBLEM_SIZE, PROBLEM_SIZE);
                        }
                    }

                    //przygotowanie danych do generowania sasiedztwa dobrych rozwiazan
                    for (int i = N_ELITE; i < N_ELITE + N_BEST_SOLUTIONS; i++)
                    {
                        for (int j = 0; j < BEST_NEIGHBOURHOOD_SIZE; j++)
                        {
                            int row_nr = N_ELITE * ELITE_NEIGHBOURHOOD_SIZE + (i - N_ELITE) * BEST_NEIGHBOURHOOD_SIZE + j;
                            Array.Copy(hpermutations, i * PROBLEM_SIZE, hneighbourhoods, row_nr * PROBLEM_SIZE, PROBLEM_SIZE);
                        }
                    }

                    //wygenerowanie sasiedztw (losowe zamiany w permutacjach)
                    for (int i = 0; i < N_ELITE * ELITE_NEIGHBOURHOOD_SIZE + N_BEST_SOLUTIONS * BEST_NEIGHBOURHOOD_SIZE; i++)
                    {
                        int ind1 = random.Next(PROBLEM_SIZE);
                        int ind2 = random.Next(PROBLEM_SIZE);       //TODO zapewnic zeby byly rozne?
                        int tmp  = hneighbourhoods[i, ind1];
                        hneighbourhoods[i, ind1] = hneighbourhoods[i, ind2];
                        hneighbourhoods[i, ind2] = tmp;
                    }

                    //policz wyniki dla sasiedztw
                    gpu.CopyToDevice(hneighbourhoods, dneighbourhoods);
                    gpu.Launch(NEIGHBOURHOOD_BEES, 1).calcCosts(dweights, ddistances, dneighbourhoods, dnresults);
                    gpu.CopyFromDevice(dnresults, hnresults);

                    //posortuj wyniki dla wszystkich sasiedztw
                    hneighbourhoods = GetSortedNeibhbourhoodsArray(hneighbourhoods, hnresults);

                    //wybierz najlepsze permutacje z sasiedztw elity
                    for (int i = 0; i < N_ELITE; i++)
                    {
                        int i_n = i * ELITE_NEIGHBOURHOOD_SIZE;
                        Array.Copy(hneighbourhoods, i_n * PROBLEM_SIZE, hpermutations, i * PROBLEM_SIZE, PROBLEM_SIZE);
                    }

                    //wybierz najlepsze permutacje z sasiedztw dobrych rozwiazan
                    for (int i = N_ELITE; i < N_ELITE + N_BEST_SOLUTIONS; i++)
                    {
                        int i_n = N_ELITE * ELITE_NEIGHBOURHOOD_SIZE + (i - N_ELITE) * BEST_NEIGHBOURHOOD_SIZE;
                        Array.Copy(hneighbourhoods, i_n * PROBLEM_SIZE, hpermutations, i * PROBLEM_SIZE, PROBLEM_SIZE);
                    }

                    //gorsze rozwiazania pomijamy - generujemy nowe losowe permutacje
                    GenerateRandomPermutations(N_ELITE + N_BEST_SOLUTIONS, N_BEES);
                }

                PrintResult("Best");

                callback.setFirstValue(bestFitnesses[0]);
                callback.setFinalValue(bestFitnesses[ITERATIONS_NUM - 1]);
                callback.setImprovementValue((bestFitnesses[0] - bestFitnesses[ITERATIONS_NUM - 1]) / bestFitnesses[0] * 100.0);
                callback.setDatapoints(bestFitnesses, maxOfIteration);
                callback.setReferenceSolution(REFERENCE_SOLUTION);
                callback.setError(Math.Abs(bestFitnesses[ITERATIONS_NUM - 1] - REFERENCE_SOLUTION) / REFERENCE_SOLUTION * 100.0);

                gpu.FreeAll();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine("\nThe end");
        }
示例#34
0
    public void GenerateLevel()
    {
        // TODO: match doors & remove inside corner square in 2x2 tile
        List <GameObject> prefabs = new List <GameObject>();

        foreach (Tile t in tilemap)
        {
            int tw = t.Width;
            int th = t.Height;

            int[,] squares = t.GetRelativeSpacesOccupied();

            for (int i = 0; i < squares.Length / 2; i++)
            {
                int sqx = squares[i, 0];
                int sqy = squares[i, 1];
                GridToPosition(t.XPos + sqx, t.YPos + sqy);

                // Place the room center/floor prefab
                prefabs.Add(Instantiate(prefabroom, pos, qforward));
                // Place the wall/door/open prefabs
                bool topsquare = (sqy == 0);
                if (!topsquare) // check if there's a square above
                {
                    topsquare = true;
                    for (int j = 0; j < squares.Length / 2; j++)
                    {
                        if (squares[j, 0] == sqx && squares[j, 1] == 0)
                        {
                            topsquare = false;
                            break;
                        }
                    }
                }
                if (topsquare)
                {
                    prefabs.Add(Instantiate((t.TopWall[sqx] == Wall.Door ? prefabdoor : prefabwall), pos, qforward));
                }
                else
                {
                    prefabs.Add(Instantiate(prefabopen, pos, qforward));
                }

                bool rightsquare = (sqx == tw - 1);
                if (!rightsquare) // check if there's a square to the right
                {
                    rightsquare = true;
                    for (int j = 0; j < squares.Length / 2; j++)
                    {
                        if (squares[j, 1] == sqy && squares[j, 0] == 1)
                        {
                            rightsquare = false;
                            break;
                        }
                    }
                }
                if (rightsquare)
                {
                    prefabs.Add(Instantiate((t.RightWall[sqy] == Wall.Door ? prefabdoor : prefabwall), pos, qright));
                }
                else
                {
                    prefabs.Add(Instantiate(prefabopen, pos, qright));
                }

                bool bottomsquare = (sqy == th - 1);
                if (!bottomsquare) // check if there's a square below
                {
                    bottomsquare = true;
                    for (int j = 0; j < squares.Length / 2; j++)
                    {
                        if (squares[j, 0] == sqx && squares[j, 1] == 1)
                        {
                            bottomsquare = false;
                            break;
                        }
                    }
                }
                if (bottomsquare)
                {
                    int wi = tw - sqx - 1;
                    prefabs.Add(Instantiate((t.BottomWall[wi] == Wall.Door ? prefabdoor : prefabwall), pos, qback));
                }
                else
                {
                    prefabs.Add(Instantiate(prefabopen, pos, qback));
                }

                bool leftsquare = (sqx == 0);
                if (!leftsquare) // check if there's a square to the left
                {
                    leftsquare = true;
                    for (int j = 0; j < squares.Length / 2; j++)
                    {
                        if (squares[j, 1] == sqy && squares[j, 0] == 0)
                        {
                            leftsquare = false;
                            break;
                        }
                    }
                }
                if (leftsquare)
                {
                    int wi = th - sqy - 1;
                    prefabs.Add(Instantiate((t.LeftWall[wi] == Wall.Door ? prefabdoor : prefabwall), pos, qleft));
                }
                else
                {
                    prefabs.Add(Instantiate(prefabopen, pos, qleft));
                }
            }
        }
        foreach (GameObject pf in prefabs)
        {
            pf.transform.parent = levelParent;
        }
    }
示例#35
0
        //Méthode qui permet de faire la matrice de convolution et qui est réutilisée dans la méthode Convolution
        private Pixel Operation(int[,] matrice, int i, int j)
        {
            byte r;
            byte g;
            byte b;

            if (i == 0)
            {
                if (j == 0)
                {
                    r = (byte)((image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 4);
                    g = (byte)((image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 4);
                    b = (byte)((image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 4);
                }
                else if (j == haut - 1)
                {
                    r = (byte)((image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2]) / 4);
                    g = (byte)((image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2]) / 4);
                    b = (byte)((image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2]) / 4);
                }
                else
                {
                    r = (byte)((image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 6);
                    g = (byte)((image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 6);
                    b = (byte)((image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 6);
                }
            }
            else if (i == large - 1)
            {
                if (j == 0)
                {
                    r = (byte)((image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1]) / 4);
                    g = (byte)((image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1]) / 4);
                    b = (byte)((image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1]) / 4);
                }
                else if (j == haut - 1)
                {
                    r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1]) / 4);
                    g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1]) / 4);
                    b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1]) / 4);
                }
                else
                {
                    r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1]) / 6);
                    g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1]) / 6);
                    b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1]) / 6);
                }
            }
            else if (j == 0)
            {
                r = (byte)((image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 6);
                g = (byte)((image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 6);
                b = (byte)((image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 6);
            }
            else if (j == haut - 1)
            {
                r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2]) / 6);
                g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2]) / 6);
                b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2]) / 6);
            }
            else
            {
                r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 9);
                g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 9);
                b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 9);
            }
            Pixel res = new Pixel(r, g, b);

            return(res);
        }
 public static void Main(String[] args)
 {
     int[,] avg1 = { { 2, 3, 4 }, { 3, 4, 5 }, { 1, 9, 6 } };
     Delta(avg1);
     Console.ReadKey();
 }
示例#37
0
    public static int TestEntryPoint()
    {
        bool passed = true;
        //initialize class
        CL cl1 = new CL();
        //initialize struct
        VT vt1;

        vt1.f_vt_test1_op1 = Single.NaN;
        vt1.f_vt_test1_op2 = 7.1234567F;
        vt1.f_vt_test2_op1 = -2.0F;
        vt1.f_vt_test2_op2 = 0.0F;
        vt1.f_vt_test3_op1 = Single.PositiveInfinity;
        vt1.f_vt_test3_op2 = 0.0F;

        float[] f_arr1d_test1_op1 = { 0, Single.NaN };
        float[,] f_arr2d_test1_op1   = { { 0, Single.NaN }, { 1, 1 } };
        float[, ,] f_arr3d_test1_op1 = { { { 0, Single.NaN }, { 1, 1 } } };

        float[] f_arr1d_test1_op2 = { 7.1234567F, 0, 1 };
        float[,] f_arr2d_test1_op2   = { { 0, 7.1234567F }, { 1, 1 } };
        float[, ,] f_arr3d_test1_op2 = { { { 0, 7.1234567F }, { 1, 1 } } };

        float[] f_arr1d_test2_op1 = { 0, -2.0F };
        float[,] f_arr2d_test2_op1   = { { 0, -2.0F }, { 1, 1 } };
        float[, ,] f_arr3d_test2_op1 = { { { 0, -2.0F }, { 1, 1 } } };

        float[] f_arr1d_test2_op2 = { 0.0F, 0, 1 };
        float[,] f_arr2d_test2_op2   = { { 0, 0.0F }, { 1, 1 } };
        float[, ,] f_arr3d_test2_op2 = { { { 0, 0.0F }, { 1, 1 } } };

        float[] f_arr1d_test3_op1 = { 0, Single.PositiveInfinity };
        float[,] f_arr2d_test3_op1   = { { 0, Single.PositiveInfinity }, { 1, 1 } };
        float[, ,] f_arr3d_test3_op1 = { { { 0, Single.PositiveInfinity }, { 1, 1 } } };

        float[] f_arr1d_test3_op2 = { 0.0F, 0, 1 };
        float[,] f_arr2d_test3_op2   = { { 0, 0.0F }, { 1, 1 } };
        float[, ,] f_arr3d_test3_op2 = { { { 0, 0.0F }, { 1, 1 } } };

        int[,] index = { { 0, 0 }, { 1, 1 } };

        {
            float f_l_test1_op1 = Single.NaN;
            float f_l_test1_op2 = 7.1234567F;
            if (!Single.IsNaN(f_l_test1_op1 % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 1 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 2 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 3 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 4 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 5 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 6 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 7 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test1_op1 % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 8 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 9 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 10 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 11 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 12 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 13 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 14 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 15 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test1_op1 % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 16 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 17 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 18 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 19 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 20 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 21 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 22 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 23 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test1_f("test1_op1") % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 24 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 25 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 26 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 27 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 28 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 29 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 30 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 31 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test1_op1 % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 32 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 33 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 34 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 35 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 36 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 37 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 38 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 39 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test1_op1 % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 40 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 41 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 42 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 43 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 44 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 45 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 46 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 47 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test1_op1[1] % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 48 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 49 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 50 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 51 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 52 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 53 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 54 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 55 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test1_op1[index[0, 1], index[1, 0]] % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 56 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_l_test1_op2))
            {
                Console.WriteLine("Test1_testcase 57 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_s_test1_op2))
            {
                Console.WriteLine("Test1_testcase 58 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_test1_f("test1_op2")))
            {
                Console.WriteLine("Test1_testcase 59 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % cl1.f_cl_test1_op2))
            {
                Console.WriteLine("Test1_testcase 60 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % vt1.f_vt_test1_op2))
            {
                Console.WriteLine("Test1_testcase 61 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_arr1d_test1_op2[0]))
            {
                Console.WriteLine("Test1_testcase 62 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_arr2d_test1_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test1_testcase 63 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test1_op1[index[0, 0], 0, index[1, 1]] % f_arr3d_test1_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test1_testcase 64 failed");
                passed = false;
            }
        }

        {
            float f_l_test2_op1 = -2.0F;
            float f_l_test2_op2 = 0.0F;
            if (!Single.IsNaN(f_l_test2_op1 % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 1 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 2 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 3 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 4 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 5 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 6 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 7 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test2_op1 % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 8 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 9 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 10 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 11 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 12 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 13 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 14 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 15 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test2_op1 % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 16 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 17 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 18 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 19 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 20 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 21 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 22 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 23 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test2_f("test2_op1") % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 24 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 25 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 26 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 27 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 28 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 29 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 30 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 31 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test2_op1 % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 32 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 33 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 34 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 35 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 36 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 37 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 38 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 39 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test2_op1 % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 40 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 41 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 42 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 43 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 44 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 45 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 46 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 47 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test2_op1[1] % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 48 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 49 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 50 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 51 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 52 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 53 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 54 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 55 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test2_op1[index[0, 1], index[1, 0]] % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 56 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_l_test2_op2))
            {
                Console.WriteLine("Test2_testcase 57 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_s_test2_op2))
            {
                Console.WriteLine("Test2_testcase 58 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_test2_f("test2_op2")))
            {
                Console.WriteLine("Test2_testcase 59 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % cl1.f_cl_test2_op2))
            {
                Console.WriteLine("Test2_testcase 60 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % vt1.f_vt_test2_op2))
            {
                Console.WriteLine("Test2_testcase 61 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_arr1d_test2_op2[0]))
            {
                Console.WriteLine("Test2_testcase 62 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_arr2d_test2_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test2_testcase 63 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test2_op1[index[0, 0], 0, index[1, 1]] % f_arr3d_test2_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test2_testcase 64 failed");
                passed = false;
            }
        }

        {
            float f_l_test3_op1 = Single.PositiveInfinity;
            float f_l_test3_op2 = 0.0F;
            if (!Single.IsNaN(f_l_test3_op1 % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 1 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 2 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 3 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 4 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 5 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 6 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 7 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_l_test3_op1 % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 8 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 9 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 10 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 11 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 12 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 13 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 14 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 15 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_s_test3_op1 % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 16 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 17 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 18 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 19 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 20 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 21 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 22 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 23 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_test3_f("test3_op1") % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 24 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 25 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 26 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 27 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 28 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 29 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 30 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 31 failed");
                passed = false;
            }
            if (!Single.IsNaN(cl1.f_cl_test3_op1 % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 32 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 33 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 34 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 35 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 36 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 37 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 38 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 39 failed");
                passed = false;
            }
            if (!Single.IsNaN(vt1.f_vt_test3_op1 % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 40 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 41 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 42 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 43 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 44 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 45 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 46 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 47 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr1d_test3_op1[1] % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 48 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 49 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 50 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 51 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 52 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 53 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 54 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 55 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr2d_test3_op1[index[0, 1], index[1, 0]] % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 56 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_l_test3_op2))
            {
                Console.WriteLine("Test3_testcase 57 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_s_test3_op2))
            {
                Console.WriteLine("Test3_testcase 58 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_test3_f("test3_op2")))
            {
                Console.WriteLine("Test3_testcase 59 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % cl1.f_cl_test3_op2))
            {
                Console.WriteLine("Test3_testcase 60 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % vt1.f_vt_test3_op2))
            {
                Console.WriteLine("Test3_testcase 61 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_arr1d_test3_op2[0]))
            {
                Console.WriteLine("Test3_testcase 62 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_arr2d_test3_op2[index[0, 1], index[1, 0]]))
            {
                Console.WriteLine("Test3_testcase 63 failed");
                passed = false;
            }
            if (!Single.IsNaN(f_arr3d_test3_op1[index[0, 0], 0, index[1, 1]] % f_arr3d_test3_op2[index[0, 0], 0, index[1, 1]]))
            {
                Console.WriteLine("Test3_testcase 64 failed");
                passed = false;
            }
        }

        if (!passed)
        {
            Console.WriteLine("FAILED");
            return(1);
        }
        else
        {
            Console.WriteLine("PASSED");
            return(100);
        }
    }
示例#38
0
 /**
  * Tracks puzzle redo.
  */
 private void trackPuzzleRedo()
 {
     puzzleRedo = SudokuStore.boardCopy(puzzle);
 }
示例#39
0
        private async void Change_value(object sender, EventArgs e)
        {
            PictureBox target = (PictureBox)sender;

            if (colorPicture == 0)
            {
                UndoBoard = (int[, ])board.Clone();

                foreach (Control c in this.Controls)
                {
                    if (c is TextBox && c.Name == "Score")
                    {
                        undoPoint = c.Text;
                    }
                }
                startPointX  = algo.FirstNumberX(target.Name);
                startPointY  = algo.FirstNumberY(target.Name);
                colorPicture = board[startPointX, startPointY];
                if (colorPicture != 0)
                {
                    target.Image = images[colorPicture + 5];
                }
            }
            else if (startPointX == algo.FirstNumberX(target.Name) && startPointY == algo.FirstNumberY(target.Name))
            {
                startPointX  = 0;
                startPointY  = 0;
                EndPointX    = 0;
                EndPointY    = 0;
                colorPicture = 0;
            }
            else
            {
                foreach (Control c in this.Controls)
                {
                    if (c is Panel)
                    {
                        c.Enabled = false;
                    }
                }
                EndPointX = algo.FirstNumberX(target.Name);
                EndPointY = algo.FirstNumberY(target.Name);

                if (board[EndPointX, EndPointY] == 0)
                {
                    int  tempX       = 0;
                    int  tempY       = 0;
                    bool CreatePoint = false;

                    LinkedList <string> findPath = algo.findPath(board, startPointX, startPointY, EndPointX, EndPointY);
                    if (findPath.Count() > 1)
                    {
                        foreach (string item in findPath)
                        {
                            int x = algo.FirstNumberX(item);
                            int y = algo.FirstNumberY(item);

                            tempX = x;
                            tempY = y;

                            board[x, y] = colorPicture;
                            LoadImage(board);
                            await Task.Delay(50);

                            foreach (Control c in panel1.Controls)
                            {
                                PictureBox p = (PictureBox)c;

                                if (p.Name == algo.ConvertTwoPosition(tempX, tempY))
                                {
                                    p.Image = null;
                                    if (x != EndPointX || y != EndPointY)
                                    {
                                        board[tempX, tempY] = 0;
                                    }
                                }
                            }
                        }
                        CreatePoint = true;
                    }
                    LinkedList <string> ScorePoint = new LinkedList <string>();
                    ScorePoint = algo.ScoreBoard(board, EndPointX, EndPointY, colorPicture);
                    if (ScorePoint.Count() >= 4)
                    {
                        ScorePoint.AddLast(algo.ConvertTwoPosition(EndPointX, EndPointY));
                        ClearPointWhenGetScore(board, ScorePoint);
                        int Score = ScorePoint.Count() * 5;
                        foreach (Control c in this.Controls)
                        {
                            if (c is TextBox && c.Name == "Score")
                            {
                                c.Font = new Font("Microsoft Sans Serif", 16, FontStyle.Regular);

                                string TempText = c.Text;
                                c.Text = c.Text + " +" + Score.ToString();
                                await Task.Delay(500);

                                int startScore = 0;
                                int EndScore   = 0;
                                c.Text = TempText;
                                if (c.Text != "")
                                {
                                    startScore = Int32.Parse(c.Text);
                                    EndScore   = Score + Int32.Parse(c.Text);
                                }
                                else
                                {
                                    startScore = 0;
                                    EndScore   = Score;
                                }
                                for (int i = startScore; i <= EndScore; i++)
                                {
                                    c.Text = i.ToString();
                                    await Task.Delay(10);
                                }
                            }
                        }
                        LoadImage(board);
                    }
                    else
                    {
                        if (CreatePoint)
                        {
                            algo.RandomPointBoard(board);
                            CreatePoint = false;
                        }
                    }

                    LoadImage(board);
                    colorPicture = 0;
                    Console.WriteLine(algo.CheckgameOver(board));
                    if (algo.CheckgameOver(board) > 78)
                    {
                        foreach (Control c in this.Controls)
                        {
                            if (c is TextBox && c.Name == "Score")
                            {
                                var form3 = new Form3(c.Text);
                                form3.Show();
                                this.Hide();
                            }
                        }
                    }
                }
                else if (board[EndPointX, EndPointY] > 0)
                {
                    foreach (Control c in panel1.Controls)
                    {
                        PictureBox p = (PictureBox)c;
                        if (p.Name == algo.ConvertTwoPosition(startPointX, startPointY))
                        {
                            p.Image      = images[colorPicture];
                            target.Image = images[board[EndPointX, EndPointY] + 5];
                        }
                    }
                    colorPicture = board[EndPointX, EndPointY];
                    startPointX  = EndPointX;
                    startPointY  = EndPointY;
                    EndPointX    = 0;
                    EndPointY    = 0;
                }

                foreach (Control c in this.Controls)
                {
                    if (c is Panel)
                    {
                        c.Enabled = true;
                    }
                }
                canUndo = true;
            }
        }
示例#40
0
 /**
  * Default constructor.
  */
 public JanetSudoku()
 {
     puzzle          = SudokuStore.boardCopy(SudokuPuzzles.PUZZLE_EMPTY);
     rndSeedOnCells  = true;
     rndSeedOnDigits = true;
 }
示例#41
0
        public IGameMove selectMove(IGameState gameState)
        {
            int[,] board = Forza4GameState.ParseBoard(gameState, 6, 7);

            return(MakeMove(board, gameState.currentPlayer));
        }
示例#42
0
 public void CleanUp()
 {
     array2D = null;
 }
示例#43
0
 private static int Horizontal(int[,] sockets, int opponentPlayer, int currentPlayer, int slot, int rowIndex, int colIndex)
 {
     if (sockets[rowIndex, colIndex] == opponentPlayer)
     {
         if (((rowIndex - 1) < sockets.GetLength(0) && (rowIndex - 1) > 0) && (sockets[rowIndex - 1, colIndex] == opponentPlayer))
         {
             if ((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && (sockets[rowIndex - 2, colIndex] == opponentPlayer)) && (sockets[rowIndex - 3, colIndex] == 0))
             {
                 if ((colIndex > 0) && (sockets[rowIndex - 3, colIndex - 1] != 0))
                 {
                     slot = colIndex + 3;
                 }
                 else if (colIndex == 0)
                 {
                     slot = colIndex + 3;
                 }
             }
             if (((((rowIndex - 2) < sockets.GetLength(0) && (rowIndex - 2) > 0) && (sockets[rowIndex - 2, colIndex] == opponentPlayer)) && (((rowIndex + 1) > 0 && (rowIndex + 1) < sockets.GetLength(0)) && (sockets[rowIndex + 1, colIndex] != currentPlayer))) && (sockets[rowIndex + 1, colIndex] == 0))
             {
                 if (((rowIndex > 0) && (colIndex > 0)) && (sockets[rowIndex + 1, colIndex - 1] != 0))
                 {
                     slot = colIndex - 1;
                 }
                 else if (colIndex == 0)
                 {
                     slot = colIndex + 1;
                 }
             }
         }
         if ((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && (sockets[rowIndex - 1, colIndex] == 0)) && ((sockets[rowIndex - 2, colIndex] == opponentPlayer) && (sockets[rowIndex - 3, colIndex] == opponentPlayer)))
         {
             if ((colIndex > 0) && (sockets[rowIndex - 1, colIndex - 1] != 0))
             {
                 slot = colIndex + 1;
             }
             else if ((colIndex == 0) && (sockets[rowIndex - 1, colIndex] == 0))
             {
                 slot = colIndex + 1;
             }
         }
         if ((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && (sockets[rowIndex - 1, colIndex] == opponentPlayer)) && ((sockets[rowIndex - 2, colIndex] == 0) && (sockets[rowIndex - 3, colIndex] == opponentPlayer)))
         {
             if ((colIndex > 0) && (sockets[rowIndex - 2, colIndex - 1] != 0))
             {
                 slot = colIndex + 2;
             }
             else if ((colIndex == 0) && (sockets[rowIndex - 2, colIndex] == 0))
             {
                 slot = colIndex + 2;
             }
         }
     }
     if (((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && ((rowIndex + 1) >= 0 && (rowIndex + 1) < sockets.GetLength(0))) && ((sockets[rowIndex, colIndex] == opponentPlayer) && (sockets[rowIndex - 1, colIndex] == opponentPlayer))) && (((sockets[rowIndex - 2, colIndex] == 0) && (sockets[rowIndex - 3, colIndex] == 0)) && (sockets[rowIndex + 1, colIndex] == 0)))
     {
         slot = colIndex + 2;
     }
     if (
         (rowIndex - 2) < sockets.GetLength(0) && (rowIndex - 2) > 0 &&
         (rowIndex + 2) >= 0 && (rowIndex + 2) < sockets.GetLength(0) &&
         (sockets[rowIndex, colIndex] == opponentPlayer) && (sockets[rowIndex - 1, colIndex] == opponentPlayer) &&
         (sockets[rowIndex - 2, colIndex] == 0 && (sockets[rowIndex + 2, colIndex] == 0) && sockets[rowIndex + 1, colIndex] == 0))
     {
         slot = colIndex - 1;
     }
     return(slot);
 }
示例#44
0
 public Placer(Figure[] figures, int[,] coordinates, int size)
 {
     this.Figures     = figures;
     this.Coordinates = coordinates;
     this.Field       = new int[size, size];
 }
示例#45
0
 public void Resize(int blocksAcross)
 {
     this.blocksAcross = blocksAcross;
     cellsInRow        = blocksAcross * blocksAcross;
     cells             = new int[cellsInRow, cellsInRow];
 }
示例#46
0
 private static int Diagonal(int[,] sockets, int opponentPlayer, int slot, int rowIndex, int colIndex)
 {
     if ((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && ((colIndex + 3) < sockets.GetLength(1))) && (sockets[rowIndex, colIndex] == opponentPlayer))
     {
         if (sockets[rowIndex - 1, colIndex + 1] == opponentPlayer)
         {
             if (sockets[rowIndex - 2, colIndex + 2] == opponentPlayer)
             {
                 if ((sockets[rowIndex - 3, colIndex + 3] == 0) && (sockets[rowIndex - 3, colIndex + 2] != 0))
                 {
                     slot = colIndex + 3;
                 }
             }
             else if (((sockets[rowIndex - 2, colIndex + 2] == 0) && (sockets[rowIndex - 3, colIndex + 3] == opponentPlayer)) && (sockets[rowIndex - 2, colIndex + 1] != 0))
             {
                 slot = colIndex + 2;
             }
         }
         else if (((sockets[rowIndex - 1, colIndex + 1] == 0) && (sockets[rowIndex - 2, colIndex + 2] == opponentPlayer)) && ((sockets[rowIndex - 3, colIndex + 3] == opponentPlayer) && (sockets[rowIndex - 1, colIndex] != 0)))
         {
             slot = colIndex + 1;
         }
     }
     if (((((rowIndex - 3) < sockets.GetLength(0) && (rowIndex - 3) > 0) && ((colIndex + 3) < sockets.GetLength(1))) && ((sockets[rowIndex, colIndex] == 0) && (sockets[rowIndex - 1, colIndex + 1] == opponentPlayer))) && ((sockets[rowIndex - 2, colIndex + 2] == opponentPlayer) && (sockets[rowIndex - 3, colIndex + 3] == opponentPlayer)))
     {
         slot = colIndex;
     }
     if ((((rowIndex + 3) >= 0 && (rowIndex + 3) < sockets.GetLength(0)) && ((colIndex + 3) < sockets.GetLength(1))) && (sockets[rowIndex, colIndex] == opponentPlayer))
     {
         if (sockets[rowIndex + 1, colIndex + 1] == opponentPlayer)
         {
             if (sockets[rowIndex + 2, colIndex + 2] == opponentPlayer)
             {
                 if ((sockets[rowIndex + 3, colIndex + 3] == 0) && (sockets[rowIndex + 3, colIndex + 2] != 0))
                 {
                     slot = colIndex + 3;
                 }
             }
             else if (((sockets[rowIndex + 2, colIndex + 2] == 0) && (sockets[rowIndex + 3, colIndex + 3] == opponentPlayer)) && (sockets[rowIndex + 2, colIndex + 1] != 0))
             {
                 slot = colIndex + 2;
             }
         }
         else if (((sockets[rowIndex + 1, colIndex + 1] == 0) && (sockets[rowIndex + 2, colIndex + 2] == opponentPlayer)) && ((sockets[rowIndex + 3, colIndex + 3] == opponentPlayer) && (sockets[rowIndex + 1, colIndex] != 0)))
         {
             slot = colIndex + 1;
         }
     }
     if (((((rowIndex + 3) >= 0 && (rowIndex + 3) < sockets.GetLength(0)) && ((colIndex + 3) < sockets.GetLength(1))) && ((sockets[rowIndex, colIndex] == 0) && (sockets[rowIndex + 1, colIndex + 1] == opponentPlayer))) && ((sockets[rowIndex + 2, colIndex + 2] == opponentPlayer) && (sockets[rowIndex + 3, colIndex + 3] == opponentPlayer)))
     {
         if ((colIndex == 0) && (sockets[rowIndex, colIndex] != 0))
         {
             slot = colIndex;
             return(slot);
         }
         if ((colIndex > 0) && (sockets[rowIndex, colIndex - 1] != 0))
         {
             slot = colIndex;
         }
     }
     return(slot);
 }
示例#47
0
    static bool IsValid(Vector2 candidate, Vector2 sampleRegionSize, float cellSize, float radius, List <Vector2> points, int[,] grid)
    {
        if (candidate.x >= 0 && candidate.x < sampleRegionSize.x && candidate.y >= 0 && candidate.y < sampleRegionSize.y)
        {
            int cellX        = (int)(candidate.x / cellSize);
            int cellY        = (int)(candidate.y / 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);

            for (int x = searchStartX; x <= searchEndX; x++)
            {
                for (int y = searchStartY; y <= searchEndY; y++)
                {
                    int pointIndex = grid[x, y] - 1;
                    if (pointIndex != -1)
                    {
                        float sqrDst = (candidate - points[pointIndex]).sqrMagnitude;
                        if (sqrDst < radius * radius)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        return(false);
    }
示例#48
0
        // Main method to test the homework
        public static void Main()
        {
            //1 test for TwoMax
            Console.WriteLine("Which is larger: 4, 2 ");
            Console.WriteLine(TwoMax(4, 2));

            //2 test for ThreeMax
            Console.WriteLine("Which is larger: 4, 9 ,4");
            Console.WriteLine(ThreeMax(4, 9, 4));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            //3 test for starts with vowel
            Console.WriteLine("Is it a vowel: E");
            Console.WriteLine(StartsWithVowel('E'));
            Console.WriteLine("Is it a vowel: V");
            Console.WriteLine(StartsWithVowel('V'));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            //4 test for Palindrome
            Console.WriteLine("Is it a Palindrome: abcfcbA");
            Console.WriteLine(PalindromeCheck("abcfcbA"));
            Console.WriteLine("Is it a Palindrome: abbfa");
            Console.WriteLine(PalindromeCheck("abbfa"));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();


            //5 Odds in Array
            int[] testArray = { 1, 2, 1, 2, 1, 2, 3, 3 };
            Console.WriteLine("How many odd in the array: ");             //, testArray);
            foreach (int i in testArray)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\nThe odd numbers of the array are: ");
            foreach (int i in OddArray(testArray))
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\nPress Enter to Continue");
            Console.ReadLine();

            //6 multiplies the values of a integer list
            List <int> myList = new List <int>();

            myList.Add(2);
            myList.Add(2);
            myList.Add(5);
            Console.WriteLine("\nThe list has he following");
            foreach (int i in myList)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\nTheir product is {0}", Multiply(myList));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 7. Checks if a list of doubles is sorted
            List <double> doubleList = new List <double>();

            doubleList.Add(2.1);
            doubleList.Add(4.3);
            doubleList.Add(5.2);
            doubleList.Add(6.9);
            Console.WriteLine("\nThe list has the following: ");
            foreach (double i in doubleList)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\nIs this list sorted: {0}", IsSorted(doubleList));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 8. Returns the smallest element of an Array
            testArray = new int[8] {
                6, 3, 7, 9, 2, 1, 8, 4
            };
            Console.WriteLine("The array has the following");
            foreach (int i in testArray)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\n{0} is the lowest.", Lowest(testArray));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 9. Returns the number of duplicates in an list
            List <char> charList = new List <char>();

            charList.Add('n');
            charList.Add('a');
            charList.Add('w');
            charList.Add('a');
            charList.Add('d');
            charList.Add('e');
            charList.Add('w');
            Console.WriteLine("\nThe list has he following");
            foreach (char i in charList)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\nThe array has {0} duplicates", Dups(charList));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 10. Lowest value in an dictionary
            Dictionary <string, int> testD = new Dictionary <string, int>();

            testD.Add("Apples", 3);
            testD.Add("Pears", 7);
            testD.Add("Pineapples", 2);
            testD.Add("Kiwis", 4);
            testD.Add("Peaches", 1);
            Console.WriteLine("From the following Key Value Pair:");
            foreach (KeyValuePair <string, int> kpv in testD)
            {
                Console.WriteLine("Key: {0}, Value: {1}", kpv.Key, kpv.Value);
            }
            Console.WriteLine("The lowest value is {0}", LowestValue(testD));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 11. Pangram check
            string pgString = "The quick brown fox jumps over the lazy dog";

            Console.WriteLine("Is \"{0}\" a Pangram : {1}", pgString, PanGramCheck(pgString));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 12. LoShu
            int[,] loShuArray = { { 4, 9, 2 }, { 3, 5, 7 }, { 8, 1, 6 } };
            Console.WriteLine("Is the Above a LoShu Square: {0}", LoShu(loShuArray));
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 13. List of Words larger than n
            List <string> words = new List <string>();

            words.Add("Television");
            words.Add("Radio");
            words.Add("Computer");
            words.Add("Phone");
            Console.WriteLine("Current word list");
            foreach (string s in words)
            {
                Console.WriteLine(s);
            }
            Console.WriteLine("\nWords Larger than 6");
            foreach (string s in FilterLongWords(words, 6))
            {
                Console.WriteLine(s);
            }
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();

            // 14. Top Ten
            testD.Add("Bananas", 10);
            testD.Add("Mangos", 3);
            testD.Add("Papaya", 6);
            testD.Add("Grapes", 4);
            testD.Add("Oranges", 7);
            testD.Add("Uniq", 8);
            Console.WriteLine("Current Dictionary of Words");
            foreach (KeyValuePair <string, int> w in testD)
            {
                Console.WriteLine("Key: {0}, Value {1}", w.Key, w.Value);
            }
            Console.WriteLine("\nTop Ten Dictionary of Words");
            TopTen(testD);

            /*
             * foreach (KeyValuePair<string, int> w in )
             * {
             *      Console.WriteLine("Key: {0}, Value {1}", w.Key, w.Value);
             * }*/
            Console.WriteLine("Press Enter to Continue");
            Console.ReadLine();
        }
示例#49
0
 public Table(int row, int col)
 {
     arr = new int[row, col];
     Random r = new Random();
 }
示例#50
0
 public void resetUniqueCandidates()
 {
     uniqueCandidates = new int[cellsInRow, cellsInRow];
 }
示例#51
0
 public Map(int size)
 {
     this.size = size;
     map       = new int[size, size];
 }
示例#52
0
        public void EquipWeapon(string weaponName)
        {
            atkUp      = new int[0, 0];
            magicAtkUp = new int[0, 0];

            Hud.Instance.WeaponColor = ConsoleColor.White;

            if (isSword == true)
            {
                weaponSymbol = "╫";
                switch (weaponName)
                {
                case "WoodenSword":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkYellow;
                    atkUp = new int[2, 5];
                    break;

                case "StoneSword":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkGray;
                    atkUp = new int[7, 10];
                    break;

                case "IronSword":
                    Hud.Instance.WeaponColor = ConsoleColor.Gray;
                    atkUp = new int[30, 50];
                    break;

                case "SilverSword":
                    Hud.Instance.WeaponColor = ConsoleColor.White;
                    atkUp                = new int[75, 120];
                    magicAtkUp           = new int[20, 40];
                    Player.Instance.Luk += 1;
                    break;

                case "AzureSword":
                    Hud.Instance.WeaponColor = ConsoleColor.Blue;
                    atkUp = new int[210, 350];
                    break;

                default:
                    atkUp = new int[0, 0];
                    break;
                }

                Player.Instance.Weapon = weaponName;
            }
            else if (isAxe == true)
            {
                weaponSymbol = "φ";
                switch (weaponName)
                {
                case "WoodenAxe":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkYellow;
                    atkUp = new int[1, 7];
                    break;

                case "StoneAxe":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkGray;
                    atkUp = new int[4, 14];
                    break;

                case "IronAxe":
                    Hud.Instance.WeaponColor = ConsoleColor.Gray;
                    atkUp = new int[20, 70];
                    break;

                case "FireAxe":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkRed;
                    atkUp                = new int[50, 175];
                    magicAtkUp           = new int[1, 5];
                    Player.Instance.Luk += 1;
                    break;

                case "MalachiteAxe":
                    Hud.Instance.WeaponColor = ConsoleColor.Green;
                    atkUp = new int[150, 500];
                    break;

                default:
                    atkUp = new int[0, 0];
                    break;
                }

                Player.Instance.Weapon = weaponName;
            }
            else if (isStaff == true)
            {
                weaponSymbol = "ÿ";
                switch (weaponName)
                {
                case "FireStaftt":
                    Hud.Instance.WeaponColor = ConsoleColor.Red;
                    magicAtkUp = new int[1, 5];
                    break;

                case "IceStaff":
                    Hud.Instance.WeaponColor = ConsoleColor.Cyan;
                    magicAtkUp = new int[5, 10];
                    break;

                case "LightStaff":
                    Hud.Instance.WeaponColor = ConsoleColor.Yellow;
                    magicAtkUp           = new int[25, 50];
                    Player.Instance.Luk += 4;
                    break;

                case "DarkStaff":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkMagenta;
                    magicAtkUp = new int[75, 150];
                    break;

                case "AmethystStaff":
                    Hud.Instance.WeaponColor = ConsoleColor.Magenta;
                    magicAtkUp = new int[200, 350];
                    break;

                default:
                    magicAtkUp = new int[0, 0];
                    break;
                }

                Player.Instance.Weapon = weaponName;
            }
            else if (isWand == true)
            {
                weaponSymbol = "¡";
                switch (weaponName)
                {
                case "ElectricWand":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkBlue;
                    magicAtkUp           = new int[3, 3];
                    Player.Instance.Luk += 1;
                    break;

                case "NatureWand":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkGreen;
                    magicAtkUp           = new int[7, 8];
                    Player.Instance.Luk += 1;
                    break;

                case "LasoWand":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkYellow;
                    magicAtkUp           = new int[35, 45];
                    atkUp                = new int[15, 15];
                    Player.Instance.Luk += 1;
                    break;

                case "VenomWand":
                    Hud.Instance.WeaponColor = ConsoleColor.DarkMagenta;
                    magicAtkUp           = new int[100, 120];
                    Player.Instance.Luk += 1;
                    break;

                case "QuartzWand":
                    Hud.Instance.WeaponColor = ConsoleColor.Gray;
                    magicAtkUp           = new int[275, 300];
                    Player.Instance.Luk += 1;
                    break;

                default:
                    magicAtkUp = new int[0, 0];
                    break;
                }

                Player.Instance.Weapon = weaponName;
            }
        }
    private void cost()
    {
        C = new int[10, 10];
        for (x = 0; x < 10; x++)
        {
            for (z = 0; z < 10; z++)
            {
                if ((x == pos.x) && (z == pos.y) && (OC[x, z] == 0))
                {
                    C[x, z]  = 0;
                    OC[x, z] = 1;
                    if (z < 9)
                    {
                        if (OC[x, z + 1] == 0)
                        {
                            C[x, z + 1]  = C[x, z] + 1;
                            OC[x, z + 1] = 1;
                            cp           = 1;
                        }
                    }
                    if (x < 9)
                    {
                        if (OC[x + 1, z] == 0)
                        {
                            C[x + 1, z]  = C[x, z] + 1;
                            OC[x + 1, z] = 1;
                            cp           = 1;
                        }
                    }
                    if (z > 0)
                    {
                        if (OC[x, z - 1] == 0)
                        {
                            C[x, z - 1]  = C[x, z] + 1;
                            OC[x, z - 1] = 1;
                            cp           = 1;
                        }
                    }
                    if (x > 0)
                    {
                        if (OC[x - 1, z] == 0)
                        {
                            C[x - 1, z]  = C[x, z] + 1;
                            OC[x - 1, z] = 1;
                            cp           = 1;
                        }
                    }
                }
            }
        }
        cc = 1;
        while (true)
        {
            cp = 0;
            for (x = 0; x < 10; x++)
            {
                for (z = 0; z < 10; z++)
                {
                    if (C[x, z] == cc)
                    {
                        if (z < 9)
                        {
                            if (OC[x, z + 1] == 0)
                            {
                                C[x, z + 1]  = C[x, z] + 1;
                                OC[x, z + 1] = 1;
                                cp           = 1;
                            }
                        }
                        if (x < 9)
                        {
                            if (OC[x + 1, z] == 0)
                            {
                                C[x + 1, z]  = C[x, z] + 1;
                                OC[x + 1, z] = 1;
                                cp           = 1;
                            }
                        }
                        if (z > 0)
                        {
                            if (OC[x, z - 1] == 0)
                            {
                                C[x, z - 1]  = C[x, z] + 1;
                                OC[x, z - 1] = 1;
                                cp           = 1;
                            }
                        }
                        if (x > 0)
                        {
                            if (OC[x - 1, z] == 0)
                            {
                                C[x - 1, z]  = C[x, z] + 1;
                                OC[x - 1, z] = 1;
                                cp           = 1;
                            }
                        }
                    }
                }
            }

            if (cp == 0)
            {
                break;
            }
            cc = cc + 1;
        }
    }
示例#54
0
        private void розмиканняToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]);
            int width  = Im[comboBox1.SelectedIndex].Width,
                height = Im[comboBox1.SelectedIndex].Height;

            byte[,,] rgbE  = new byte[3, height, width];
            byte[,,] rgbEN = new byte[3, height, width];

            int Rozmir_maski_S = 1;

            int[,] S = StructElement(toolStripComboBox1.SelectedIndex);

            bool nullPoint = false;

            for (int y = Rozmir_maski_S; y < height - Rozmir_maski_S; y++)
            {
                for (int x = Rozmir_maski_S; x < width - Rozmir_maski_S; x++)
                {
                    if (rgb[0, y, x] == 255)
                    {
                        nullPoint = false;

                        for (int i = -Rozmir_maski_S; i <= Rozmir_maski_S; i++)
                        {
                            for (int j = -Rozmir_maski_S; j <= Rozmir_maski_S; j++)
                            {
                                if (S[1 + i, 1 + j] == 1)
                                {
                                    if (rgb[0, y + i, x + j] == 0)
                                    {
                                        nullPoint = true;
                                    }
                                }
                            }
                        }

                        if (nullPoint == true)
                        {
                            rgbE[0, y, x] = RGB.Limit(0);
                            rgbE[1, y, x] = RGB.Limit(0);
                            rgbE[2, y, x] = RGB.Limit(0);
                        }
                        else
                        {
                            rgbE[0, y, x] = RGB.Limit(255);
                            rgbE[1, y, x] = RGB.Limit(255);
                            rgbE[2, y, x] = RGB.Limit(255);
                        }
                    }
                }
            }

            for (int y = Rozmir_maski_S; y < height - Rozmir_maski_S; y++)
            {
                for (int x = Rozmir_maski_S; x < width - Rozmir_maski_S; x++)
                {
                    if (rgbE[0, y, x] == 255)
                    {
                        for (int i = -Rozmir_maski_S; i <= Rozmir_maski_S; i++)
                        {
                            for (int j = -Rozmir_maski_S; j <= Rozmir_maski_S; j++)
                            {
                                if (S[1 + i, 1 + j] == 1)
                                {
                                    rgbEN[0, y + i, x + j] = RGB.Limit(255);
                                    rgbEN[1, y + i, x + j] = RGB.Limit(255);
                                    rgbEN[2, y + i, x + j] = RGB.Limit(255);
                                }
                            }
                        }
                    }
                }
            }

            Im.Add(RGB.RgbToBitmapNaive(rgbEN));

            comboBox1.Items.Add(comboBox1.Text + "+R" + toolStripComboBox1.SelectedIndex);
            comboBox1.Text = comboBox1.Text + "+R" + toolStripComboBox1.SelectedIndex;

            label2.Text = "R" + toolStripComboBox1.SelectedIndex;
        }
    public void TakeInput()
    {
        foreach (Neuron inputneuron in Input.Neurons)
        {
            inputneuron.Inputs.Clear();
        }
        int[,] boardState = Board.BoardInst.ConvertBoardToANNInput();
        int ix = 0;
        

        // Take Boardstate and convert it to 3 bit for each square
        for (int x = 0; x < 5; x++)
        {
            for (int y = 0; y < 5; y++)
            {
                switch (boardState[x,y])
                {
                    case 1:
                        for (int z = 0; z < 3; z++)
                        {
                            Input.Neurons[ix + z].Inputs.Add(1);
                        }
                        break;
                    case 2:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 0 || z == 1)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                        }
                        break;
                    case 3:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 0 || z == 2)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                        }
                        break;
                    case 4:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 1 || z == 2)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                            
                        }
                        break;
                    case 5:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 1)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                        }
                        break;
                    case 6:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 2)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                        }
                        break;
                    case 7:
                        for (int z = 0; z < 3; z++)
                        {
                            if (z == 0)
                            {
                                Input.Neurons[ix + z].Inputs.Add(0);
                            }
                            else
                            {
                                Input.Neurons[ix + z].Inputs.Add(1);

                            }
                        }
                        break;
                    default:
                        break;
                }
                //Input.Neurons[ix].Inputs.Add(boardState[x, y]);
                ix = ix + 3;
            }
        }
      //  Input.Neurons[25].Inputs.Add((double)GameManager.GmInst.Player1Points);
    //    Input.Neurons[26].Inputs.Add((double)GameManager.GmInst.Player2Points);
        int i = 0;
        foreach (Neuron item in Input.Neurons)
        {

          
       //     Debug.Log("Input = "+ item.Inputs[0] + "\n" + "Weight = " + item.Weights[0] + "\n" + "Bias = " + item.BiasWeight + "\n" + "Output " + item.Output);
            
            //    Debug.Log("Weight = "+ item.Weights[0]);
            //    Debug.Log("Bias = " + item.BiasWeight);
            //    Debug.Log("error " + item.Error);
            //

            i++;
        }

    }
示例#56
0
        static void Main(string[] args)
        {
            // Start of the block Arrays and collections
            int[]    intArray    = new int[5];
            string[] stringArray = new string[5];

            int[]    populatedArray       = new int[] { 0, 1, 2, 3, 4, 5 };
            string[] populatedStringArray = new string[] { "One", "Two", "Three" };

            intArray[0] = 5;
            intArray[2] = 15;

            int firstValue = intArray[0];

            int[,] multiInt          = new int[2, 3]; //  2 in the first column, 3 in the second
            int[,] multiPopulatedInt = { { 1, 2, 3 }, { 5, 6, 7 } };

            int firstMultiValue  = multiPopulatedInt[0, 0]; // value would be 1
            int secondMultiValue = multiPopulatedInt[1, 2]; // value 7

            List <string> listOfStrings = new List <string>();

            listOfStrings.Add("fist String");           // add to the end of List
            listOfStrings.Insert(0, "Inserted String"); // insert based on index
            listOfStrings.Remove("first String");       // removing based on content
            listOfStrings.Remove("0");                  // removing based in index

            listOfStrings.Sort();
            var theFirstString = listOfStrings[0];

            Dictionary <string, string> names = new Dictionary <string, string>();

            names.Add("James", "Bond");
            names.Add("Money", "Penny");
            names.Remove("James");
            // End of the block Arrays and collections

            PetStruct dog = new PetStruct();

            dog.Type   = PetType.Dog;
            dog.HasFur = true;
            dog.Legs   = 4;

            PetClass duck = new PetClass();

            duck.Type   = PetType.Duck;
            duck.HasFur = false;
            duck.Legs   = 2;

            Console.WriteLine("A " + dog.Type + " has " + dog.Legs + " legs.");
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs + " legs.");

            MultipleLegs(dog, duck);
            Console.WriteLine("A " + dog.Type + " has " + dog.Legs + " legs.");
            Console.WriteLine("A " + duck.Type + " has " + duck.Legs + " legs.");

            List <PetClass> pets = new List <PetClass>();

            //PetClass mydog = new PetClass(); // a way to create the object

            // Another way to create the object in the List using LINQ
            pets.Add(new PetClass {
                HasFur = false, Legs = 2, Name = "Donald", Type = PetType.Duck
            });                                                                                        // frist item of the list
            pets.Add(new PetClass {
                HasFur = true, Legs = 4, Name = "Pluto", Type = PetType.Dog
            });                                                                                     // second item

            List <PetClass> results = (from p in pets
                                       where p.Type == PetType.Dog
                                       select p).ToList();

            //<PetClass> results = (from p in pets
            //                          where p.Name == "Pluto"
            //                          select p).FirstOrDefault();

            // Another way using Lambda
            PetClass result = pets.FirstOrDefault(p => p.Type == PetType.Dog); // when returned a sigle item

            Console.WriteLine("found " + results.Count + " Dogs");
            Console.ReadLine();
        }
        //Places a hall in the given tilemap with given x,y coordinates, direction and length.
        //Direction is cardinal, 0 is north, 1 is east, 2 is south, 3 is west.)
        public void placeHall(int[,] map, bool[,] cMap, int xCoor, int yCoor, int direction, int length)
        {
            //Console.WriteLine("X:" + xCoor);
            //Console.WriteLine("Y:" + yCoor);
            //Console.WriteLine("Direction:" + direction);
            //Console.WriteLine("Length:" + length);
            for (int i = 0; i < length; i++)
            {
                switch (direction)
                {
                case 0:
                    map[yCoor - i, xCoor]  = 5;
                    cMap[yCoor - i, xCoor] = true;

                    if (map[yCoor - i, xCoor - 1] == 0 || map[yCoor - i, xCoor - 1] == 1 || map[yCoor - i, xCoor - 1] == 7)
                    {
                        map[yCoor - i, xCoor - 1] = 4;
                    }
                    else if (i == 0 && map[yCoor - i, xCoor - 1] == 2)
                    {
                        map[yCoor - i, xCoor - 1] = 13;
                    }
                    else if (map[yCoor - i, xCoor - 1] == 8)
                    {
                        map[yCoor - i, xCoor - 1] = 11;
                    }


                    if (map[yCoor - i, xCoor + 1] == 0 || map[yCoor - i, xCoor + 1] == 3 || map[yCoor - i, xCoor + 1] == 9)
                    {
                        map[yCoor - i, xCoor + 1] = 6;
                    }
                    else if (i == 0 && map[yCoor - i, xCoor + 1] == 2)
                    {
                        map[yCoor - i, xCoor + 1] = 12;
                    }
                    else if (map[yCoor - i, xCoor + 1] == 8)
                    {
                        map[yCoor - i, xCoor + 1] = 10;
                    }

                    if (((i + 1) < length) && (map[yCoor - i - 1, xCoor] == 5))
                    {
                        i = length;
                    }

                    break;

                case 1:
                    map[yCoor, xCoor + i]  = 5;
                    cMap[yCoor, xCoor + i] = true;

                    if (map[yCoor - 1, xCoor + i] == 0 || map[yCoor - 1, xCoor + i] == 1 || map[yCoor - 1, xCoor + i] == 3)
                    {
                        map[yCoor - 1, xCoor + i] = 2;
                    }
                    else if (i == 0 && map[yCoor - 1, xCoor + i] == 6)
                    {
                        map[yCoor - 1, xCoor + i] = 12;
                    }
                    else if (map[yCoor - 1, xCoor + i] == 4)
                    {
                        map[yCoor - 1, xCoor + i] = 13;
                    }

                    if (map[yCoor + 1, xCoor + i] == 0 || map[yCoor + 1, xCoor + i] == 7 || map[yCoor + 1, xCoor + i] == 9)
                    {
                        map[yCoor + 1, xCoor + i] = 8;
                    }
                    else if (i == 0 && map[yCoor + 1, xCoor + i] == 6)
                    {
                        map[yCoor + 1, xCoor + i] = 10;
                    }
                    else if (map[yCoor + 1, xCoor + i] == 4)
                    {
                        map[yCoor + 1, xCoor + i] = 11;
                    }

                    if (((i + 1) < length) && (map[yCoor, xCoor + i + 1] == 5))
                    {
                        i = length;
                    }

                    break;

                case 2:
                    map[yCoor + i, xCoor]  = 5;
                    cMap[yCoor + i, xCoor] = true;

                    if (map[yCoor + i, xCoor - 1] == 0 || map[yCoor + i, xCoor - 1] == 7 || map[yCoor + i, xCoor - 1] == 1)
                    {
                        map[yCoor + i, xCoor - 1] = 4;
                    }
                    else if (i == 0 && map[yCoor + i, xCoor - 1] == 8)
                    {
                        map[yCoor + i, xCoor - 1] = 11;
                    }
                    else if (map[yCoor + i, xCoor - 1] == 2)
                    {
                        map[yCoor + i, xCoor - 1] = 13;
                    }

                    if (map[yCoor + i, xCoor + 1] == 0 || map[yCoor + i, xCoor + 1] == 9 || map[yCoor + i, xCoor + 1] == 3)
                    {
                        map[yCoor + i, xCoor + 1] = 6;
                    }
                    else if (i == 0 && map[yCoor + i, xCoor + 1] == 8)
                    {
                        map[yCoor + i, xCoor + 1] = 10;
                    }
                    else if (map[yCoor + i, xCoor + 1] == 2)
                    {
                        map[yCoor + i, xCoor + 1] = 12;
                    }

                    if (((i + 1) < length) && (map[yCoor + i + 1, xCoor] == 5))
                    {
                        i = length;
                    }

                    break;

                case 3:
                    map[yCoor, xCoor - i]  = 5;
                    cMap[yCoor, xCoor - i] = true;

                    if (map[yCoor - 1, xCoor - i] == 0 || map[yCoor - 1, xCoor - i] == 1 || map[yCoor - 1, xCoor - i] == 3)
                    {
                        map[yCoor - 1, xCoor - i] = 2;
                    }
                    else if (i == 0 && map[yCoor - 1, xCoor - i] == 4)
                    {
                        map[yCoor - 1, xCoor - i] = 13;
                    }
                    else if (map[yCoor - 1, xCoor - i] == 6)
                    {
                        map[yCoor - 1, xCoor - i] = 12;
                    }

                    if (map[yCoor + 1, xCoor - i] == 0 || map[yCoor + 1, xCoor - i] == 7 || map[yCoor + 1, xCoor - i] == 9)
                    {
                        map[yCoor + 1, xCoor - i] = 8;
                    }
                    else if (i == 0 && map[yCoor + 1, xCoor - i] == 4)
                    {
                        map[yCoor + 1, xCoor - i] = 11;
                    }
                    else if (map[yCoor + 1, xCoor - i] == 6)
                    {
                        map[yCoor + 1, xCoor - i] = 10;
                    }

                    if (((i + 1) < length) && (map[yCoor, xCoor - i - 1] == 5))
                    {
                        i = length;
                    }

                    break;
                }
            }
        }
示例#58
0
        /*
         * Inicia algoritmo de busqueda
         */
        private void btnIniciar_Click(object sender, EventArgs e)
        {
            botonEnviar = true;
            int a = (int.Parse(button1.Text));

            /*
             * Tomo los valores del boton
             */
            int[,] inicio = { { System.Int32.Parse(button1.Text), Int32.Parse(button2.Text), Int32.Parse(button3.Text) },
                              { Int32.Parse(button4.Text),        Int32.Parse(button5.Text), Int32.Parse(button6.Text) },
                              { Int32.Parse(button7.Text),        Int32.Parse(button8.Text), Int32.Parse(button9.Text) } };
            int[,] sino = { { Int32.Parse(button01.Text), Int32.Parse(button02.Text), Int32.Parse(button03.Text) },
                            { Int32.Parse(button04.Text), Int32.Parse(button05.Text), Int32.Parse(button06.Text) },
                            { Int32.Parse(button07.Text), Int32.Parse(button08.Text), Int32.Parse(button09.Text) } };
            /*Me percate que no imprime el arreglo*/
            //vv_lb.Text = inicio.ToString();
            Nodo inicial = new Nodo(inicio);

            inicial.Equals(inicio);
            BuscarSolucion(inicial, sino);

            void BuscarSolucion(Nodo inici, int[,] sin)
            {
                List <Nodo> Expancion = new List <Nodo>(); // crea un arraylist para guardar el nodo creado
                List <Nodo> visitar   = new List <Nodo>(); // array para identificar las rutas encontradas

                Expancion.Add(inici);
                Expancion.RemoveAt(0);
                int contador = 0;

                /*
                 * Todo el algoritmo de busqueda quedo en esta parte
                 */
                int ayu = 0;

                while (Expancion.Count != 0)
                {
                    contador++;

                    Nodo  Revisar = new Nodo(Expancion);                //no se que error tiene
                    int[] zerop   = UbicacionCero(Revisar.GetEstado()); //recive las pocisiones

                    List <Nodo> hijos = new List <Nodo>();
                    visitar.Add(Revisar);
                    /*Aqui esta lo que te digo, necesito enviar tanto la clase como el los dos puntos de zerop[0],zerop[1]*/
                    if (zerop[0] != 0)
                    {
                        Nodo hijo = new Nodo(clonar(Revisar.GetEstado()));
                        int[,] arrb = hijo.GetEstado();
                        ayu         = arrb[zerop[0], zerop[0]];
                        arrb[zerop[0], zerop[0]] = arrb[zerop[0] - 1, zerop[1]];
                        arrb[zerop[0], zerop[1]] = ayu;

                        /* int[,] arrb = hijo.GetEstado() [zerop[0] - 1 zerop[1]];
                         * hijo.GetEstado()[zerop[0]][zerop[1]] = arrb; *//*aqui necesito igualar tanto el objeto como el array al entero arrb*/
                        /* hijo.GetEstado() + [zerop[0] - 1][zerop[1]] = 0;
                         * Expancion.Add(hijo);
                         * hijos.Add(hijo);
                         */
                    }
                    if (zerop[0] != 2)
                    {
                        Nodo hijo = new Nodo(clonar(Revisar.GetEstado()));
                        int[,] arrb = hijo.GetEstado();
                        ayu         = arrb[zerop[0], zerop[0]];
                        arrb[zerop[0], zerop[0]] = arrb[zerop[0] + 1, zerop[1]];
                        arrb[zerop[0], zerop[1]] = ayu;

                        /* int[,] abj = hijo.GetEstado() + [zerop[0] + 1][zerop[1]];
                         * hijo.GetEstado() + [zerop[0]][zerop[1]] = abj;
                         * hijo.GetEstado() + [zerop[0] + 1][zerop[1]] = 0;
                         * Expancion.Add(hijo);
                         * hijos.Add(hijo);*/
                    }
                    if (zerop[1] != 0)
                    {
                        Nodo hijo = new Nodo(clonar(Revisar.GetEstado()));
                        int[,] arrb = hijo.GetEstado();
                        ayu         = arrb[zerop[0], zerop[0]];
                        arrb[zerop[0], zerop[0]] = arrb[zerop[0], zerop[1] - 1];
                        arrb[zerop[0], zerop[1]] = ayu;

                        /*int[,] izq = hijo.GetEstado() +[zerop[0]][zerop[1] - 1];
                         * hijo.GetEstado() + [zerop[0]][zerop[1]] = izq;
                         * hijo.GetEstado() + [zerop[0]][zerop[1] - 1] = 0;
                         * Expancion.Add(hijo);
                         * hijos.Add(hijo);*/
                    }
                    if (zerop[1] != 2)
                    {
                        Nodo hijo = new Nodo(clonar(Revisar.GetEstado()));
                        int[,] arrb = hijo.GetEstado();
                        ayu         = arrb[zerop[0], zerop[0]];
                        arrb[zerop[0], zerop[0]] = arrb[zerop[0], zerop[1] + 1];
                        arrb[zerop[0], zerop[1]] = ayu;

                        /*int[,] der = hijo.GetEstado() + [zerop[0]][zerop[1] + 1];
                         * hijo.GetEstado() + [zerop[0]][zerop[1]] = der;
                         * hijo.GetEstado() + [zerop[0]][zerop[1] + 1] = 0;
                         * Expancion.Add(hijo);
                         * hijos.Add(hijo);*/
                    }
                    Revisar.SetHijos(hijos);
                }
                ;
            }

            // muchas de las propiedas de las funciones mandaban un error que no eran compatibles entre ellas
            // por eso algunas veces crea objetos de mas solo para poder guardarlos y utilizarlos
            int[] UbicacionCero(int[,] revisar)
            {
                // otra vez se crea un arraylist para resivir el nodo
                int[] Posicion = new int[2]; // este solo guarda las ubucaciones de los nodos finales o el nodo final
                                             // pase el arraylist a un array para poder examinarlo en for
                for (int i = 0; i < revisar.Length; i++)
                {
                    for (int g = 0; g < revisar.Length; g++)
                    {
                        if (revisar[i, g] == 0)
                        {
                            Posicion[0] = i;
                            Posicion[1] = g;
                        }
                    }
                }
                return(Posicion);
            }

            int[,] clonar(int[,] v)//clonamos los array, para poder imprimirlos sin errores
            {
                int[,] clon = new int[v.Length, v.Length];
                for (int i = 0; i < v.Length; i++)
                {
                    for (int g = 0; g < v.Length; g++)
                    {
                        clon[i, g] = v[i, g];
                    }
                }
                return(clon);
            }

            /*
             * Finaliza Algoritmo de busqueda
             */
        }
        //Checks if the given coordinate can house a room
        //within the given constraints. (maxRoomWidth,
        //minRoomHeight, ect.)
        //Returns whether a room can fit or not
        public bool canRoomFit(int[,] map, int xCoor, int yCoor)
        {
            //Console.WriteLine("xCoor" + xCoor);
            //Console.WriteLine("yCoor" + yCoor);
            int stretchTall = 0;
            int stretchWide = 0;

            for (int i = 0; i <= minRoomWidth; i++)
            {
                //Console.WriteLine("Left:" + (xCoor - i));
                //Console.WriteLine("Right:" + (xCoor + i));
                if (xCoor - i <= 1 || (xCoor + i) >= map.GetLength(1))
                {
                    return(false);
                }
                if (map[yCoor, xCoor - i] != 0)
                {
                    return(false);
                }
                if (map[yCoor, xCoor + i] != 0)
                {
                    return(false);
                }

                stretchWide = i;
            }
            for (int i = 0; i <= minRoomHeight; i++)
            {
                //Console.WriteLine("Up:" + (yCoor - i));
                //Console.WriteLine("Down:" + (yCoor + i));
                if (yCoor - i <= 1 || (yCoor + i) >= map.GetLength(0))
                {
                    return(false);
                }
                if (map[yCoor - i, xCoor] != 0)
                {
                    return(false);
                }
                if (map[yCoor + i, xCoor] != 0)
                {
                    return(false);
                }

                stretchTall = i;
            }
            if (map[yCoor - stretchTall, xCoor - stretchWide] != 0 || map[yCoor - stretchTall, xCoor + stretchWide] != 0)
            {
                return(false);
            }
            else if (map[yCoor + stretchTall, xCoor - stretchWide] != 0 || map[yCoor + stretchTall, xCoor + stretchWide] != 0)
            {
                return(false);
            }


            //for (int i = 0; i <= minRoomWidth || i <= minRoomHeight; i++)
            //{
            //    Console.WriteLine(i);
            //    if (stretchWide == 0)
            //    {
            //        if (i < minRoomWidth)
            //        {
            //            //Console.WriteLine("Left:" + (xCoor - i));
            //            //Console.WriteLine("Right:" + (xCoor + i));
            //            if (xCoor - i >= 1 || (xCoor + i) <= map.GetLength(1))
            //                return false;
            //            if (map[yCoor, xCoor - i] != 0 || map[yCoor, xCoor + i] != 0)
            //                return false;
            //        }
            //        else if (i == minRoomWidth)
            //        {
            //            stretchWide = minRoomWidth;
            //        }
            //    }

            //    if (stretchTall != 0)
            //    {
            //        if (map[yCoor - stretchTall, xCoor - i] != 0 || map[yCoor - stretchTall, xCoor + i] != 0)
            //            return false;
            //        else if (map[yCoor + stretchTall, xCoor - i] != 0 || map[yCoor + stretchTall, xCoor + i] != 0)
            //            return false;
            //    }

            //    if (stretchTall == 0)
            //    {
            //        if (i < minRoomHeight)
            //        {
            //            //Console.WriteLine("Up:" + (yCoor - i));
            //            //Console.WriteLine("Down:" + (yCoor + i));
            //            if (yCoor - i >= 1 || (yCoor + i) <= map.GetLength(0))
            //                return false;
            //            if (map[yCoor - i, xCoor] != 0 || map[yCoor + i, xCoor] != 0)
            //                return false;
            //        }
            //        else if (i == minRoomHeight)
            //        {
            //            stretchTall = minRoomHeight;
            //        }
            //    }

            //    if (stretchWide != 0)
            //    {
            //        if (map[yCoor - i, xCoor - stretchWide] != 0 || map[yCoor - i, xCoor + stretchWide] != 0)
            //            return false;
            //        else if (map[yCoor + i, xCoor - stretchWide] != 0 || map[yCoor + i, xCoor + stretchWide] != 0)
            //            return false;
            //    }

            //}

            //Console.WriteLine("Room fits");

            return(true);
        }
        //Places a room in the given tilemap using given coordinates and given constraints
        //enumerated at the top of the class.
        //Returns a Room object, which contains x,y coordinates, width, and height.
        public Room placeRoom(int[,] map, bool[,] cMap, int xCoor, int yCoor)
        {
            Room placedRoom;

            int randomWidthMax  = random.Next(minRoomWidth, maxRoomWidth);
            int randomHeightMax = random.Next(minRoomHeight, maxRoomHeight);

            //Console.WriteLine("Random Width Max" + randomWidthMax);
            //Console.WriteLine("Random Height Max" + randomHeightMax);

            int  leftMapBound  = 0;
            int  rightMapBound = map.GetLength(1) - 1;
            int  upperMapBound = 0;
            int  lowerMapBound = map.GetLength(0) - 1;
            int  leftBound     = xCoor - minRoomWidth;
            int  rightBound    = xCoor + minRoomWidth;
            int  upperBound    = yCoor - minRoomHeight;
            int  lowerBound    = yCoor + minRoomHeight;
            bool leftSet       = false;
            bool rightSet      = false;
            bool upperSet      = false;
            bool lowerSet      = false;

            //Console.WriteLine("X:" + xCoor);
            //Console.WriteLine("Y:" + yCoor);
            //Console.WriteLine("LeftBound:" + leftBound);
            //Console.WriteLine("Right Bound:" + rightBound);
            //Console.WriteLine("UpperBound:" + upperBound);
            //Console.WriteLine("Lower Bound:" + lowerBound);

            //for (int i = minRoomWidth; i < randomWidthMax; i++)
            //{
            //    if (map[yCoor, xCoor - i] != 0 || map[yCoor, xCoor + i] != 0)
            //    {
            //        leftBound = xCoor - i + 1;
            //        rightBound = xCoor + i - 1;
            //        i = randomWidthMax;
            //    }
            //}

            //for (int i = minRoomHeight; i < randomHeightMax; i++)
            //{
            //    if (map[yCoor - i, xCoor] != 0 || map[yCoor + i, xCoor] != 0)
            //    {
            //        upperBound = yCoor - i + 1;
            //        lowerBound = yCoor + i - 1;
            //        i = randomHeightMax;
            //    }
            //}

            int sizeCounter = (int)MathHelper.Min(minRoomHeight, minRoomWidth);

            while (sizeCounter <= randomWidthMax || sizeCounter <= randomHeightMax)
            {
                //Console.WriteLine(sizeCounter);

                if ((!leftSet || !upperSet) && map[yCoor - sizeCounter, xCoor - sizeCounter] != 0)
                {
                    //Console.WriteLine("Upper Left collision detected");
                    if (!leftSet)
                    {
                        leftBound = xCoor - sizeCounter + 1;
                        leftSet   = true;
                    }
                    else if (!upperSet)
                    {
                        upperBound = yCoor - sizeCounter + 1;
                        upperSet   = true;
                    }
                }

                if ((!rightSet || !upperSet) && map[yCoor - sizeCounter, xCoor + sizeCounter] != 0)
                {
                    //Console.WriteLine("Upper right collision detected");
                    if (!rightSet)
                    {
                        rightBound = xCoor + sizeCounter - 1;
                        rightSet   = true;
                    }
                    if (!upperSet)
                    {
                        upperBound = yCoor - sizeCounter + 1;
                        upperSet   = true;
                    }
                }

                if ((!leftSet || !lowerSet) && map[yCoor + sizeCounter, xCoor - sizeCounter] != 0)
                {
                    //Console.WriteLine("Lower Left collision detected");

                    if (!leftSet)
                    {
                        leftBound = xCoor - sizeCounter + 1;
                        leftSet   = true;
                    }
                    if (!lowerSet)
                    {
                        lowerBound = yCoor + sizeCounter - 1;
                        lowerSet   = true;
                    }
                }

                if ((!rightSet && !lowerSet) && map[yCoor + sizeCounter, xCoor + sizeCounter] != 0)
                {
                    //Console.WriteLine("Lower right collision detected");

                    if (!lowerSet)
                    {
                        lowerBound = yCoor + sizeCounter - 1;
                        lowerSet   = true;
                    }
                    if (!rightSet)
                    {
                        rightBound = xCoor + sizeCounter - 1;
                        rightSet   = true;
                    }
                }

                if (sizeCounter <= randomWidthMax)
                {
                    if (!leftSet)
                    {
                        if (map[yCoor, xCoor - sizeCounter] != 0)
                        {
                            leftBound = xCoor - sizeCounter + 1;
                            leftSet   = true;
                        }
                        if (map[yCoor, xCoor - sizeCounter] == 0)
                        {
                            leftBound = xCoor - sizeCounter;
                        }
                    }

                    if (!rightSet)
                    {
                        if (map[yCoor, xCoor + sizeCounter] != 0)
                        {
                            rightBound = xCoor + sizeCounter - 1;
                            rightSet   = true;
                        }
                        if (map[yCoor, xCoor + sizeCounter] == 0)
                        {
                            rightBound = xCoor + sizeCounter;
                        }
                    }
                }

                if (sizeCounter <= randomHeightMax)
                {
                    if (!upperSet)
                    {
                        if (map[yCoor - sizeCounter, xCoor] != 0)
                        {
                            upperBound = yCoor - sizeCounter + 1;
                            upperSet   = true;
                        }
                        else if (map[yCoor - sizeCounter, xCoor] == 0)
                        {
                            upperBound = yCoor - sizeCounter;
                        }
                    }

                    if (!lowerSet)
                    {
                        if (map[yCoor + sizeCounter, xCoor] != 0)
                        {
                            lowerBound = yCoor + sizeCounter - 1;
                            lowerSet   = true;
                        }
                        else if (map[yCoor + sizeCounter, xCoor] == 0)
                        {
                            lowerBound = yCoor + sizeCounter;
                        }
                    }
                }

                if (leftSet && rightSet && upperSet && lowerSet)
                {
                    //Console.WriteLine("Terminating loop - all bounds set");
                    sizeCounter = (int)MathHelper.Max(maxRoomWidth, maxRoomHeight) + 1;
                }

                sizeCounter++;

                if (xCoor - sizeCounter < leftMapBound || xCoor + sizeCounter > rightMapBound || yCoor - sizeCounter < upperMapBound || yCoor + sizeCounter > lowerMapBound)
                {
                    //Console.WriteLine("Terminating loop - room bounds went are illegal");
                    sizeCounter = (int)MathHelper.Max(maxRoomWidth, maxRoomHeight);
                }
            }

            //Console.WriteLine("LeftBound:" + leftBound);
            //Console.WriteLine("Right Bound:" + rightBound);
            //Console.WriteLine("UpperBound:" + upperBound);
            //Console.WriteLine("Lower Bound:" + lowerBound);

            map[upperBound, leftBound]  = 1;
            map[upperBound, rightBound] = 3;
            map[lowerBound, leftBound]  = 7;
            map[lowerBound, rightBound] = 9;

            for (int i = upperBound + 1; i < lowerBound; i++)
            {
                map[i, leftBound]  = 4;
                map[i, rightBound] = 6;
            }
            for (int i = leftBound + 1; i < rightBound; i++)
            {
                map[upperBound, i] = 2;
                map[lowerBound, i] = 8;
            }

            for (int i = upperBound + 1; i < lowerBound; i++)
            {
                for (int j = leftBound + 1; j < rightBound; j++)
                {
                    map[i, j]  = 5;
                    cMap[i, j] = true;
                }
            }
            //tileMap[yCoor, xCoor] = 14;

            //Console.WriteLine("Actual Width:" + (rightBound - leftBound + 1));
            //Console.WriteLine("Actual Height:" + (lowerBound - upperBound + 1));
            Rectangle dimensions = new Rectangle(leftBound, upperBound, rightBound - leftBound + 1, lowerBound - upperBound + 1);

            placedRoom = new Room(dimensions);
            return(placedRoom);
        }