Ejemplo n.º 1
0
        public void TestBasicStrategy()
        {
            BasicStrategy strategy = new BasicStrategy();

            Assert.IsTrue(strategy.ToString() == "Basic Strategy");

            int        dimension  = 3;
            List <int> cellValues = new List <int>();

            for (int i = 0; i < dimension * dimension * dimension * dimension; ++i)
            {
                cellValues.Add(0);
            }

            SudokuPuzzle puzzle = new SudokuPuzzle(dimension, cellValues);

            Assert.IsFalse(strategy.AdvancePuzzle(puzzle));
            puzzle.Rows[0][0].RemoveAllExcept(1);
            int count = 0;

            while (strategy.AdvancePuzzle(puzzle))
            {
                ++count;
            }

            Assert.IsTrue(count > 0);
            Assert.IsFalse(strategy.AdvancePuzzle(puzzle));
        }
Ejemplo n.º 2
0
        private void HandleSplitHand(Player player)
        {
            bool actionFinished = false;

            if (player.HasSplitHand)
            {
                while (!actionFinished)
                {
                    PlayerAction basicAction       = BasicStrategy.CalculateStrategy(dealer, player.SplitHand, player.HasSplitHand);
                    PlayerAction illustriousAction = IllustriousEighteen.CalculateStrategy(dealer, player.SplitHand, counter, player.HasSplitHand);

                    switch (illustriousAction)
                    {
                    case PlayerAction.Stand:
                        actionFinished = true;
                        break;

                    case PlayerAction.Hit:
                        Hit(player.SplitHand);
                        break;

                    case PlayerAction.Double:
                        Hit(player.SplitHand);
                        actionFinished = true;
                        break;

                    case PlayerAction.Split:
                        actionFinished = true;
                        break;

                    case PlayerAction.NoAction:
                        switch (basicAction)
                        {
                        case PlayerAction.Stand:
                            actionFinished = true;
                            break;

                        case PlayerAction.Hit:
                            Hit(player.SplitHand);
                            break;

                        case PlayerAction.Double:
                            Hit(player.SplitHand);
                            actionFinished = true;
                            break;

                        case PlayerAction.Split:
                            actionFinished = true;
                            break;
                        }
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void TestSplit8s()
        {
            BasicStrategy bs                = new BasicStrategy();
            Hand          playersHand       = new Hand(0);
            Card          playersFirstCard  = new Card(Suit.DIAMOND, CardType.EIGHT);
            Card          playersSecondCard = new Card(Suit.HEART, CardType.EIGHT);

            playersHand.AddCard(playersFirstCard);
            playersHand.AddCard(playersSecondCard);
            Card dealerUpCard = new Card(Suit.CLUB, CardType.KING);

            Assert.AreEqual(HandAction.SPLIT, bs.DetermineActionForHand(0, playersHand, dealerUpCard));
        }
Ejemplo n.º 4
0
        public void TestDoubleDownOn11()
        {
            BasicStrategy bs                = new BasicStrategy();
            Hand          playersHand       = new Hand(0);
            Card          playersFirstCard  = new Card(Suit.DIAMOND, CardType.NINE);
            Card          playersSecondCard = new Card(Suit.HEART, CardType.TWO);

            playersHand.AddCard(playersFirstCard);
            playersHand.AddCard(playersSecondCard);
            Card dealerUpCard = new Card(Suit.CLUB, CardType.KING);

            Assert.AreEqual(HandAction.DOUBLE_DOWN, bs.DetermineActionForHand(0, playersHand, dealerUpCard));
        }
Ejemplo n.º 5
0
        public void Get_answered()
        {
            Tile tile  = new Tile(8, 8);
            Tile tile2 = new Tile(7, 8, 2);
            Tile tile3 = new Tile(6, 8, 3);

            List <Tile> tileList = new List <Tile>();

            tileList.Add(tile);
            tileList.Add(tile2);
            tileList.Add(tile3);

            Assert.AreEqual(BasicStrategy.GetAnswered(tileList).Count, 2);
        }
Ejemplo n.º 6
0
        public void TestAcesAgainstHigh()
        {
            BasicStrategy bs                = new BasicStrategy();
            HandAction    ha                = HandAction.SPLIT;
            Hand          playersHand       = new Hand(0);
            Card          playersFirstCard  = new Card(Suit.DIAMOND, CardType.ACE);
            Card          playersSecondCard = new Card(Suit.HEART, CardType.ACE);

            playersHand.AddCard(playersFirstCard);
            playersHand.AddCard(playersSecondCard);
            Card dealerUpCard = new Card(Suit.CLUB, CardType.KING);

            Assert.AreEqual(ha, bs.DetermineActionForHand(0, playersHand, dealerUpCard));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Grab All Strategies from the Solver.Strategies Directory using reflection.
        /// Sidenote: 3 cheers for over-engineering.
        /// </summary>
        internal void LoadStrategies()
        {
            _strategies = new List <BasicStrategy>();
            System.Reflection.Assembly asm = Assembly.Load("Solver");
            Type[] types = asm.GetTypes().Select(t => t).Where(t => t.Namespace == "Solver.Strategies" &&
                                                               t.BaseType.Name == "BasicStrategy" || t.Name == "BasicStrategy").ToArray();

            foreach (Type t in types)
            {
                BasicStrategy strat = Activator.CreateInstance(t) as BasicStrategy;
                strat.Grid = this.Grid;
                if (strat.Difficulty != Difficulty.basic)
                {
                    strat.Enabled = false;
                }
                _strategies.Add(strat);
            }
        }
        public void DoubleDownExceptSixTwoTest()
        {
            PlayerState expectedState = PlayerState.DoubleDown;
            Player      player        = new BasicStrategy
            {
                Chips = 500,
                hand  = new Hand
                {
                    cards = new List <Card>()
                    {
                        new Card(Suit.Club, Face.Six),
                        new Card(Suit.Club, Face.Two)
                    }
                }
            };

            player.hand.SetHandValues();
            PlayerState state = (player.React(dealersUpCard: new Card(Suit.Club, Face.Five), ref player.CurrentState, player.hand, new List <int>()));

            Assert.AreNotEqual(expectedState, state);
        }
        public void SoftStandingNumberPlayer18()
        {
            PlayerState expectedState = PlayerState.Stand;
            Player      player        = new BasicStrategy
            {
                Chips = 500,
                hand  = new Hand
                {
                    cards = new List <Card>()
                    {
                        new Card(Suit.Club, Face.Ace),
                        new Card(Suit.Club, Face.Seven)
                    }
                }
            };

            player.hand.SetHandValues();
            PlayerState state = (player.React(dealersUpCard: new Card(Suit.Club, Face.Eight), ref player.CurrentState, player.hand, new List <int>()));

            Assert.AreEqual(expectedState, state);
        }
        public void HoldingHard16Against10Test()
        {
            PlayerState expectedState = PlayerState.Hit;
            Player      player        = new BasicStrategy
            {
                Chips = 500,
                hand  = new Hand
                {
                    cards = new List <Card>()
                    {
                        new Card(Suit.Club, Face.Ten),
                        new Card(Suit.Club, Face.Six)
                    }
                }
            };

            player.hand.SetHandValues();
            PlayerState state = (player.React(dealersUpCard: new Card(Suit.Club, Face.Ten), ref player.CurrentState, player.hand, new List <int>()));

            Assert.AreEqual(expectedState, state);
        }
Ejemplo n.º 11
0
        private static float playHandBasic(ref Deck deck, Hand playerHand, ref Hand dealerHand, ref BasicStrategy policy, ref double winLoss)
        {
            var reward = 0.0f;
            var mult = 1.0f;
            //check for blackjack.
            if (playerHand.getValue() == 21 && dealerHand.getValue() != 21)
            {
                winLoss += 1.5;
                return 1.5f;
            }
            else if (dealerHand.getValue() == 21) //dealer got blackjack
            {
                winLoss -= 1.0;
                return -1.0f;
            }
            else
            {
                //player decisions
                var actionTaken = policy.choosePlayerAction(playerHand, dealerHand);

                if (actionTaken == 1)//hit
                {
                    //player decisions
                    var action = policy.choosePlayerAction(playerHand, dealerHand);
                    while (action == 1)
                    {
                        playerHand.addCards(deck.getCard());
                        action = policy.choosePlayerAction(playerHand, dealerHand);
                    }
                    //see if we busted
                    if (playerHand.getValue() > 21)
                    {
                        winLoss -= 1.0;
                    }
                    else
                    {
                        actionTaken = 0;
                    }

                }
                else if (actionTaken == 2) //double
                {
                    playerHand.addCards(deck.getCard());
                    if (playerHand.getValue() > 21)
                    {
                        winLoss -= 2.0;
                        reward = -1.0f;
                        mult = 2.0f;
                    }
                    else
                    {
                        mult = 2.0f;
                        actionTaken = 0;
                    }
                }
                else if (actionTaken == 3) //split
                {
                    Hand pH1 = new Hand();
                    Hand pH2 = new Hand();

                    var val = playerHand.getValue() / 2;
                    //split card and get an extra.
                    pH1.addCards(val);
                    pH2.addCards(val);
                    pH1.addCards(deck.getCard());
                    pH2.addCards(deck.getCard());

                    //win loss for the hands
                    reward = playHandBasic(ref deck, pH1, ref dealerHand, ref policy, ref winLoss);
                    reward += playHandBasic(ref deck, pH2, ref dealerHand, ref policy, ref winLoss);

                    winLoss += reward;
                }
                if (actionTaken == 0) //stand
                {
                    //play dealer
                    var dealerVal = playDealer(ref deck, ref dealerHand);
                    if (dealerVal > 21) //dealer busts
                    {
                        winLoss += 1.0 * mult;
                        reward = 1.0f * mult;

                    }
                    else if (dealerVal < playerHand.getValue()) //we beat dealer
                    {
                        winLoss += 1.0f * mult;
                        reward = 1.0f * mult;
                    }
                    else if (dealerVal == playerHand.getValue()) //draw
                    {
                        reward = 0.0f;
                    }
                    else //we lost to dealer
                    {
                        winLoss -= 1.0 * mult;
                        reward = -1.0f * mult;
                    }
                }
            }

            return reward;
        }
Ejemplo n.º 12
0
        /*
        static private void showPolicy(Net.Net n)
        {
            Console.Write("    ");
            var pol = new NNBasicStrategy(n, 1.0);
            for (int d = 2; d <= 11; d++)
            {
                Console.Write(d + " ");
            }
            Console.WriteLine();
            //Try each possible input and get the output.
            for (int p = 21; p >= 4; p--)
            {
                if(p >= 10)
                    Console.Write(p + "  ");
                else
                    Console.Write(p + "   ");
                for (int d = 2; d <= 11; d++)
                {
                    Hand pH = new Hand();
                    Hand dH = new Hand();
                    pH.addCards(p);
                    dH.addCards(d);
                    //var a = pol.choosePlayerAction(pH, dH, deck);
                    Console.Write(a + " ");
                }
                Console.WriteLine();
            }

            //do for soft totals
            Console.WriteLine();
            Console.WriteLine("------ SOFTS ------");

            for (int p = 2; p <= 9; p++)
            {
                Console.Write(p + "   ");
                for (int d = 2; d <= 11; d++)
                {
                    Hand pH = new Hand();
                    Hand dH = new Hand();
                    pH.addCards(11);
                    pH.addCards(p);
                    dH.addCards(d);
                   // var a = pol.choosePlayerAction(pH, dH);
                    Console.Write(a + " ");
                }
                Console.WriteLine();
            }

        }
        */
        /*
        private static double simpleBasicStrategy(int numOfHands)
        {
            var ret = new List<double>();
            int totalHandsPlayed;
            double winLoss = 0.0; //-1 for loss, +1 for win. +1.5 for blackjack. 0 for draw
            var policy = new BasicStrategy();
            //do each hand
            Deck deck = new Deck(6);
            deck.shuffleCards();
            for (totalHandsPlayed = 0; totalHandsPlayed < numOfHands; totalHandsPlayed++)
            {
                if (deck.isDeckFinished())
                {
                    deck = new Deck(6);
                    deck.shuffleCards();
                }

                //decide bet
                var trueCount = deck.getTrueCount();
                var bet = 1.0;
                if (trueCount > 2)
                    bet = 10.0;

                Hand playerHand = new Hand();
                Hand dealerHand = new Hand();
                //deal initial cards
                playerHand.addCards(deck.getCard());
                dealerHand.addCards(deck.getCard());
                playerHand.addCards(deck.getCard());
                dealerHand.addCards(deck.getCard());
                playHandBasic(ref deck, playerHand, ref dealerHand, ref policy, ref winLoss, bet);
            }
            var x = winLoss / (numOfHands);
            return x;
        }
        */
        private static double ccBasicStrategy(Net.Net bettingNet, int numOfHands, double eps, ref Deck deck, bool isTraining = false)
        {
            int totalHandsPlayed;
            double winLoss = 0.0; //-1 for loss, +1 for win. +1.5 for blackjack. 0 for draw
            var policy = new BasicStrategy();
            var bettingPolicy = new NNBettingStrategy(bettingNet, eps);
            //do each hand
            for (totalHandsPlayed = 0; totalHandsPlayed < numOfHands; totalHandsPlayed++)
            {
                if (deck.isDeckFinished())
                {
                    deck = new Deck(6);
                    deck.shuffleCards();
                }

                //figure out bet
                var bet = 1.0f;
                var actionTaken = bettingPolicy.chooseBet(deck);

                if (actionTaken == 1)
                    bet = 5.0f;
                if (actionTaken == 2)
                    bet = 10.0f;

                Hand playerHand = new Hand();
                Hand dealerHand = new Hand();
                //deal initial cards
                playerHand.addCards(deck.getCard());
                dealerHand.addCards(deck.getCard());
                playerHand.addCards(deck.getCard());
                dealerHand.addCards(deck.getCard());

                var winBefore = winLoss;
                var winAfter = winLoss;
                var diff = winAfter - winBefore;

                var reward = playHandBasic(ref deck, playerHand, ref dealerHand, ref policy, ref winLoss);
                reward = reward * bet;
                if(isTraining )
                    bettingPolicy.runBackwards(reward, actionTaken);

                diff = (bet * diff) - diff;
                winLoss += diff;
            }
            var x = winLoss / (numOfHands);
            return x;
        }
Ejemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        DebugLog.Clean();
        DebugLog.Add(new UnityDebugLogger());

        PersistentDataStorage.Instance.ResetState();

        _manager = new SystemManager();

        Tutor joao  = new Tutor("Joao");
        Tutor maria = new Tutor("Maria");

        SetPersonality(joao, maria);
        _manager.Tutors.Add(joao);
        _manager.Tutors.Add(maria);


        {
            EmotivectorAppraisal appraisal = new EmotivectorAppraisal();
            IPredictor           predictor = new AdditiveSecondDerivativePredictor(new WeightedMovingAveragePredictor(),
                                                                                   new WeightedMovingAveragePredictor(), new WeightedMovingAveragePredictor());
            {
                AffectiveUpdater updater = new NamedArrayAffectiveUpdater("Grades", 0, 20)
                {
                    Emotivector = new Emotivector("Grades", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedArrayAffectiveUpdater("Hours", 0, 16)
                {
                    Emotivector = new Emotivector("StudyHours", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            _manager.AffectiveAppraisal = appraisal;
        }

        {
            // Setup Empathic Strategy
            _manager.EmpathicStrategySelector = new SS_SelectFirst();
            BasicStrategy strategy = new BasicStrategy();
            strategy.Intentions.Add(new Intention("demo"));
            _manager.Strategies.Add(strategy);
        }

        // Setup Dialog Selector
        if (YarnDialogDatabase != null)
        {
            string[] yarnFilesContent = new string[YarnDialogDatabase.Length];
            for (int i = 0; i < YarnDialogDatabase.Length; i++)
            {
                yarnFilesContent[i] = YarnDialogDatabase[i].text;
            }

            var dialogSelector = new BasicYarnDialogSelector(yarnFilesContent);

            _manager.DialogSelector = dialogSelector;
        }

        {
            // Setup Dialog Manager
            var dialogManager = new YarnDialogManager(false);
            _manager.DialogManager = dialogManager;
            dialogManager.Tutors.Add(joao);
            dialogManager.Tutors.Add(maria);
            dialogManager.ModuleManager = ModuleManager;


            // Handlers Order matters

            // Tag Handlers (should always be first)
            dialogManager.Handlers.Add(new EmotionTagNodeHandler());

            // Line Handlers
            dialogManager.Handlers.Add(new ParallelLineHandler());

            // Options Handlers
            dialogManager.Handlers.Add(new SequenceOptionsHandler());

            // Node Handlers
            dialogManager.Handlers.Add(new LogCompleteNodeHandler());

            // Command Handlers
            dialogManager.Handlers.Add(new WaitCommandHandler());
            dialogManager.Handlers.Add(new ModuleCommandHandler());
            dialogManager.Handlers.Add(new ExitCommandHandler());
            dialogManager.Handlers.Add(new LogCommandHandler());

            if (_commandHandler)
            {
                dialogManager.Handlers.Add(_commandHandler);
            }
        }

        Playing = true;
    }
Ejemplo n.º 14
0
        static void Main()
        {
start:
            Console.WriteLine(@".NET Garbage Collector (GC) Demo. Copyright © 2018 DCOM Engineering, LLC

Available Commands:
cls                         Clears the screen
clr                         Clears references to BitmapImages so they can be collected
leak_strategy               Performs allocation of BitmapImage and holds references to cause a memory leak
deterministic_strategy      Performs allocation of BitmapImage and explicitly disposes of them
indeterministic_strategy    Performs allocation of BitmapImage and lets the GC dispose of them
finalizer_strategy          Performs allocation of BitmapImage and frees the resources through finalization
inheritance_strategy        Performs allocation of BitmapImage / ImageBase anad explicitly disposes of them
gc                          Forces garbage collection and waits for pending finalizers
exit                        Exits the application
");

            while (true)
            {
                Console.Write(@"DCOM:\> ");

                string input = Console.ReadLine();

                Console.WriteLine();

                Strategy strategy = null;

                switch (input.ToLower())
                {
                case "cls":
                    Console.Clear();
                    goto start;

                case "clr":
                    MemoryLeakStrategy.ZeroRefCount();
                    break;

                case "exit":
                    Environment.Exit(0);
                    break;

                case "leak_strategy":
                    strategy = new MemoryLeakStrategy();
                    break;

                case "deterministic_strategy":
                    strategy = new BasicStrategy(BasicStrategyMode.Deterministic);
                    break;

                case "indeterministic_strategy":
                    strategy = new BasicStrategy(BasicStrategyMode.Indeterministic);
                    break;

                case "inheritance_strategy":
                    strategy = new InheritanceStrategy();
                    break;

                case "finalizer_strategy":
                    strategy = new FinalizerStrategy();
                    break;

                case "gc":
                    strategy = new GCCollectStrategy();
                    break;

                default:
                    Console.WriteLine("Not a known strategy.");
                    Console.WriteLine();
                    continue;
                }

                var data = strategy?.Run();

                if (data != null)
                {
                    Screen.Print(data);
                }
            }
        }
Ejemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        DebugLog.Clean();
        DebugLog.Add(new UnityDebugLogger());

        PersistentDataStorage.Instance.StoreDataOnline = StoreDataOnline;

        IDataStorage dataStorage = PersistentDataStorage.Instance;

        _manager = new SystemManager();

        Tutor joao = new Tutor("Joao")
        {
            Personality = new ExpectancyPersonality(TutorsPersonality[0].text)
        };
        Tutor maria = new Tutor("Maria")
        {
            Personality = new ExpectancyPersonality(TutorsPersonality[1].text)
        };

        _manager.Tutors.Add(joao);
        _manager.Tutors.Add(maria);

        {
            EmotivectorAppraisal appraisal = new EmotivectorAppraisal();
            IPredictor           predictor = new AdditiveSecondDerivativePredictor(new WeightedMovingAveragePredictor(),
                                                                                   new WeightedMovingAveragePredictor(), new WeightedMovingAveragePredictor());
            {
                AffectiveUpdater updater = new NamedArrayAffectiveUpdater("Grades", 0, 20)
                {
                    Emotivector = new Emotivector("objective-performance", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedArrayAffectiveUpdater("Hours", 0, 16)
                {
                    Emotivector = new Emotivector("objective-effort", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedArrayAffectiveUpdater("Visits", 0, 50)
                {
                    Emotivector = new Emotivector("objective-engagement", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedDatedArrayAffectiveUpdater("Challenge", 0, 4)
                {
                    Emotivector = new Emotivector("subjective-challenging", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedDatedArrayAffectiveUpdater("Enjoyment", 0, 4)
                {
                    Emotivector = new Emotivector("subjective-enjoyment", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            {
                AffectiveUpdater updater = new NamedDatedArrayAffectiveUpdater("Importance", 0, 4)
                {
                    Emotivector = new Emotivector("subjective-importance", predictor)
                };
                appraisal.AddUpdater(updater);
            }
            _manager.AffectiveAppraisal = appraisal;
        }

//        {
//
//            // Setup Empathic Strategy
//            _manager.EmpathicStrategySelector = new BaseStrategySelector();
//
//            var strategies = TaskFactory.FromJson(Tasks.text);
//            foreach (var taskStrategy in strategies)
//            {
//                taskStrategy.DataStorage = dataStorage;
//                _manager.Strategies.Add(taskStrategy);
//            }
//        }

        {
            // Setup Empathic Strategy
            _manager.EmpathicStrategySelector = new ExpectancyStrategySelector();

            // Welcoming and Goodbye
            {
                var strategy = new BasicStrategy();
                strategy.Name = "welcome";
                strategy.Intentions.Add(new Intention("welcome"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "exit";
                strategy.Intentions.Add(new Intention("exit"));
                _manager.Strategies.Add(strategy);
            }

            // Theme Introduction
            {
                var strategy = new BasicStrategy();
                strategy.Name = "subjective-challenging-intro";
                strategy.Intentions.Add(new Intention("subjective-challenging-intro"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "subjective-enjoyment-intro";
                strategy.Intentions.Add(new Intention("subjective-enjoyment-intro"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "subjective-importance-intro";
                strategy.Intentions.Add(new Intention("subjective-importance-intro"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "objective-performance-intro";
                strategy.Intentions.Add(new Intention("objective-performance-intro"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "objective-effort-intro";
                strategy.Intentions.Add(new Intention("objective-effort-intro"));
                _manager.Strategies.Add(strategy);
            }
            {
                var strategy = new BasicStrategy();
                strategy.Name = "objective-engagement-intro";
                strategy.Intentions.Add(new Intention("objective-engagement-intro"));
                _manager.Strategies.Add(strategy);
            }

            // Version 01
            if (_strategyVersion == 1)
            {
                // Subjective - Challenging
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("rest"));
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("rest"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }

                // Subjective - Enjoyment
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-lesser";
                    strategy.Intentions.Add(new Intention("change-view"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-greater";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }

                // Subjective - Importance
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-lesser";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("change-view"));
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-lesser";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-greater";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Performance
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-greater";
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Effort
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Engagement
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-greater";
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
            }

            // Version 02
            if (_strategyVersion == 2)
            {
                // Subjective - Challenging
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-as-expected";
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-greater";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-reward-lesser";
                    strategy.Intentions.Add(new Intention("rest"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-challenging-punishment-greater";
                    strategy.Intentions.Add(new Intention("rest"));
                    _manager.Strategies.Add(strategy);
                }

                // Subjective - Enjoyment
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-greater";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-reward-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("change-view"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-lesser";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-enjoyment-punishment-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }

                // Subjective - Importance
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-as-expected";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-greater";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-reward-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-lesser";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "subjective-importance-punishment-greater";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Performance
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-as-expected";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-reward-lesser";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-lesser";
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-performance-punishment-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Effort
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-as-expected";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-reward-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    strategy.Intentions.Add(new Intention("change-view"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-effort-punishment-greater";
                    strategy.Intentions.Add(new Intention("help"));
                    _manager.Strategies.Add(strategy);
                }

                // Objective - Engagement
                // Reward
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-as-expected";
                    strategy.Intentions.Add(new Intention("believe-you"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-greater";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-reward-lesser";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                // Punishment
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-as-expected";
                    strategy.Intentions.Add(new Intention("change-view"));
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-lesser";
                    strategy.Intentions.Add(new Intention("summary"));
                    _manager.Strategies.Add(strategy);
                }
                {
                    var strategy = new BasicStrategy();
                    strategy.Name = "objective-engagement-punishment-greater";
                    strategy.Intentions.Add(new Intention("capabilities"));
                    _manager.Strategies.Add(strategy);
                }
            }
        }

        // Setup Dialog Selector
        if (YarnDialogDatabase != null)
        {
            string[] yarnFilesContent = new string[YarnDialogDatabase.Length];
            for (int i = 0; i < YarnDialogDatabase.Length; i++)
            {
                yarnFilesContent[i] = YarnDialogDatabase[i].text;
            }

            var dialogSelector =
                new TagYarnDialogSelector(new PersistentVariableStorage(dataStorage), yarnFilesContent);

            _manager.DialogSelector = dialogSelector;
        }

        {
            // Setup Dialog Manager
            var dialogManager = new YarnDialogManager(false);
            _manager.DialogManager = dialogManager;
            dialogManager.Tutors.Add(joao);
            dialogManager.Tutors.Add(maria);
            dialogManager.ModuleManager = ModuleManager;


            // Handlers Order matters

            // Tag Handlers (should always be first)
            dialogManager.Handlers.Add(new EmotionTagNodeHandler());

            // Line Handlers
            dialogManager.Handlers.Add(new SequenceLineHandler());

            // Options Handlers
            dialogManager.Handlers.Add(new SequenceOptionsHandler());

            // Node Handlers
            dialogManager.Handlers.Add(new LogCompleteNodeHandler());

            // Command Handlers
            dialogManager.Handlers.Add(new WaitCommandHandler());
            dialogManager.Handlers.Add(new ModuleCommandHandler());
            dialogManager.Handlers.Add(new ExitCommandHandler());
            dialogManager.Handlers.Add(new LogCommandHandler());

            if (_commandHandler)
            {
                dialogManager.Handlers.Add(_commandHandler);
            }
        }

//        var state = dataStorage.GetState();
//        state["Current"].AsObject["Activity"] = "Test";
//        var activity = state["Activities"].AsObject["Test"].AsObject;
//        activity["Name"] = "Test Activity";
//        var checkpoints = activity["Checkpoints"].AsArray;
//        {
//            var checkpoint = new JSONObject();
//            checkpoint["Type"] = "Checkbox";
//            checkpoint["Name"] = "Test Checkpoint";
//            checkpoint["Date"] = "23/07/2018";
//            checkpoint["Effort"] = .5f;
//            checkpoint["Importance"] = .7f;
//            checkpoint["CheckboxDone"] = true;
//            checkpoints[0] = checkpoint;
//        }
//        {
//            var checkpoint = new JSONObject();
//            checkpoint["Type"] = "Evaluation";
//            checkpoint["Name"] = "Test Evaluation";
//            checkpoint["Date"] = "23/07/2018";
//            checkpoint["Effort"] = .7f;
//            checkpoint["Importance"] = .5f;
//            checkpoint["EvaluationScore"] = null;
//            checkpoints[1] = checkpoint;
//        }
//        {
//            var checkpoint = new JSONObject();
//            checkpoint["Type"] = "Evaluation";
//            checkpoint["Name"] = "Test Evaluation 2";
//            checkpoint["Date"] = "23/07/2018";
//            checkpoint["Effort"] = .7f;
//            checkpoint["Importance"] = .5f;
//            checkpoint["EvaluationScore"] = 16;
//            checkpoints[2] = checkpoint;
//        }

        ActivityMenuController activityMenuController = new ActivityMenuController();

        activityMenuController.MenuPrefab = _activityMenuPrefab;

        MoodleLoginController loginController = new MoodleLoginController(_webManager);

        loginController.MenuPrefab = _loginMenuPrefab;

        if (_commandHandler)
        {
            _commandHandler.controllers.Add(activityMenuController);
            _commandHandler.controllers.Add(loginController);
        }

        Playing = true;
    }
Ejemplo n.º 16
0
 public BasicStrategyContext(BasicStrategy strategy)
 {
     this._basicStrategy = strategy;
 }
Ejemplo n.º 17
0
    private void InitTutors(string file, string node)
    {
        _manager = new SystemManager();

        Tutor joao  = new Tutor("Joao");
        Tutor maria = new Tutor("Maria");

        _manager.Tutors.Add(joao);
        _manager.Tutors.Add(maria);

        {
            // Setup Affective Appraisal
            ModularAffectiveAppraisal appraisal = new ModularAffectiveAppraisal(
                new UserAA_OneEmotion(new Emotion(EmotionEnum.Happiness,
                                                  0.2f)),
                new TutorAA_CopyUser()
                );
            _manager.AffectiveAppraisal = appraisal;
        }

        {
            // Setup Empathic Strategy
            _manager.EmpathicStrategySelector = new SS_SelectFirst();
            BasicStrategy strategy = new BasicStrategy();
            strategy.Intentions.Add(new Intention(node));
            _manager.Strategies.Add(strategy);
        }

        {
            // Setup Dialog Selector
            if (YarnDialogDatabase != null)
            {
//                string[] yarnFilesContent = new string[YarnDialogDatabase.Length];
                IList <string> yarnFilesContent = new List <string>();
                for (int i = 0; i < YarnDialogDatabase.Length; i++)
                {
                    yarnFilesContent.Add(YarnDialogDatabase[i].text);
                }

                yarnFilesContent = yarnFilesContent.Concat(ReadFiles(new[] { file })).ToList();

                var dialogSelector = new YarnPreviewDialogSelector(yarnFilesContent.ToArray());

                _manager.DialogSelector = dialogSelector;
            }
        }

        {
            // Setup Dialog Manager
            var dialogManager = new YarnDialogManager(false);
            _manager.DialogManager = dialogManager;
            dialogManager.Tutors.Add(joao);
            dialogManager.Tutors.Add(maria);
            dialogManager.ModuleManager = this.ModuleManager;


            // Handlers Order matters

            // Tag Handlers (should always be first)
            dialogManager.Handlers.Add(new EmotionTagNodeHandler());

            // Line Handlers
            dialogManager.Handlers.Add(new SequenceLineHandler());

            // Options Handlers
            dialogManager.Handlers.Add(new SequenceOptionsHandler());

            // Node Handlers
            dialogManager.Handlers.Add(new LogCompleteNodeHandler());

            // Command Handlers
            dialogManager.Handlers.Add(new WaitCommandHandler());
            dialogManager.Handlers.Add(new ModuleCommandHandler());
            dialogManager.Handlers.Add(new ExitCommandHandler());
            dialogManager.Handlers.Add(new LogCommandHandler());
        }
    }