private void UpdateMoveOperators()
        {
            IMoveGenerator oldMoveGenerator = MoveGenerator;
            IMoveMaker     oldMoveMaker     = MoveMaker;
            ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;

            ClearMoveParameters();

            if (problem != null)
            {
                foreach (IMultiMoveGenerator generator in problem.Operators.OfType <IMultiMoveGenerator>().OrderBy(x => x.Name))
                {
                    MoveGeneratorParameter.ValidValues.Add(generator);
                }
                foreach (IExhaustiveMoveGenerator generator in problem.Operators.OfType <IExhaustiveMoveGenerator>().OrderBy(x => x.Name))
                {
                    MoveGeneratorParameter.ValidValues.Add(generator);
                }

                if (oldMoveGenerator != null)
                {
                    IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
                    if (newMoveGenerator != null)
                    {
                        MoveGenerator = newMoveGenerator;
                    }
                }

                ChooseMoveOperators(oldMoveMaker, oldMoveEvaluator);
            }
        }
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();

            rpsGameStore.GetGame().Returns(new RPSGame(numberOfGames, numberOfDynamite));
            moveMaker.MakeMove(Arg.Any <int>()).Returns(Move.Rock);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();
            rpsGame.AddGame(Move.Rock);
            rpsGame.Games[0].UpdateOutcome(Outcome.Win, Move.Warterbomb);

            rpsGameStore.GetGame().Returns(rpsGame);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();

            rpsGame.AddGame(Move.Paper);
            rpsGameStore.GetGame().Returns(rpsGame);
            moveMaker.MakeMove(Arg.Any <int>()).Returns(Move.Rock);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
        private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null)
        {
            if (oldMoveMaker == null)
            {
                oldMoveMaker = MoveMaker;
            }
            if (oldMoveEvaluator == null)
            {
                oldMoveEvaluator = MoveEvaluator;
            }
            MoveMakerParameter.ValidValues.Clear();
            MoveEvaluatorParameter.ValidValues.Clear();

            if (MoveGenerator != null && Problem != null)
            {
                IMoveGenerator generator = MoveGeneratorParameter.Value;
                foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators.OfType <IOperator>()).OrderBy(x => x.Name))
                {
                    MoveMakerParameter.ValidValues.Add(moveMaker);
                }
                foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators.OfType <IOperator>()).OrderBy(x => x.Name))
                {
                    MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
                }

                if (oldMoveMaker != null)
                {
                    IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
                    if (mm != null)
                    {
                        MoveMaker = mm;
                    }
                }
                if (oldMoveEvaluator != null)
                {
                    ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
                    if (me != null)
                    {
                        MoveEvaluator = me;
                    }
                }
            }
        }
Esempio n. 6
0
        private void UpdateMoveParameters()
        {
            IMoveMaker oldMoveMaker = MoveMaker;
            ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;

            ClearMoveParameters();
            if (MoveGenerator != null)
            {
                List <Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
                foreach (Type type in moveTypes.ToList())
                {
                    if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
                    {
                        moveTypes.Remove(type);
                    }
                }

                var        operators        = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
                IMoveMaker defaultMoveMaker = operators.OfType <IMoveMaker>().FirstOrDefault();
                ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType <ISingleObjectiveMoveEvaluator>().FirstOrDefault();
                foreach (IMoveMaker moveMaker in operators.OfType <IMoveMaker>().OrderBy(op => op.Name))
                {
                    MoveMakerParameter.ValidValues.Add(moveMaker);
                }
                foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType <ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
                {
                    MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
                }

                if (oldMoveMaker != null)
                {
                    IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
                    if (mm != null)
                    {
                        MoveMaker = mm;
                    }
                    else
                    {
                        oldMoveMaker = null;
                    }
                }
                if (oldMoveMaker == null && defaultMoveMaker != null)
                {
                    MoveMaker = defaultMoveMaker;
                }

                if (oldMoveEvaluator != null)
                {
                    ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
                    if (me != null)
                    {
                        MoveEvaluator = me;
                    }
                    else
                    {
                        oldMoveEvaluator = null;
                    }
                }
                if (oldMoveEvaluator == null && defaultMoveEvaluator != null)
                {
                    MoveEvaluator = defaultMoveEvaluator;
                }
            }
        }
    private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null) {
      if (oldMoveMaker == null) oldMoveMaker = MoveMaker;
      if (oldMoveEvaluator == null) oldMoveEvaluator = MoveEvaluator;
      MoveMakerParameter.ValidValues.Clear();
      MoveEvaluatorParameter.ValidValues.Clear();

      if (MoveGenerator != null && Problem != null) {
        IMoveGenerator generator = MoveGeneratorParameter.Value;
        foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators.OfType<IOperator>()).OrderBy(x => x.Name))
          MoveMakerParameter.ValidValues.Add(moveMaker);
        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators.OfType<IOperator>()).OrderBy(x => x.Name))
          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);

        if (oldMoveMaker != null) {
          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
          if (mm != null) MoveMaker = mm;
        }
        if (oldMoveEvaluator != null) {
          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
          if (me != null) MoveEvaluator = me;
        }
      }
    }
Esempio n. 8
0
 public void Setup()
 {
     rpsGameStore = Substitute.For <IRPSGameStore>();
     moveMaker    = Substitute.For <IMoveMaker>();
     rpsPlayer    = new RPSPlayer(rpsGameStore, moveMaker);
 }
Esempio n. 9
0
 public RPSPlayer(IRPSGameStore rpsGameStore, IMoveMaker moveMaker)
 {
     this.rpsGameStore = rpsGameStore;
     this.moveMaker    = moveMaker;
 }