Example #1
0
        public DocumentContext(DbContextOptions <DocumentContext> options) : base(options)
        {
            Database.EnsureCreated();
//			if (PartsOfSpeech.ToList().Count != partsOfSpeech.Length)
//			{
//				foreach (var pos in partsOfSpeech)
//				{
//					PartsOfSpeech.Add(new PartOfSpeech()
//					{
//						Name = pos
//					});
//				}
//			}

            if (MembersOfSentence.ToList().Count != membersOfSentence.Length)
            {
                foreach (var mos in membersOfSentence)
                {
                    MembersOfSentence.Add(new MemberOfSentence()
                    {
                        Name = mos
                    });
                }
            }

            SaveChanges();

            if (Documents.ToList().Count == 0)
            {
                Documents.Add(MainAnalyzer.ParseText(
                                  "Мой дядя самых честных правил.", this));
            }
            SaveChanges();
        }
        private string CalculateStrongestOpponent(HandHistories.Objects.Hand.HandHistory CurrentGame, Street CurrentStreet)
        {
            try
            {
                IEnumerable <EquityRangeSelectorItemViewModel> oponnentHands = new List <EquityRangeSelectorItemViewModel>();

                var opponentName = string.Empty;

                MainAnalyzer.GetStrongestOpponent(CurrentGame, CurrentStreet, out opponentName, out oponnentHands);

                if (AutoGenerateHandRanges)
                {
                    if (!string.IsNullOrEmpty(opponentName) &&
                        oponnentHands.Any() &&
                        PlayersList.Any(x => x.PlayerName == opponentName && x.Cards.All(c => !c.Validate())))
                    {
                        oponnentHands.ForEach(r => r.UsedCards = _board.Cards);

                        var player = PlayersList.FirstOrDefault(x => x.PlayerName == opponentName);
                        player?.SetRanges(oponnentHands);
                    }
                }

                return(opponentName);
            }
            catch (Exception ex)
            {
                LogProvider.Log.Error(this, "Could not determine the strongest opponent", ex);
            }

            return(string.Empty);
        }
        internal IEnumerable <EquityRangeSelectorItemViewModel> GetHeroAutoRange(string heroName)
        {
            if (_currentHandHistory == null)
            {
                return(null);
            }

            try
            {
                var handHistory = _currentHandHistory.DeepClone();

                handHistory.Hero = handHistory.Players.FirstOrDefault(x => x.PlayerName == heroName);

                var heroAutoHands = MainAnalyzer.GetHeroRange(handHistory, _currentStreet);

                if (heroAutoHands != null && heroAutoHands.Any())
                {
                    heroAutoHands = heroAutoHands.Where(x => EquityCalculatorMode == EquityCalculatorMode.Holdem ||
                                                        (EquityCalculatorMode == EquityCalculatorMode.HoldemSixPlus && x.FisrtCard > RangeCardRank.Five && x.SecondCard > RangeCardRank.Five));

                    heroAutoHands.ForEach(r => r.UsedCards = _board.Cards);

                    var opponentsCount = CountOpponents();

                    BluffToValueRatioCalculator.AdjustPlayerRange(heroAutoHands, _currentStreet, handHistory, GetBoardText(), opponentsCount);
                    return(heroAutoHands);
                }
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Could not build auto range for hero", e);
            }

            return(null);
        }
        public JsonResult Add(DocumentViewModel documentViewModel)
        {
            Document document = MainAnalyzer.ParseText(documentViewModel.Text, db);

            db.Documents.Add(document);


            db.SaveChanges();
            document.Words = document.Words.OrderBy(x => x.Index).ToList();
            return(Json(document));
        }
        internal Dictionary <MadeHandType, int> GetCombosByHandType(IEnumerable <string> range)
        {
            try
            {
                var boardCards = GetBoardText();

                var combosByHandType = MainAnalyzer.GetCombosByHandType(range, boardCards);

                return(combosByHandType);
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, "Could not get combos by hand type.", e);
            }

            return(new Dictionary <MadeHandType, int>());
        }
Example #6
0
        protected Diagnostic[] GetDiagnostics(string code, bool ignoreErrors = false)
        {
            code = @"
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Threading.Tasks;
public class NotNullAttribute : System.Attribute { }
public class CheckNullAttribute : System.Attribute { }
public class IsNullCheckAttribute : System.Attribute { }
public static class Constraint
{
    public static void NotNull(Expression<Func<object>> func)
    {
    }

    public static void NotNull<T>(T obj, string name)
    {
    }
}
" + code;
            var document = CreateDocument(code);
            var analyzer = new MainAnalyzer();

            var compilation         = document.Project.GetCompilationAsync().Result;
            var compilerDiagnostics = compilation.GetDiagnostics();

            if (!ignoreErrors && compilerDiagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
            {
                Assert.Fail($"Compilation error(s): {compilerDiagnostics.FirstOrDefault(d => d.Severity == DiagnosticSeverity.Error)}");
            }

            if (diagnosticIds == null || diagnosticIds.Length == 0)
            {
                return(GetDiagnosticsForAnalyzer(document, analyzer));
            }
            return(GetDiagnosticsForAnalyzer(document, analyzer).Where(i => !i.Id.StartsWith("NC") || diagnosticIds.Contains(i.Id)).ToArray());
        }