public void BytePointConstructorTest()
        {
            BytePoint target = new BytePoint();

            Assert.AreEqual(target.Size, 0);
            Assert.IsNull(target.PointValues);
        }
示例#2
0
        public void OperateTest()
        {
            int shift = 1;
            ByteMutation_Shifts target = new ByteMutation_Shifts(shift);

            BytePoint p1 = new BytePoint(new byte[] { 1, 2, 3, 4 });
            BytePoint p2 = new BytePoint(new byte[] { 17, 2, 3, 46 });
            BytePoint p3 = new BytePoint(new byte[] { 4, 2, 36, 4 });
            BytePoint p4 = new BytePoint(new byte[] { 7, 26, 3, 4 });
            BytePoint p5 = new BytePoint(new byte[] { 35, 2, 33, 4 });

            PointSet expected = new PointSet(new HashSet <Point>()
            {
                p1, p2, p3, p4, p5
            });

            PointSet pointSet = new PointSet(new HashSet <Point>()
            {
                p1, p2, p3, p4, p5
            });
            PointSet actual;

            actual = target.Operate(pointSet);
            Assert.AreEqual(expected.Set.Count, actual.Set.Count);
        }
        public void BytePointConstructorTest1()
        {
            byte      value  = 0;
            BytePoint target = new BytePoint(value);

            Assert.AreEqual(target.Size, 1);
            Assert.IsNotNull(target.PointValues);
        }
        public void BytePointConstructorTest2()
        {
            byte[]    values = new byte[] { 3, 4, 5 };
            BytePoint target = new BytePoint(values);

            Assert.AreEqual(target.Size, 3);
            Assert.AreEqual(target.PointValues, values);
        }
        public void StringRepresentTest()
        {
            byte[]    tab      = new byte[] { 1, 2, 3, 4, 5 };
            BytePoint target   = new BytePoint(tab);
            string    expected = "[1\t2\t3\t4\t5]";
            string    actual;

            actual = target.StringRepresent();
            Assert.AreEqual(expected, actual);
        }
示例#6
0
        public void MutateTest()
        {
            int shift = 1;
            ByteMutation_Shifts target = new ByteMutation_Shifts(shift);
            Point point = new BytePoint(10);
            Point actual;

            actual = target.Mutate(point);
            Assert.IsTrue(actual.StringRepresent().Equals("[5]") || actual.StringRepresent().Equals("[20]"));
        }
        public void MutateTest()
        {
            int added = 2;
            ByteMutation_ValueAdded target = new ByteMutation_ValueAdded(added);
            Point point = new BytePoint(10);
            Point actual;

            actual = target.Mutate(point);
            Assert.IsTrue(actual.StringRepresent().Equals("[12]") || actual.StringRepresent().Equals("[8]"));
        }
        public void SetPointValueTest()
        {
            ByteEvaluation_Zeros target = new ByteEvaluation_Zeros();
            Point point = new BytePoint(5);
            Point actual;

            actual = target.SetPointValue(point);
            double x = actual.Value - 0.53333333333333333;

            Assert.IsTrue(Math.Abs(x) < 0.0001);
        }
        public void CrossTest()
        {
            ByteCrossover_RandomOR target = new ByteCrossover_RandomOR();
            Point point1   = new BytePoint(new byte[] { 0, 2, 3 });
            Point point2   = new BytePoint(new byte[] { 0, 2, 3 });
            Point expected = new BytePoint(new byte[] { 0, 2, 3 });
            Point actual;

            actual = target.Cross(point1, point2);
            Assert.AreEqual(expected.ToString(), actual.ToString());
        }
        public void PointValuesTest()
        {
            byte[]    tab    = new byte[] { 1, 2, 3, 4, 5 };
            BytePoint target = new BytePoint(tab);

            byte[] expected = new byte[] { 1, 2, 3, 4, 5 };
            byte[] actual;
            target.PointValues = expected;
            actual             = target.PointValues;
            Assert.AreEqual(expected, actual);
        }
示例#11
0
        /// <summary>
        /// Creates new point by crossing two points
        /// using byte operation 'and'
        /// </summary>
        /// <param name="point1">first point to be crossed</param>
        /// <param name="point2">second point to be crossed</param>
        override public Point Cross(Point point1, Point point2)
        {
            BytePoint xP = (BytePoint)point1;
            BytePoint yP = (BytePoint)point2;

            byte[] values = new byte[point1.Size];

            for (int i = 0; i < point1.Size; i++)
            {
                values[i] = (byte)(xP.PointValues[i] & yP.PointValues[i]);
            }

            return(new BytePoint(values));
        }
示例#12
0
        /// <summary>
        /// Set given point value
        /// p1 - how many ones in bytes
        /// p0 - how many zeros in bytes
        /// (p1 * 0.3 + p0) / (p0 + p1)
        /// </summary>
        /// <param name="point">point to be evaluated</param>
        override public Point SetPointValue(Point p)
        {
            BytePoint byteP = (BytePoint)p;

            int p0 = 0, p1 = 0;

            for (int i = 0; i < p.Size; i++)
            {
                Count(byteP.PointValues[i]);
                p0 += _zeros;
                p1 += _ones;
            }

            p.Value = ((double)(p1 * 0.3 + p0) / (p0 + p1));

            return(p);
        }
示例#13
0
        public void CreateTest()
        {
            int howMany = 5;
            int size    = 4; // TODO: Initialize to an appropriate value
            ByteInitialization_Regular target = new ByteInitialization_Regular(howMany, size);

            BytePoint p1       = new BytePoint(new byte[] { 1, 2, 3, 4 });
            BytePoint p2       = new BytePoint(new byte[] { 2, 2, 3, 46 });
            BytePoint p3       = new BytePoint(new byte[] { 3, 2, 36, 4 });
            BytePoint p4       = new BytePoint(new byte[] { 4, 26, 3, 4 });
            BytePoint p5       = new BytePoint(new byte[] { 5, 2, 33, 4 });
            PointSet  expected = new PointSet(new HashSet <Point>()
            {
                p1, p2, p3, p4, p5
            });
            PointSet actual;

            actual = target.Create();
            Assert.AreEqual(expected.Set.Count, actual.Set.Count);
            //sprawdzic StringReprezentation jednego punktu
        }
        /// <summary>
        /// changes point randomly
        /// adds or subtract given vauled
        /// </summary>
        /// <param name="point">point to be mutated</param>
        override public Point Mutate(Point point)
        {
            BytePoint newP = (BytePoint)point;

            double k;

            for (int i = 0; i < point.Size; i++)
            {
                k = _r.NextDouble();
                if (k > 0.5)
                {
                    newP.PointValues[i] -= (byte)_added;
                }
                else
                {
                    newP.PointValues[i] += (byte)_added;
                }
            }

            return(newP);
        }
        public void OperateTest()
        {
            ByteCrossover_RandomOR target = new ByteCrossover_RandomOR();
            Point point1 = new BytePoint(new byte[] { 0, 4, 5 });
            Point point2 = new BytePoint(new byte[] { 0, 2, 3 });
            Point point3 = new BytePoint(new byte[] { 6, 2, 7 });


            PointSet expected = new PointSet(new HashSet <Point>()
            {
                point1, point2, point3
            });

            PointSet pointSet = new PointSet(new HashSet <Point>()
            {
                point1, point2
            });
            PointSet actual;

            actual = target.Operate(pointSet);
            Assert.AreEqual(expected.Set.Count, actual.Set.Count);
        }
示例#16
0
        public void CreateTest()
        {
            int howMany = 5;
            int size    = 4;
            ByteInitialization_Random target = new ByteInitialization_Random(howMany, size);
            BytePoint p1 = new BytePoint(new byte[] { 1, 2, 3, 4 });
            BytePoint p2 = new BytePoint(new byte[] { 17, 2, 3, 46 });
            BytePoint p3 = new BytePoint(new byte[] { 4, 2, 36, 4 });
            BytePoint p4 = new BytePoint(new byte[] { 7, 26, 3, 4 });
            BytePoint p5 = new BytePoint(new byte[] { 35, 2, 33, 4 });

            PointSet expected = new PointSet(new HashSet <Point>()
            {
                p1, p2, p3, p4, p5
            });
            PointSet actual;

            actual = target.Create();
            Assert.AreEqual(expected.Set.Count, actual.Set.Count);
            //tu sprawdzic rozmiary
            //Assert.AreEqual(expected.Set.g, actual.Set.Count);
        }
示例#17
0
        /// <summary>
        /// Shifts point randomly
        /// left or right
        /// </summary>
        /// <param name="point">point to be mutated</param>
        override public Point Mutate(Point point)
        {
            BytePoint newP = (BytePoint)point;

            Random r = new Random();
            double k;

            for (int i = 0; i < point.Size; i++)
            {
                k = r.NextDouble();
                if (k > 0.5)
                {
                    newP.PointValues[i] >>= _shift;
                }
                else
                {
                    newP.PointValues[i] <<= _shift;
                }
            }

            return(newP);
        }
示例#18
0
    public MapChunkIO()
    {
        //step 1: get the single instance of the MaterialManager.
        //materialManager = MaterialManager.INSTANCE;

        //step 2: read the mapInfo.bytes.
        string rootPath = Application.streamingAssetsPath + "/Map/MapFragments";

        //Debug.Log("rootPath: " + rootPath);
        if (!ValidateDirExists(rootPath))
        {
            Debug.LogError("Map is broken.");
            return;
        }
        string mapInfoPath = rootPath + "/mapInfo.bytes";

        if (!ValidateFileExists(mapInfoPath))
        {
            Debug.LogError("Map is broken.");
            return;
        }
        using (BinaryReader br = new BinaryReader(new FileStream(mapInfoPath, FileMode.Open)))
        {
            Chunk_X_Max = br.ReadInt32();
            Chunk_Z_Max = br.ReadInt32();
            ChunkSize   = br.ReadInt32();
            //Debug.Log("Chunk_X_Max: " + Chunk_X_Max);
            //Debug.Log("Chunk_Z_Max: " + Chunk_Z_Max);
            //Debug.Log("ChunkSize: " + ChunkSize);
        }

        //step 3: read all chunks.
        ChunkCount = 0;
        chunks     = new ChunkData[Chunk_X_Max, Chunk_Z_Max];
        for (int chunkX = 0; chunkX < Chunk_X_Max; chunkX++)
        {
            string dirPath = rootPath + '/' + chunkX;
            if (!ValidateDirExists(dirPath))
            {
                continue;
            }

            DirectoryInfo dirInfo   = new DirectoryInfo(dirPath);
            FileInfo[]    fileInfos = dirInfo.GetFiles();
            foreach (FileInfo fileInfo in fileInfos)
            {
                if (!fileInfo.FullName.EndsWith(".bytes"))
                {
                    continue;
                }

                string strChunkZ = fileInfo.Name.Split('.')[0];
                int    chunkZ;
                if (int.TryParse(strChunkZ, out chunkZ))
                {
                    using (BinaryReader br = new BinaryReader(new FileStream(fileInfo.FullName, FileMode.Open)))
                    {
                        int         cubeCount     = br.ReadInt32();
                        int         materialCount = br.ReadInt32();
                        BytePoint[] positions     = new BytePoint[cubeCount];
                        byte[]      materialIds   = new byte[cubeCount];
                        bool[][]    isVisible     = new bool[cubeCount][];
                        int         index         = 0;
                        for (int i = 0; i < materialCount; i++)
                        {
                            byte materialId = br.ReadByte();
                            int  count      = br.ReadInt32();
                            while (count-- > 0)
                            {
                                ushort encodedXYZ = br.ReadUInt16();
                                byte   encodedVisible = br.ReadByte();
                                byte   x, y, z;
                                DecodeXYZ(encodedXYZ, out x, out y, out z);
                                positions[index]   = new BytePoint(x, y, z);
                                materialIds[index] = materialId;
                                isVisible[index]   = DecodeVisible(encodedVisible);
                                index++;
                            }
                        }
                        int visibleCount;
                        visibleCount = br.ReadInt32();

                        chunks[chunkX, chunkZ] = new ChunkData(positions, materialIds, isVisible, visibleCount);
                        ChunkCount++;
                    }
                }
            }
        }
    }