コード例 #1
0
ファイル: Soft3DBitmap.cs プロジェクト: Gaunt/Soft3D
 public static unsafe Bitmap ToBitmap(Int32[,] pole)
 {
     Bitmap b;
     fixed(int* pp = &pole[0,0])
      b= new Bitmap(pole.GetLength(1), pole.GetLength(0),pole.GetLength(1)*4, System.Drawing.Imaging.PixelFormat.Format32bppArgb,(IntPtr)pp);
     return b;
 }
コード例 #2
0
ファイル: TexturedTriangle.cs プロジェクト: Gaunt/Soft3D
 //vytvori otexturovany trojuhelnik z t, s texturou texture namapovanou podle coords
 public TexturedTriangle(Triangle3D t,Triangle2D coords,Int32[,] texture)
     : base(t.V1,t.V2,t.V3)
 {
     texcoords = coords;
     bitmap = texture;
     width = texture.GetLength(0);
     height = texture.GetLength(1);
     port = new Viewport(1,1,width,width);
 }
コード例 #3
0
        static void Main(string[] args)
        {
            var stream = Console.In;
            string line;
            while ((line = stream.ReadLine()) != null)
            {
                File.AppendAllLines("debug.txt", new[] {line});
                var strings = line.Split(' ');
                var planets = Int32.Parse(strings[0]);
                var earthIndex = Int32.Parse(strings[1]);
                var atlantisIndex = Int32.Parse(strings[2]);
                var distances = new Int32[planets,planets];
                _initializeDistances(distances);

                for (int i = 3; i < strings.Length; i++)
                {
                    var aux = strings[i].Split(',');
                    if (aux.Length != 3) continue;
                    distances[Int32.Parse(aux[0]), Int32.Parse(aux[1])] = Int32.Parse(aux[2]);
                }

                List<BellmanFord.Vertex> vertices = new List<BellmanFord.Vertex>();
                for (int i = 0; i < planets; i++)
                {
                    vertices.Add(new BellmanFord.Vertex() { id = i});
                }

                List<BellmanFord.Edge> edges = new List<BellmanFord.Edge>();
                for (int i = 0; i < distances.GetLength(0); i++)
                {
                    for (int z = 0; z < distances.GetLength(1); z++)
                    {
                        edges.Add(new BellmanFord.Edge()
                                      {
                                          Source = vertices[i],
                                          Destination = vertices[z],
                                          Weight = Int32.MaxValue == distances[i,z] ? Double.PositiveInfinity : distances[i,z]
                                      });
                    }
                }

                try
                {
                    BellmanFord.Run(vertices, edges,  vertices[earthIndex]);
                    Console.WriteLine(25000 + vertices[atlantisIndex].Distance);

                }
                catch (Exception e)
                {
                    Console.WriteLine("BAZINGA");
                }
                if (stream.Peek() == -1) break;
            }
        }
コード例 #4
0
ファイル: .Soft3dScreen.cs プロジェクト: Gaunt/Soft3D
        private double[,] zbuffer; //pamet hloubky

        #endregion Fields

        #region Constructors

        //nastavi promenne na defaultni hodnoty.
        //parametrem bitmap se predava odkaz na bitmapu do ktere se bude kreslit
        public Soft3DScreen(Int32[,] bitmap)
        {
            screen = bitmap;
            screenHeight = bitmap.GetLength(1);
            screenWidth = bitmap.GetLength(0);
            zbuffer = new double[screenWidth, screenHeight];
            for(int i = 0;i<screenWidth;i++)
              for(int j = 0;j<screenHeight;j++)
                zbuffer[i,j] = 1;//inicializace z bufferu na max hodnotu

            projection = new Projection(Math.PI/4,(double)screenWidth/(double)screenHeight,
            2.4,50);//nastaveni projekce,zorny uhel je 45 stupnu
            viewport = new Viewport(2,2,
                        screenWidth,screenHeight);
            byte[] white = {255,255,255,255};
            color = BitConverter.ToInt32(white, 0);
            viewMatrix=Matrix44.GetIdentityMatrix();
        }
コード例 #5
0
 public void EqualsTest()
 {
     var data = new Int32[,] { { 0, 0 }, { -1, -1 }, { 1, 1 } };
     var length = data.GetLength(0);
     for (var i = 0; i < length; i++)
     {
         InteropInt32 interopInt32 = data[i, 0];
         InteropInt32 interopInt322 = data[i, 1];
         Assert.IsTrue(interopInt32.Equals(interopInt322));
     }
 }
コード例 #6
0
        static void Main(string[] args)
        {
            int[,] ladder = new Int32[,] {
            {1,38},{4,14},{9,31},{21,42},{28,84},{51,67},{71,91},{80,100}
            };

            int[,] snake = new Int32[,]{
            {17,7},{54,34},{62,19},{64,60},{87,24},{93,73},{95,75},{98,79}
            };
            int i = 0;
            int j = 0;
            int your_turn;

            Console.WriteLine("Ïnput -> How many players in games:\t");
            int user_no = Convert.ToInt16(Console.ReadLine());

            int[,] user_array = new int[user_no, 2]; //how many users will be involved in snake gme

            // store users into array
            for (i = 0; i < user_no; i++)
            {
                for (j = 0; j < 2; j++)
                {
                    if (j == 0)
                        user_array[i, j] = i + 1;
                    else
                        user_array[i, j] = 0;
                    //Console.WriteLine(user_array[i,j]);
                }
            }

            int goal = 0;
            while (goal < 100) // winner stage
            {
                for (i = 0; i < user_no; i++) // need to make one by one
                {

                    if (user_array[i, 1] >= 100) // get user step from array to check goal or not
                    {
                        goal = 100;
                        break; // Reached point
                    }

                    else // if not reach goal, go on
                    {

                        int turn = 0; // we need to go one by on. Don't make two twice.

                        while (turn != i + 1) // we need to go one by on. Don't make two twice.
                        {
                            Console.Write("\nEnter Your turn:\t");
                            your_turn = Convert.ToInt16(Console.ReadLine());// now. who is turn?

                            if (your_turn == i + 1)
                            {
                                Random rnd = new Random(); // declare random number
                                int rnd_no = rnd.Next(1, 6); // get one random number

                                Console.WriteLine("Your existing step is " + user_array[i, 1] + "\n");

                                user_array[i, 1] += rnd_no;

                                turn = i + 1; // 1; end while; let's go to for loop

                                for (int a = 0; a < ladder.GetLength(0); a++)
                                {

                                    if (ladder[a, 0] == user_array[i, 1])
                                    {
                                        //    Console.WriteLine("Random number is " + rnd_no+"\nCongrat!!!!!  You get a ladder:   "+ladder[a,1]);
                                        Console.WriteLine("\nCongrat!!!!!  You get a ladder:   " + ladder[a, 1]);
                                        user_array[i, 1] = ladder[a, 1];

                                        //    Console.WriteLine("You reached here:   " + user_array[i,1]);
                                    }
                                    if (snake[a, 0] == user_array[i, 1])
                                    {
                                        //    Console.WriteLine("Random number is " + rnd_no + "\nYou get a snake:   " + snake[a, 1]);
                                        Console.WriteLine("\nYou get a snake:   " + snake[a, 1]);
                                        user_array[i, 1] = snake[a, 1];
                                        //    Console.WriteLine("You reached here:   " + user_array[i, 1]);
                                    }
                                }

                                if (user_array[i, 1] > 100)
                                {
                                    int value = user_array[i, 1] - 100;
                                    int value1 = 100 - value;
                                    user_array[i, 1] = value1;
                                    Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *******Now Your Step is " + user_array[i, 1] + "\n"); // show user your step

                                }
                                else if (user_array[i, 1] == 100) // for check to get goal
                                {
                                    goal = 100;
                                    // show user your step
                                    Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *** Now Your Step is  " + user_array[i, 1] + "\n");

                                    i = user_no + user_no;      // for break while and for
                                    turn = i + 1;               // for break while and for

                                    break;
                                }
                                else
                                    Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *** Now Your Step is  " + user_array[i, 1] + "\n"); // show user your step

                                break;
                            }

                            else
                            {
                                Console.WriteLine("\nSo Sorry!\nIt is not your turn:Now Player No:  " + (i + 1) + " turn!!!");
                                turn = your_turn; // let go while loop coz not your turn!!!! Try again!

                            }

                        }//end while

                    }//end else

                }//end for
                Console.WriteLine("________________________________________________________");
            }//end while

            if (goal == 10)
            {
                for (i = 0; i < user_no; i++)
                {
                    j = 1;

                    Console.WriteLine("\n\n" + user_array[i, j]);

                }

            }
        }
コード例 #7
0
ファイル: co5127getlength_int.cs プロジェクト: ArildF/masters
 public Boolean runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strBaseLoc;
   short[] in2Arr = new Int16[10]; 
   int[] in4Arr = new Int32[5]; 
   long[] in8Arr = new Int64[0]; 
   String[] strArr = new String[6]; 
   Boolean[] boArr = new Boolean[3]; 
   Double[] dblArr = new Double[2]; 
   Single[] snglArr = new Single[32000]; 
   Char[] chArr = new Char[10000]; 
   int rank;
   try {
   LABEL_860_GENERAL:
   do
     {
     strLoc = "Loc_819yt";
     rank = -1;
     in2Arr = new Int16[5];
     iCountTestcases++;
     try {
     in2Arr.GetLength(rank);
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_499ws! , GetLength=="+in2Arr.Length);
     } catch (IndexOutOfRangeException ioorExc) {}
     catch (Exception exc) {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_758! exc=="+exc);
     }
     strLoc = "Loc_819ee";
     rank = 1;
     in2Arr = new Int16[5];
     iCountTestcases++;
     try {
     in2Arr.GetLength(rank);
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_500ws! , GetLength=="+in2Arr.Length);
     } catch (IndexOutOfRangeException ioorExc) {}
     catch (Exception exc) {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_750! exc=="+exc);
     }
     strLoc = "Loc_482wu";
     rank = 0;
     in2Arr = new Int16[10];
     iCountTestcases++;
     if(in2Arr.GetLength(rank) != 10)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_481ua! , GetLength=="+in2Arr.Length);
       }
     strLoc = "Loc_471ay";
     in4Arr = new Int32[5];
     iCountTestcases++;
     if(in4Arr.GetLength(rank) != 5)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_29qaq! , GetLength=="+in4Arr.Length);
       }
     strLoc = "Loc_982uq";
     in8Arr = new Int64[0];
     iCountTestcases++;
     if(in8Arr.GetLength(rank) != 0)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_237sy! , GetLength=="+in8Arr.Length);
       }
     strLoc = "Loc_172ms";
     boArr = new Boolean[3];
     iCountTestcases++;
     if(boArr.GetLength(rank) != 3)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_382! , GetLength=="+boArr.Length);
       }
     strLoc = "Loc_49su";
     dblArr = new Double[2];
     iCountTestcases++;
     if(dblArr.GetLength(rank) != 2)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_200su! , GetLength=="+dblArr.Length);
       }
     strLoc = "Loc_371su";
     snglArr = new Single[32000];
     iCountTestcases++;
     if(snglArr.GetLength(rank) != 32000)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_319aw! , GetLength=="+snglArr.Length);
       }
     strLoc = "Loc_129wi";
     strArr = new String[5];
     strArr[2] = null;
     iCountTestcases++;
     if(strArr.GetLength(rank) != 5)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_71ahw! , GetLength=="+strArr.Length);
       }
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
コード例 #8
0
        public static bool IsEqual(this Int16[][] a, Int32[][] b, Int32 atol = 0, Double rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            if (rtol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i][j];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

            }
            else if (atol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i][j];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

            }
            else
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i][j];
    if (A != B)
        return false;
}

            }

            return true;
        }
コード例 #9
0
        public static bool IsEqual(this sbyte[,] a, Int32[,] b, Int32 atol = 0, Double rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            unsafe
            {
                fixed (sbyte* ptrA = a)
                fixed (Int32* ptrB = b)
                {
                    if (rtol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

                    }
                    else if (atol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

                    }
                    else
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A != B)
        return false;
}

                    }
                }
            }

            return true;
        }
コード例 #10
0
        public static bool IsEqual(this Decimal[][] a, Int32[,] b, Decimal atol = 0, Decimal rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            if (rtol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i, j];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

            }
            else if (atol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i, j];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

            }
            else
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = (decimal)a[i][j];
    var B = (decimal)b[i, j];
    if (A != B)
        return false;
}

            }

            return true;
        }
コード例 #11
0
        public static bool IsEqual(this Decimal[,] a, Int32[,] b, Decimal atol = 0, Decimal rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            unsafe
            {
                fixed (Decimal* ptrA = a)
                fixed (Int32* ptrB = b)
                {
                    if (rtol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

                    }
                    else if (atol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

                    }
                    else
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = (decimal)ptrA[i];
    var B = (decimal)ptrB[i];
    if (A != B)
        return false;
}

                    }
                }
            }

            return true;
        }
コード例 #12
0
ファイル: PHPReader.cs プロジェクト: bluelovers/phprpc
 private Type GetType(StringBuilder typeName, Int32[] positions, Int32 i, Char c)
 {
     Int32 length = positions.GetLength(0);
     Type type;
     if (i < length) {
         typeName[positions[i++]] = c;
         type = GetType(typeName, positions, i, '.');
         if (i < length) {
             if (type == null) {
                 type = GetType(typeName, positions, i, '_');
             }
             if (type == null) {
                 type = GetNestedType(typeName, positions, i, '+');
             }
         }
     }
     else {
         type = GetType(typeName.ToString());
     }
     return type;
 }
コード例 #13
0
        /// <summary>
        /// Gets a serie of sprites according to movement offsets
        /// </summary>
        /// <param name="block">base block</param>
        /// <param name="movements">wall kicks</param>
        /// <param name="baseRotation">original rotation</param>
        /// <param name="iteration">display iteration</param>
        protected virtual List<Sprite> GetMovementSprites(Data.Block block, Int32[,] movements, Int32 baseRotation, Int32 iteration)
        {
            var sprites = new List<Sprite>();

            for (Int32 j = 0; j < movements.GetLength(0); j++)
            {
                // Grid
                sprites.Add(
                    new SpriteField(this.Game, _field)
                    {
                        Position = this.Position + SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX +
                            SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY,
                    }
                );

                // Block boundary
                sprites.Add(
                    new Sprite(this.Game)
                    {
                        TextureName = "Graphics/blank",
                        Size = Vector2.One * SpriteField.GridCellSize * block.Width,
                        Position = this.Position + SpriteField.GridCellSize * (2 + (_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY +
                            SpriteField.GridCellSize * (2 + (_field.Width + 1) * j) * Vector2.UnitX,
                        Opacity = 0.1f,
                        Color = Color.White,
                    }
                );

                // Add base sprite
                var baseBlock = (Data.Block)block.Clone();
                baseBlock.Rotation = baseRotation;

                sprites.Add(
                    new SpriteFallingBlock(this.Game,
                        new Data.FallingBlock(this.Game, baseBlock, _field, 2, block.Height + 1)
                    )
                    {
                        Position = this.Position + SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY +
                            SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX,
                        Opacity = 0.2f,
                    }
                );

                // Add kicked sprite
                sprites.Add(
                    new SpriteFallingBlock(this.Game,
                        new Data.FallingBlock(this.Game, (Data.Block)block.Clone(), _field,  2 + movements[j, 0], block.Height + 1 + movements[j, 1])
                    )
                    {
                        Position = this.Position + SpriteField.GridCellSize * ((_field.Height - SpriteField.HiddenRows + 1) * iteration) * Vector2.UnitY +
                            SpriteField.GridCellSize * ((_field.Width + 1) * j) * Vector2.UnitX
                    }
                );
            }

            return sprites;
        }
コード例 #14
0
ファイル: Problem11.cs プロジェクト: longje/Project-Euler
 static Boolean has4NumbersLeftDiag(int x, int y, Int32[,] grid)
 {
     var lengthDown = grid.GetLength(y);
     return (lengthDown - 4 < 0);
 }
コード例 #15
0
ファイル: Fills.cs プロジェクト: gkrsu/maparound.core
        /// <summary>
        /// Создает экземпляр PatternFill.
        /// </summary>
        /// <param name="pattern">Таблица значений пиекселй шаблона</param>
        /// <param name="originX">Координата x начала отсчета</param>
        /// <param name="originY">Координата y начала отсчета</param>
        public PatternFill(Int32[,] pattern, int originX, int originY)
        {
            if (pattern.GetLength(0) == 0 || pattern.GetLength(1) == 0)
                throw new ArgumentException("pattern");

            _pattern = pattern;
            _originX = originX;
            _originY = originY;
        }