Ejemplo n.º 1
0
 public Situation(int msn, int cnb, RiverBank rb, bool isDLck, int dpth)
 {
     Msnr         = msn;
     Cnbl         = cnb;
     RvrBnk       = rb;
     msnrOpposite = MSNRALL - msn;   // Количество миссионеров на противоположном берегу.
     cnblOpposite = CNBLALL - cnb;   // Количество каннибалов на противоположном берегу.
     IsDeadLock   = isDLck;          // Признак тупика - по умолчанию = false, повторная ситуация  - тупиковая  = true.
     Depth        = dpth;            // Глубина залегания вершины.
     CheckSituation();
 }
        static void Main(string[] args)
        {
            var lion = new Character("Leão");
            var goat = new Character("Cabra");
            var hay  = new Character("Feno");


            goat.IsDevouredBy = lion;
            hay.IsDevouredBy  = goat;

            var rightRiverBank = new RiverBank("Direita");
            var leftRiverBank  = new RiverBank("Esquerda");
            var personagens    = new List <Character>
            {
                goat,
                hay,
                lion
            };

            leftRiverBank.Items = personagens;

            River = new River(rightRiverBank, leftRiverBank);

            // Enquanto os 3 não tiverem cruzado o rio para o lado direito
            while (River.LeftRiverBank.Items.Count != 0)
            {
                Character pickedCharacter;

                do
                {
                    pickedCharacter = River.CurrentRiverBank.Items[new Random().Next(0, River.CurrentRiverBank.Items.Count - 1)];

                    var remaining = River.CurrentRiverBank.Items.FindAll(p => p != pickedCharacter);

                    if (remaining.Count == 2)
                    {
                        if (remaining[0].IsDevouredBy == remaining[1] || remaining[1].IsDevouredBy == remaining[0])
                        {
                            pickedCharacter = null;
                        }
                    }

                    else if (remaining.Count == 0 && River.CurrentRiverBank == rightRiverBank)
                    {
                        pickedCharacter = null;
                        break;
                    }

                    else if (remaining.Count == 1 && pickedCharacter.IsDevouredBy != remaining[0] && remaining[0].IsDevouredBy != pickedCharacter && River.CurrentRiverBank != leftRiverBank)
                    {
                        pickedCharacter = null;
                        break;
                    }
                } while (pickedCharacter == null);


                PlayMove(pickedCharacter);
            }

            Console.ReadKey();
        }
Ejemplo n.º 3
0
 public Situation(int msn, int cnb, RiverBank rb) : this(msn, cnb, rb, false, 1)
 {
 }
Ejemplo n.º 4
0
 public Situation(int msn, int cnb, RiverBank rb, int depth) : this(msn, cnb, rb, false, depth)
 {
 }
Ejemplo n.º 5
0
 public bool equals(RiverBank otherRiverBank)
 {
     return((this.getCannibals() == otherRiverBank.getCannibals()) && (this.getMissionaries() == otherRiverBank.getMissionaries()));
 }