コード例 #1
0
 public VacuumEnvironment()
 {
     Random r = new Random();
     envState = new VacuumEnvironmentState(
             0 == r.nextInt(2) ? LocationState.Clean : LocationState.Dirty,
             0 == r.nextInt(2) ? LocationState.Clean : LocationState.Dirty);
 }
コード例 #2
0
ファイル: LavaTile.cs プロジェクト: xposure/MiniCraft.NET
        public override void render(Screen screen, Level level, int x, int y)
        {
            wRandom = new Random((int)((tickCount + (x / 2 - y) * 4311) / 10 * 54687121L + x * 3271612L + y * 3412987161L));
            //TODO: wRandom.setSeed((tickCount + (x / 2 - y) * 4311) / 10 * 54687121L + x * 3271612L + y * 3412987161L);
            int col = ColorHelper.get(500, 500, 520, 550);
            int transitionColor1 = ColorHelper.get(3, 500, level.dirtColor - 111, level.dirtColor);
            int transitionColor2 = ColorHelper.get(3, 500, level.sandColor - 110, level.sandColor);

            bool u = !level.getTile(x, y - 1).connectsToLava;
            bool d = !level.getTile(x, y + 1).connectsToLava;
            bool l = !level.getTile(x - 1, y).connectsToLava;
            bool r = !level.getTile(x + 1, y).connectsToLava;

            bool su = u && level.getTile(x, y - 1).connectsToSand;
            bool sd = d && level.getTile(x, y + 1).connectsToSand;
            bool sl = l && level.getTile(x - 1, y).connectsToSand;
            bool sr = r && level.getTile(x + 1, y).connectsToSand;

            if (!u && !l)
            {
                screen.render(x * 16 + 0, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4));
            }
            else
                screen.render(x * 16 + 0, y * 16 + 0, (l ? 14 : 15) + (u ? 0 : 1) * 32, (su || sl) ? transitionColor2 : transitionColor1, 0);

            if (!u && !r)
            {
                screen.render(x * 16 + 8, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4));
            }
            else
                screen.render(x * 16 + 8, y * 16 + 0, (r ? 16 : 15) + (u ? 0 : 1) * 32, (su || sr) ? transitionColor2 : transitionColor1, 0);

            if (!d && !l)
            {
                screen.render(x * 16 + 0, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4));
            }
            else
                screen.render(x * 16 + 0, y * 16 + 8, (l ? 14 : 15) + (d ? 2 : 1) * 32, (sd || sl) ? transitionColor2 : transitionColor1, 0);
            if (!d && !r)
            {
                screen.render(x * 16 + 8, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4));
            }
            else
                screen.render(x * 16 + 8, y * 16 + 8, (r ? 16 : 15) + (d ? 2 : 1) * 32, (sd || sr) ? transitionColor2 : transitionColor1, 0);
        }
コード例 #3
0
 public void testHashCodesM3_32_ints()
 {
     int seed = 123;
     Random rand = new Random(seed);
     HashFunction hf = Hashing.murmur3_32(seed);
     for (int i = 0; i < 1000; i++)
     {
         int val = rand.nextInt();
         byte[] data = ByteBuffer.allocate(4).putInt(val).array();
         int hc1 = hf.hashBytes(data).asInt();
         int hc2 = Murmur3.hash32(data, data.length, seed);
         Assert.Equal(hc1, hc2);
     }
 }
コード例 #4
0
 private static DateFormat randomDateStyle(Random random)
 {
     return DATE_STYLES[random.nextInt(DATE_STYLES.Length)];
 }
コード例 #5
0
        public void testHashCodesM3_128_ints()
        {
            int seed = 123;
            Random rand = new Random(seed);
            HashFunction hf = Hashing.murmur3_128(seed);
            for (int i = 0; i < 1000; i++)
            {
                int val = rand.nextInt();
                byte[] data = ByteBuffer.allocate(4).putInt(val).array();
                // guava stores the hashcodes in little endian order
                ByteBuffer buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
                buf.put(hf.hashBytes(data).asBytes());
                buf.flip();
                long gl1 = buf.getLong();
                long gl2 = buf.getLong(8);
                long[] hc = Murmur3.hash128(data, 0, data.length, seed);
                long m1 = hc[0];
                long m2 = hc[1];
                Assert.Equal(gl1, m1);
                Assert.Equal(gl2, m2);

                byte[] offsetData = new byte[data.length + 50];
                Array.Copy(data, 0, offsetData, 50, data.length);
                hc = Murmur3.hash128(offsetData, 50, data.length, seed);
                Assert.Equal(gl1, hc[0]);
                Assert.Equal(gl2, hc[1]);
            }
        }