//-------------------------------------------------------------------------
        // each candidate gets evaluated here
        //-------------------------------------------------------------------------
        private float EvaluateCandidate(CandidateSolution <bool, ProblemState> candidate)
        {
            // test every possible situation and store the candidate's suggested action in the strategy object
            Strategy strategy = StrategyFactory.GetStrategyForGP(candidate);

            // then test that strategy and return the total money lost/made
            var strategyTester = new StrategyTester(strategy, settings.TestSettings);

            return(strategyTester.GetStrategyScore(settings.TestSettings.NumHandsToPlay));
        }
Example #2
0
        public override void BuildProgram(ProgramSettings settings, Action <string, CandidateSolution <bool, ProblemState> > callback)
        {
            this.settings = settings;
            this.perGenerationCallback = callback;

            //for (int upcardRank = 14; upcardRank > 1; upcardRank--)
            foreach (var upcardRank in Card.ListOfRanks)
            {
                // skip K, Q, J
                if (upcardRank == Card.Ranks.King || upcardRank == Card.Ranks.Queen || upcardRank == Card.Ranks.Jack)
                {
                    continue;
                }

                Card dealerCard = new Card(upcardRank, Card.Suits.Diamonds);

                solutions[dealerCard.Rank] = FindStrategyForUpcard(dealerCard);
                SaveSolutionToDisk(dealerCard.Rank + "_upcard_solution.txt", solutions[dealerCard.Rank].ToString());
            }

            // convert the dictionary of GP solutions to a single strategy
            FinalStrategy = StrategyFactory.GetStrategyForGP(solutions);
            FinalStatus   = "Generations needed to find: " + NumGenerationsNeeded;
        }
        public override Strategy GetStrategy()
        {
            var strategy = StrategyFactory.GetStrategyForGP(Solution);

            return(strategy);
        }