Esempio n. 1
0
        public FieldA(int _w, int _h, int _g, int _amnt)
        {
            grid_step = _g;
            kX = _w / _g;
            kY = _h / _g;
            amnt = _amnt;
            particles = new List<ParicleA>();
            wall = new int[kX, kY];
            countC1 = countL1 = countT1 = countC2 = countL2 = countT2 = 0;

            for (var i = 0; i < amnt; ++i)
            {
                ParicleA part;
                bool f;
                do
                {
                    part = new ParicleA(kY);

                    f = particles.Any(p => p.X == part.X && p.Y == part.Y);
                } while (f);
                particles.Add(part);
            }

            for (int i = 0; i < kX/2; i++)
            {
                wall[i, kY/3] = 1;
                wall[i, (kY/3)*2] = 1;
            }

            for (int i = 0; i < (kX/3)*2; i++)
            {
                wall[i, 0] = 1;
                wall[i, kY - 1] = 1;
            }

            for (int i = kY / 3; i < (kY / 3) * 2+1; i++)
                wall[(kX/2), i] = 1;

            for (int i = 0; i < kY / 3; i++)
                wall[(kX/3)*2, i] = 1;

            for (int i = (kY / 3) * 2+1; i < kY; i++)
                wall[(kX / 3) * 2, i] = 1;

            for (int i = (kX / 3) * 2; i < kX; i++)
            {
                wall[i, kY/3] = 1;
                wall[i, (kY / 3)*2+1] = 1;
            }

            for (int i = kY / 3; i < (kY / 3) * 2 + 1; i++)
                wall[kX-1, i] = 1;
        }
Esempio n. 2
0
        private Vector NextPos(ParicleA p)
        {
            var v = new Vector(p.X, p.Y);
            var oldV = new Vector(p.X, p.Y);
            if (p.Go())
            {
                var rand = new Random((int)DateTime.Now.Ticks);
                var m = (float)rand.NextDouble();
                if (0.6 >= m)
                {
                    if (p.type==0)
                        v.Y += 1;
                    else if (p.type==1)
                        v.Y -= 1;
                }
                if (feelWall(v))
                    v.Y = oldV.Y;
                if(v.Y==oldV.Y)
                    v.X += 1;
                if (feelWall(v))
                    v.X = oldV.X;
            }

            if (p.type == 0 && v.Y == kY / 2)
                p.type = 2;

            if (p.type == 1 && v.Y == kY / 2)
                p.type = 2;

            if (v.X == kX / 3 && !p.isCnt1)
            {
                if (v.Y < kY / 2)
                    countC1++;
                else
                    countL1++;
                p.isCnt1 = true;
            }

            if ((v.X == (kX / 3) * 2 + 2) && !p.isCnt2)
            {
                countC2++;
                p.isCnt2 = true;
            }

            return v;
        }