Esempio n. 1
0
    static void Main(string[] args)
    {
        IList <ICitizen> allSubgects = new List <ICitizen>();
        int num = int.Parse(Console.ReadLine());

        for (int i = 0; i < num; i++)
        {
            string[] tolkens = Console.ReadLine().Split();

            switch (tolkens.Length)
            {
            case 3:
                allSubgects.Add(new Rebel(tolkens[0], int.Parse(tolkens[1]), tolkens[2]));
                break;

            case 4:
                allSubgects.Add(new Citizen(tolkens[0], int.Parse(tolkens[1]), tolkens[2], tolkens[3]));
                break;
            }
        }

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            if (allSubgects.Any(s => s.Name == input))
            {
                ICitizen sub = allSubgects.First(s => s.Name == input);
                sub.BuyFood();
            }
        }

        Console.WriteLine(allSubgects.Sum(s => s.Food));
    }
Esempio n. 2
0
 public Craftsman(ICitizen h, int level)
     : base(h, level)
 {
     WorkCost = 0.005f; //Config.CraftsmanWorkCost;
     h.Bag.MaxCapacity = 600; //Config.CraftsmanBagCapacity;
     h.Speed = 0.1f; //Config.CraftsmanSpeed;
 }
        public void Register(ICitizen citizen)
        {
            if (citizen == null)
            {
                throw new ArgumentNullException("citizen");
            }

            if (!String.IsNullOrWhiteSpace(citizen.VatId))
            {
                long tryParseId;
                if (long.TryParse(citizen.VatId, out tryParseId) && citizen.VatId.Length == 10)
                {
                    if (Array.Find<ICitizen>(allCitizens, human => human.VatId == citizen.VatId) != null)
                    {
                        throw new InvalidOperationException();
                    }

                    AddCitizenToArray(citizen);
                    return;
                }
            }

            citizen.VatId = GetID(citizen);
            AddCitizenToArray(citizen);
        }
Esempio n. 4
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var father = new SearchFather().Find(citizen);
            var mother = new SearchMother().Find(citizen);

            if (father.IsValid == false && mother.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = "There are no parents"
                });
            }

            if (father.IsValid)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = true,
                    Data = father.Data
                });
            }

            return(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = true,
                Data = mother.Data
            });
        }
Esempio n. 5
0
 public Guardian(ICitizen h, int level)
     : base(h, level)
 {
     base.WorkCost = 0.004f; //Config.GuardianWorkCost;
     h.Bag.MaxCapacity = 300; //Config.GuardianBagCapacity;
     h.Speed = 0.125f; //Config.GuardianSpeed;
 }
Esempio n. 6
0
        public bool Buy(ICitizen trader, TownInterfaces.ThingType type)
        {
            float  percent = (float)trader.ProfLevels["trader"] / Config.MaxLevel;
            IThing thing   = trader.Bag.GetWithPriceLower(Money, percent, type);

            if (thing != null)
            {
                float priceWithPercent = thing.Price * (1 + percent);
                Money        -= priceWithPercent;
                trader.Money += priceWithPercent;

                try
                {
                    Bag.Add(thing);
                }
                catch (OverloadedBagExeption ex)
                {
                    Log.Add("citizens:Human " + Name + " haven't enougth place for new thing after buying");
                }

                string typeName = thing.GetType().Name;
                Log.Add("other:Human " + Name + " bought " + typeName + " with price: " + priceWithPercent +
                        " at " + trader.Name);

                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var partnersSiblings = new SearchSiblings().Find(citizen.Partner);

            if (partnersSiblings.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = string.IsNullOrEmpty(NotFoundMessage) ? "There are no in laws" : NotFoundMessage
                });
            }

            return(GetFilteredResults(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = true,
                Data = partnersSiblings.Data
            }));
        }
Esempio n. 8
0
 public Thief(ICitizen h, int level)
     : base(h, level)
 {
     base.WorkCost = 0.002f; //Config.ThiefWorkCost;
     h.Bag.MaxCapacity = 750; //Config.ThiefBagCapacity;
     h.Speed = 0.125f; //Config.ThiefSpeed;
 }
        public void Register(ICitizen citizen)
        {
            if (citizen.VatId == null || CitizenRegistryHelper.FindCitizenById(citizens, citizenCount, citizen.VatId) == null)
            {
                if (String.IsNullOrWhiteSpace(citizen.VatId))
                {
                    int    birthNumber;
                    string id;

                    do
                    {
                        birthNumber = CitizenRegistryHelper.GetBirthNumber(citizen.Gender);
                        id          = CitizenRegistryHelper.GenerateVatId(citizen.BirthDate, birthNumber, citizen.Gender);
                    } while (CitizenRegistryHelper.FindCitizenById(citizens, citizenCount, id) != null);
                    citizen.VatId = id;
                }
                if (citizenCount == citizens.Length)
                {
                    Array.Resize(ref citizens, citizens.Length * 2);
                }
                citizens[citizenCount] = citizen.Clone() as Citizen;
                citizenCount++;
                lastRegistrationTime = SystemDateTime.Now();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Esempio n. 10
0
        /// <inheritdoc />
        public void Register(ICitizen citizen)
        {
            if (string.IsNullOrWhiteSpace(citizen.VatId))
            {
                int    dayNumber  = (citizen.BirthDate - startDate).Days;
                string dateString = dayNumber.ToString("D5");

                var oneDayBorned = register.Where(v => v.Key.StartsWith(dateString) && v.Key.Length == 10)
                                   .Select(v => v.Key.Substring(5, 4));

                var genderSequenceNumbers = oneDayBorned.Where(v => GenderCondition(v, citizen.Gender))
                                            .Select(v => int.Parse(v)).ToList();

                int currentNumber = genderSequenceNumbers.Any() ? genderSequenceNumbers.Max() : -1;

                int    nextSequenceNumber   = GetNextAllowed(currentNumber, citizen.Gender);
                string stringSequenceNumber = nextSequenceNumber.ToString("D4");

                int controlNumber = GetControlNumber(dateString, stringSequenceNumber);

                citizen.VatId = dateString + stringSequenceNumber + controlNumber;
            }

            if (!register.ContainsKey(citizen.VatId))
            {
                citizen.RegistrationDate = SystemDateTime.Now();
                register.Add(citizen.VatId, citizen.Clone() as ICitizen);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        public void Register(ICitizen citizen)
        {
            if (this.citizens.Contains(citizen, new Helpers.CitizenEqualsComparer()))
            {
                throw new InvalidOperationException("You already add this citizen in registry.");
            }

            var newCitizen = new Citizen(citizen.FirstName, citizen.LastName, citizen.BirthDate, citizen.Gender);

            if (string.IsNullOrEmpty(citizen.VatId))
            {
                citizen.VatId = newCitizen.VatId = this.CreateId(newCitizen);
            }
            else
            {
                newCitizen.VatId = citizen.VatId;
            }

            for (int i = 0; i < this.citizens.Length; ++i)
            {
                if (this.citizens[i] == null)
                {
                    this.citizens[i] = newCitizen;
                    this.genderCounts[(int)newCitizen.Gender]++;
                    this.lastRegistrationDateTime = SystemDateTime.Now();
                    break;
                }
            }

            if (this.citizens[this.citizens.Length - 1] != null)
            {
                this.DoubleCitizens();
            }
        }
Esempio n. 12
0
        public void Register(ICitizen citizen)
        {
            if (!String.IsNullOrEmpty(citizen.VatId))
            {
                throw new InvalidOperationException();
            }

            int days = (int)(citizen.BirthDate - _startDate).TotalDays;

            switch (citizen.Gender)
            {
            case Gender.Male:
                _registeredMan++;
                break;

            case Gender.Female:
                _registeredWoman++;
                break;
            }

            string numberStr = days.ToString("D5");

            numberStr += citizen.Gender == Gender.Male
                ? (_registeredMan / 5).ToString("D3") + (_registeredMan % 5).ToString()
                : (_registeredWoman / 5).ToString("D3") + (_registeredWoman % 5 + 1).ToString();
            numberStr    += Checksum(numberStr).ToString();
            citizen.VatId = numberStr;

            _registartions[_registeredMan + _registeredWoman - 1] =
                new Citizen(citizen.FirstName, citizen.LastName, citizen.BirthDate, citizen.Gender, citizen.VatId);

            _lastRegistration = SystemDateTime.Now.Invoke();
        }
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var children = citizen.Children;

            var grandChildren = children.SelectMany(x => x.Children ?? new List <ICitizen>()).ToList();

            if (grandChildren.Any() == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = string.IsNullOrEmpty(NotFoundMessage) ? "There are no grand children" : NotFoundMessage
                });
            }

            return(GetFilteredResults(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = true,
                Data = new ReadOnlyCollection <ICitizen>(grandChildren)
            }));
        }
Esempio n. 14
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var children = citizen.Children;

            if (children == null || children.Any() == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = string.IsNullOrEmpty(NotFoundMessage) ? "There are no children" : NotFoundMessage
                });
            }

            return(GetFilteredResults(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = true,
                Data = children
            }));
        }
Esempio n. 15
0
        public void Run()
        {
            string input = reader.ReadLine();

            while (input != "End")
            {
                string[] splitted = input.Split();

                ICitizen citizen = null;
                IRobot   robot   = null;
                if (splitted.Length == 3)
                {
                    citizen = citizenFactory.GetCitizen(splitted);
                    list.Add(citizen.Id);
                }
                else
                {
                    robot = robotFactory.GetRobot(splitted);
                    list.Add(robot.Id);
                }

                input = reader.ReadLine();
            }

            string fakeId = reader.ReadLine();

            foreach (var item in list)
            {
                if (item.EndsWith(fakeId))
                {
                    writer.WriteLine(item);
                }
            }
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            var janitor = new Janitor();

            // janitor.Name - since we explicitly implemented our IEmployee and ICitizen interface, we can't access the 'Name'
            // property unless we use any of these two abstractions that provide the concrete implementation of that property.

            ICitizen citizen = janitor;

            Console.WriteLine(citizen.Name); // Prints out 'Janitor the Citizen'.

            IEmployee employee = janitor;

            Console.WriteLine(employee.Name); // Prints out 'Janitor the Employee'.

            var teacher = new Teacher();

            // For the Teacher class, we implemented shared 'Name' property for both IEmployee and ICitizen interface.
            // Meaning we'll get the same result no matter if we call the 'Name' property from the class itself or any
            // of those abstractions (IEmployee, ICitizen).

            ICitizen  citizenTeacher  = teacher;
            IEmployee employeeTeacher = teacher;

            Console.WriteLine(teacher.Name);
            Console.WriteLine(citizenTeacher.Name);
            Console.WriteLine(employeeTeacher.Name);
            // All three lines will print out 'Just a teacher' on the console.
        }
        private string GetID(ICitizen citizen)
        {
            if (citizen == null)
            {
                throw new ArgumentNullException("citizen");
            }

            var result = new StringBuilder();
            result.Append(String.Format("{0:00000}", citizen.BirthDate.Subtract(dateToCompare).TotalDays));

            int? ordinalNumber = null;
            for (int i = registeredCitizensCount - 1; i >= 0; i--)
            {
                if (allCitizens[i].VatId.StartsWith(result.ToString()))
                {
                    ordinalNumber = Convert.ToInt32(allCitizens[i].VatId.Substring(6, 4));
                    break;
                }
            }

            result.Append(String.Format("{0:0000}", ordinalNumber != null ? ordinalNumber + 2 :
                         (citizen.Gender == Gender.Male ? 1 : 0)));
            result.Append(FindKey(result.ToString()));

            return result.ToString();
        }
Esempio n. 18
0
 public Farmer(ICitizen h, int level)
     : base(h, level)
 {
     base.WorkCost = 0.005f; //Config.FarmerWorkCost;
     h.Bag.MaxCapacity = 450; //Config.FarmerBagCapacity;
     h.Speed = 0.1f; //Config.FarmerSpeed;
 }
Esempio n. 19
0
        private void MainForm_MouseClick(object sender, MouseEventArgs e)
        {
            ICitizen h = town.IsMouseOnHuman(e.Location - new Size((int)Config.dx, (int)Config.dy));

            if ((h == clickedHuman) && (h != null))
            {
                clickedHuman.IsClicked = false;
                clickedHuman           = null;
                return;
            }

            if ((h == null) && (clickedHuman != null))
            {
                clickedHuman.IsClicked = false;
                clickedHuman           = null;
            }

            if (h != null)
            {
                if (clickedHuman != null)
                {
                    clickedHuman.IsClicked = false;
                }
                h.IsClicked  = true;
                clickedHuman = h;
                town.Citizens.Add(h);
                town.Citizens.Remove(h);
            }
        }
Esempio n. 20
0
        public Status AddPartner(ICitizen citizen, ICitizen partner)
        {
            Status status;

            try
            {
                citizen.AddPartner(partner);
                partner.AddPartner(citizen);
                status = new Status
                {
                    IsValid = true
                };

                _citizens.Add(partner);
            }
            catch (Exception exception)
            {
                status = new Status
                {
                    IsValid = false,
                    Message = exception.Message
                };
            }

            return(status);
        }
Esempio n. 21
0
        // ReSharper disable once UnusedMember.Local
        protected virtual void OnCollisionEnter(Collision collision)
        {
            ICitizen citizenAgent = collision.GetContact(0).otherCollider.GetComponent <ICitizen>();

            if (citizenAgent == null)
            {
                return;
            }

            GameManager.CollisionsTotal++;
            if (IsSymptomatic)
            {
                GameManager.CollisionsSymptomatic++;
            }

            GameManager.Collisions[HealthStatus]++;

            if (!IsContagious)
            {
                return;
            }

            citizenAgent.Infect(GameManager.ChanceOfInfection);
            AddReward(-0.1f);
        }
Esempio n. 22
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var siblings = citizen.Father.Children.Where(x => x != citizen).ToList();

            if (siblings.Any() == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = "There are no siblings"
                });
            }

            return(GetFilteredResults(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = true,
                Data = new ReadOnlyCollection <ICitizen>(siblings)
            }));
        }
Esempio n. 23
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var cousins = new List <ICitizen>();

            var fathersSiblings = _searchSiblings.Find(citizen.Father);

            if (fathersSiblings.IsValid)
            {
                fathersSiblings.Data.ToList().ForEach(x =>
                {
                    var children = _searchChildren.Find(x);
                    if (children.IsValid)
                    {
                        cousins.AddRange(children.Data);
                    }
                });
            }

            var mothersSiblings = new SearchSiblings().Find(citizen.Mother);

            if (mothersSiblings.IsValid)
            {
                var searchChildren = new SearchChildren();
                mothersSiblings.Data.ToList().ForEach(x =>
                {
                    var children = searchChildren.Find(x);
                    if (children.IsValid)
                    {
                        cousins.AddRange(children.Data);
                    }
                });
            }

            if (cousins.Any())
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = true,
                    Data = new ReadOnlyCollection <ICitizen>(cousins)
                });
            }

            return(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = false,
                Message = "There are no cousins"
            });
        }
Esempio n. 24
0
 public Status AddCitizen(ICitizen citizen)
 {
     _citizens.Add(citizen);
     return(new Status
     {
         IsValid = true
     });
 }
Esempio n. 25
0
 public Citizen(ICitizen ob)
 {
     this.firstName   = ob.FirstName;
     this.lastName    = ob.LastName;
     this.dateOfBirth = ob.BirthDate;
     this.gender      = ob.Gender;
     this.vatId       = ob.VatId;
 }
Esempio n. 26
0
 public static bool BackgroundCheck(ICitizen citizen)
 {
     if (BlackList.Contains(citizen))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 27
0
        public void Q6ProfessorTest2_ICitizen()
        {
            var      prof    = CreateProfInstance(null as Professor, "47212121", "Sauleh", "http://img.co/sauleh.jpg", Degree.PhD, 20);
            ICitizen citizen = prof;

            Assert.AreEqual("47212121", citizen.NationalId);
            Assert.AreEqual("Sauleh", citizen.Name);
        }
Esempio n. 28
0
 public void AddHuman(ICitizen h)
 {
     PeopleIn.Add(h);
     if (h.Path.Count != 0)
     {
         h.CurrentRoom = Util.ConvertIntToIndex(h.Path.Last());
     }
 }
Esempio n. 29
0
        public bool Equals(ICitizen other)
        {
            if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(other?.Name))
            {
                return(false);
            }

            return(Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 30
0
        public void Q5DabirTest2_ICitizen()
        {
            var dabir = CreateDabirInstance(null as Dabir, "47212121", "Ali", "http://img.co/ali.jpg", Degree.Master, 10);

            ICitizen citizen = dabir;

            Assert.AreEqual("47212121", citizen.NationalId);
            Assert.AreEqual("Ali", citizen.Name);
        }
Esempio n. 31
0
        public void Q4KhaleTest2_ICitizen()
        {
            var khale = CreateKhalleInstance(null as Khalle, "47212121", "Zahra", "http://img.co/zahra.jpg", Degree.PhD);

            ICitizen citizen = khale;

            Assert.AreEqual("47212121", citizen.NationalId);
            Assert.AreEqual("Zahra", citizen.Name);
        }
Esempio n. 32
0
        protected override Status <bool> IsValid(ICitizen citizen)
        {
            var status = base.IsValid(citizen).IsValid&& citizen.Father != null;

            return(new Status <bool>
            {
                IsValid = status,
                Message = status ? string.Empty : "There is no father"
            });
        }
        protected virtual Status <bool> IsValid(ICitizen citizen)
        {
            var status = citizen != null;

            return(new Status <bool>
            {
                IsValid = status,
                Message = status ? string.Empty : "Does not exist"
            });
        }
Esempio n. 34
0
        public IRoyal AddPartner(ICitizen partner)
        {
            if (_partner != null)
            {
                throw new DoNotCheatException();
            }

            _partner = partner;
            return(this);
        }
Esempio n. 35
0
 public virtual void RemoveResident(ICitizen h)
 {
     residents.Remove(h);
 }
Esempio n. 36
0
        public bool Sell(ICitizen buyer, TownInterfaces.ThingType type)
        {
            float percent = (float)ProfLevels["trader"] / Config.MaxLevel;
            IThing thing = Bag.GetWithPriceLower(buyer.Money, percent, (TownInterfaces.ThingType)type);

            if (thing != null)
            {
                float priceWithPercent = thing.Price * (1 + percent);
                buyer.Money -= priceWithPercent;
                Money += priceWithPercent;
                try
                {
                    buyer.Bag.Add(thing);
                }
                catch (OverloadedBagExeption ex)
                {
                    Log.Add("citizens:Human " + buyer.Name + " haven't enougth place for new thing after buying");
                }

                string typeName = thing.GetType().Name;
                Log.Add("other:Human " + Name + " sold " + typeName + " with price: " + priceWithPercent +
                    " to " + buyer.Name );

                return true;
            }
            return false;
        }
Esempio n. 37
0
        private void MainForm_MouseClick(object sender, MouseEventArgs e)
        {
            ICitizen h = town.IsMouseOnHuman(e.Location - new Size((int)Config.dx, (int)Config.dy));

            if ((h == clickedHuman) && (h != null))
            {
                clickedHuman.IsClicked = false;
                clickedHuman = null;
                return;
            }

            if ((h == null) && (clickedHuman != null))
            {
                clickedHuman.IsClicked = false;
                clickedHuman = null;
            }

            if (h != null)
            {
                if (clickedHuman != null)
                clickedHuman.IsClicked = false;
                h.IsClicked = true;
                clickedHuman = h;
                town.Citizens.Add(h);
                town.Citizens.Remove(h);
            }
        }
Esempio n. 38
0
 public virtual void AddResident(ICitizen h)
 {
     residents.Add(h);
     h.Home = this;
 }
Esempio n. 39
0
 public BehaviourModel(ICitizen human, int level)
 {
     body = human;
     Level = level;
     StateMachine = new StackFSM("rest");
 }
Esempio n. 40
0
 public void Attack(ICitizen target)
 {
     attackTarget = target;
     Attack();
 }
Esempio n. 41
0
 public virtual void AddWorker(ICitizen h)
 {
     workers.Add(h);
     h.WorkBuilding = this;
 }
Esempio n. 42
0
 public virtual void RemoveWorker(ICitizen h)
 {
     workers.Remove(h);
 }
Esempio n. 43
0
 public void AddHuman(ICitizen h)
 {
     PeopleIn.Add(h);
     if (h.Path.Count != 0)
     h.CurrentRoom = Util.ConvertIntToIndex(h.Path.Last());
 }
Esempio n. 44
0
 public void RemoveHuman(ICitizen h)
 {
     PeopleIn.Remove(h);
 }