示例#1
0
 private static double recursion(IExplorable node, int depth, double alpha, double beta, bool maximizing, int playCount)
 {
     if (depth == 0 || node.IsTerminal())
     {
         return(node.HeuresticValue(playCount));
     }
     if (maximizing)
     {
         double v = -inf;
         foreach (var child in node.Explore())
         {
             v     = Math.Max(v, AlphaBeta.recursion(child, depth - 1, alpha, beta, false, playCount + 1));
             alpha = Math.Max(alpha, v);
             if (beta <= alpha)
             {
                 break;
             }
         }
         return(v);
     }
     else
     {
         double v = inf;
         foreach (var child in node.Explore())
         {
             v    = Math.Min(v, AlphaBeta.recursion(child, depth - 1, alpha, beta, true, playCount + 1));
             beta = Math.Min(beta, v);
             if (beta <= alpha)
             {
                 break;
             }
         }
         return(v);
     }
 }
示例#2
0
        public Exploration(IExplorable attempt, ExplorationJson exp)
        {
            if (exp.id == null)
            {
                throw new ArgumentNullException("exp");
            }

            this.attempt = attempt;
            this.exp     = exp;

            switch (exp.kind)
            {
            case "InternalError":
                // Should not happen
                this.errors = new string[] { exp.exception };
                break;

            case "CompilationError":
                this.errors = exp.errors.Select(e => e.ToString()).ToList();
                break;

            case "BadPuzzle":
                this.errors = new string[] { exp.description };
                break;

            case "BadDependency":
                this.errors = exp.referencedTypes;
                break;

            default:
                this.errors = null;
                break;
            }
        }
示例#3
0
 public static ExplorationBody FromIExplorable(IExplorable attempt)
 {
     return(new ExplorationBody
     {
         program = Program.FromIExplorable(attempt),
         challengeId = attempt.ChallengeId,
     });
 }
示例#4
0
 public static Program FromIExplorable(IExplorable attempt)
 {
     return(new Program
     {
         text = attempt.Text,
         language = attempt.Language.ToCodeHuntAPIString(),
     });
 }
示例#5
0
        public Translation translate(IExplorable attempt, bool wait = false)
        {
            var postRequest = new RestRequest("translate", Method.POST);

            postRequest.AddParameter("language", "CSharp", ParameterType.QueryString);
            postRequest.RequestFormat = DataFormat.Json;
            postRequest.AddBody(Program.FromIExplorable(attempt));
            return(new Translation(attempt, JsonConvert.DeserializeObject <TranslationJson>(client.Execute(postRequest).Content)));
        }
示例#6
0
 public EmployeeAdditionWindow(Organisation infoBase, MainWindow main, IExplorable selected)
 {
     InitializeComponent();
     Organisation  = infoBase;
     Main          = main;
     this.selected = selected;
     positionComboBox.ItemsSource = new List <string>()
     {
         "Начальник", "Интерн", "Сотрудник"
     };
 }
示例#7
0
        public static IExplorable BestMove(IExplorable node, int depth, bool maximizing)
        {
            IExplorable best_child = null;
            double      alpha = -inf, beta = inf;

            if (maximizing)
            {
                double v = -inf;
                foreach (var child in node.Explore())
                {
                    var v2 = AlphaBeta.recursion(child, depth - 1, alpha, beta, false, 1);
                    if (v2 > v)
                    {
                        v          = v2;
                        best_child = child;
                    }
                    alpha = Math.Max(alpha, v);
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
                return(best_child);
            }
            else
            {
                double v = inf;
                foreach (var child in node.Explore())
                {
                    var v2 = AlphaBeta.recursion(child, depth - 1, alpha, beta, true, 1);
                    if (v2 < v)
                    {
                        v          = v2;
                        best_child = child;
                    }
                    beta = Math.Min(beta, v);
                    if (beta <= alpha)
                    {
                        break;
                    }
                }
                return(best_child);
            }
        }
示例#8
0
        public Exploration explore(IExplorable attempt, bool wait = false)
        {
            var postRequest = new RestRequest("explorations", Method.POST);

            postRequest.RequestFormat = DataFormat.Json;
            postRequest.AddBody(ExplorationBody.FromIExplorable(attempt));
            string id = JsonConvert.DeserializeObject <ExplorationResponse>(client.Execute(postRequest).Content).id;

            var             request = new RestRequest("explorations/" + id, Method.GET);
            var             result  = client.Execute(request);
            ExplorationJson exp     = JsonConvert.DeserializeObject <ExplorationJson>(result.Content);

            while (wait && !exp.isComplete)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
                result = client.Execute(request);
                exp    = JsonConvert.DeserializeObject <ExplorationJson>(result.Content);
            }

            return(new Exploration(attempt, exp));
        }
示例#9
0
 public Translation(IExplorable attempt, TranslationJson translation)
 {
     this.attempt     = attempt;
     this.translation = translation;
 }