Example #1
0
        public void SubDecisionMakerを使って意思決定ができ遺伝もできる()
        {
            // Init parent
            var parentDecisionMaker = new ReinforcementDecisionMaker();
            var actions             = new List <IAction>();

            actions.AddRange(LocomotionAction.EightDirections());
            for (int i = 0; i < 100; i++)
            {
                actions.Add(
                    new SubDecisionMakerAction(new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition)));
            }
            parentDecisionMaker.Init(actions);
            parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true);

            // Init child
            var childDecisionMaker = new ReinforcementDecisionMaker();

            childDecisionMaker.Init(parentDecisionMaker);

            // Assertion
            foreach (var state in _dummyStates)
            {
                var parentAction = parentDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true);
                var childAction  = childDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true);
                Assert.AreEqual(
                    parentAction.Name,
                    childAction.Name
                    );

                // SubDecisionMakerActionは外に出ない
                Assert.IsInstanceOf <LocomotionAction>(parentAction);
                Assert.IsInstanceOf <LocomotionAction>(childAction);
            }
        }
Example #2
0
        public void デシリアライズ後RestoreされたものはSubDMも含めて同じDecisionをする()
        {
            // Init parent
            var parentDecisionMaker = new ReinforcementDecisionMaker();
            var actions             = new List <IAction>();

            actions.Add(new SubDecisionMakerAction(new FollowPointDecisionMaker(State.BasicKeys.RelativeFoodPosition)));
            actions.AddRange(LocomotionAction.EightDirections());
            parentDecisionMaker.Init(actions);
            parentDecisionMaker.DecideAction(_dummyStates[0], forceRandom: false, forceMax: true);

            var saveDataClone      = EditorTestExtensions.DeepCloneByMsgPack(parentDecisionMaker.Save());
            var decisionMakerClone = saveDataClone.Instantiate() as ReinforcementDecisionMaker;

            decisionMakerClone.Restore(actions);

            // Random
            foreach (var state in _dummyStates)
            {
                Assert.AreEqual(
                    parentDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true)
                    .Name,
                    decisionMakerClone.DecideAction(state, forceRandom: false, forceMax: true).Name
                    );
            }
            // Force SubDM
            foreach (var state in _dummyStates)
            {
                Assert.AreEqual(
                    parentDecisionMaker.DecideAction(state, forceRandom: false, forceMax: true, forceAction: 0)
                    .Name,     // choose from 100 choice
                    decisionMakerClone.DecideAction(state, forceRandom: false, forceMax: true, forceAction: 0).Name
                    );
            }
        }