public static string GetFuncTemplate(IChallengeSet set) { var paramPairs = set.Params .Select(t => $"{GetAlias(t.Type)} {t.SuggestedName}"); return($"{GetAlias(set.ReturnType)} Main({string.Join(", ", paramPairs)}) {{ return ... ; }}"); }
async Task <OneOf <int, IReadOnlyList <ChallengeResult>, IReadOnlyList <CompileErrorMessage> > > IGameService.Attempt( User user, Guid holeId, string code, IChallengeSet challengeSet, CancellationToken cancellationToken) { var res = await this.codeGolfService.Score(code, challengeSet, cancellationToken); await res.Match( async score => { await this.userRepository.AddOrUpdate(user, cancellationToken); var newId = Guid.NewGuid(); await this.attemptRepository.AddAttempt( new Attempt(newId, user.UserId, holeId, code, score, DateTime.UtcNow), cancellationToken); await this.signalRNotifier.NewAnswer(); if (await this.IsBestScore(holeId, newId, cancellationToken)) { await this.signalRNotifier.NewTopScore(user.LoginName, score, user.AvatarUri.ToString()); } }, _ => Task.CompletedTask, _ => Task.CompletedTask); return(res); }
Task <OneOf <int, IReadOnlyList <ChallengeResult>, IReadOnlyList <CompileErrorMessage> > > ICodeGolfService.Score( string code, IChallengeSet challenge, CancellationToken cancellationToken) { var compileResult = this.runner.Compile( code, challenge.Params.Select(a => a.Type).ToArray(), challenge.ReturnType, cancellationToken); return(compileResult.Match( async compiled => { var results = await challenge.GetResults(compiled); if (results.Any(a => a.Error != null)) { return results.ToList(); } else { return this.scorer.Score(code); } }, err => Task.FromResult((OneOf <int, IReadOnlyList <ChallengeResult>, IReadOnlyList <CompileErrorMessage> >)err.ToArray()))); }
public ChallengeSetDto Map(IChallengeSet cs) { return(new ChallengeSetDto( cs.Id, cs.Title, cs.Description, GenericPresentationHelpers.GetAlias(cs.ReturnType), cs.Params.Select( a => new ParamsDescriptionDto(GenericPresentationHelpers.GetAlias(a.Type), a.SuggestedName)) .ToArray(), cs.Challenges.Select( a => new ChallengeDto( a.Args.Select(b => b.ToString()).ToArray(), GenericPresentationHelpers.WrapIfArray(a.ExpectedResult, cs.ReturnType))).ToArray())); }
public HoleDto(Hole hole, DateTime start, DateTime end, DateTime?closedAt, bool hasNext, IChallengeSet challengeSet) { this.Hole = EnsureArg.IsNotNull(hole, nameof(hole)); this.Start = start; this.End = end; this.ClosedAt = closedAt; this.HasNext = hasNext; this.ChallengeSet = EnsureArg.IsNotNull(challengeSet, nameof(challengeSet)); }