public GradingStatus(Judger baseJudger, string problem, string user) { InitializeComponent(); judger = baseJudger; judger.OnGradeStatusChanged += Judger_OnGradeStatusChanged; if (problem == "" && user == "") { judger.GradeAll(); } else if (problem != "" && user == "") { judger.GradeProblem(problem); } else if (user != "" && problem == "") { judger.GradeUser(user); } else { judger.GradeSubmission(problem, user); } Start = DateTime.Now; DispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 0), DispatcherPriority.Background, TimerTick, Dispatcher.CurrentDispatcher); DispatcherTimer.Interval = new TimeSpan(0, 0, 1); DispatcherTimer.IsEnabled = true; }
/// <summary> /// Dispatch MANY job from database. This method should be favored over /// <c>TryDispatchJobFromDatabase(Judger)</c> /// </summary> /// <param name="judger">The judger to dispatch from.</param> /// <param name="count">The maximum count of jobs to dispatch.</param> /// <param name="replyTo">The request message this replies to, if any</param> /// <returns></returns> protected async ValueTask <int> TryDispatchJobFromDatabase( Judger judger, int count, FlowSnake?replyTo = null) { using var scope = scopeProvider.CreateScope(); var db = GetDb(scope); using var tx = await db.Database.BeginTransactionAsync(System.Data.IsolationLevel.Serializable); var jobs = await GetUndispatchedJobsFromDatabase(db, count); try { var res = await DispatchJobs(judger, jobs, replyTo); await db.SaveChangesAsync(); await tx.CommitAsync(); return(jobs.Count); } catch { await tx.RollbackAsync(); return(0); } }
/// <summary> /// Dispatch ONE job from database. /// </summary> /// <param name="judger">The judger to dispatch from</param> /// <returns></returns> protected async ValueTask <bool> TryDispatchJobFromDatabase(Judger judger) { using var scope = scopeProvider.CreateScope(); var db = GetDb(scope); using var tx = await db.Database.BeginTransactionAsync(System.Data.IsolationLevel.Serializable); var job = await GetLastUndispatchedJobFromDatabase(db); if (job == null) { return(false); } try { var res = await DispatchJob(judger, job); await db.SaveChangesAsync(); await tx.CommitAsync(); return(res); } catch { await tx.RollbackAsync(); return(false); } }
/// <summary> /// Dispatch a list of jobs to the given judger. /// <p> /// Note: this method changes the state of the job, so it needs to be /// saved to database after this method returns. /// </p> /// </summary> protected async ValueTask <bool> DispatchJobs( Judger judger, List <Job> jobs, FlowSnake?replyTo = null) { var redis = await this.redis.GetDatabase(); try { await judger.Socket.SendMessage(new MultipleNewJobServerMsg() { Jobs = jobs, ReplyTo = replyTo }); foreach (var job in jobs) { await redis.StringSetAsync(FormatJobStdout(job.Id), "", expiry : TimeSpan.FromHours(2), flags : CommandFlags.FireAndForget); await redis.StringSetAsync(FormatJobError(job.Id), "", expiry : TimeSpan.FromHours(2), flags : CommandFlags.FireAndForget); job.Judger = judger.Id; job.Stage = JobStage.Dispatched; job.DispatchTime = DateTimeOffset.Now; } return(true); } catch { return(false); } }
private void button1_Click(object sender, EventArgs e) { Task executing = new Task(() => { string root = "E:\\Judge\\"; FileFactory factory = new FileFactory("E:\\Judge\\"); string code = textBox1.Text; string language = comboBox1.Text; Submit submit = new Submit(code, language); Problem sum = new Problem(); sum.Tests = new List <TestCase> { new TestCase("5 5", "10"), new TestCase("3 9", "12"), new TestCase("3 6", "9"), new TestCase("5 5", "10"), new TestCase("3 9", "12"), new TestCase("3 6", "9") }; IChecker checker = new StringChecker(); Judger judger = new Judger(factory, checker); judger.Judge(submit, new ExecutingOptions(5, 1000)); string current = ""; this.textBox2.Text = ""; foreach (var result in judger.Assessment(judger.BuildedFileName + ".exe", sum)) { current = String.Format("\nStatus:{0} Memory:{1} Execution Time:{2}", result.Verdict, result.Memory.ToString(), result.Time.ToString()); // this.textBox2.Text = textBox2.Text + current; } }); executing.Start(); }
public static Judger getInstance() //使用单例模式 { if (_instance == null) { _instance = new Judger(); } return(_instance); }
public void ClickBoat() { if (boat.isEmpty()) { return; } actionManager.moveBoat(boat.getGameObject(), boat.BoatMoveToPosition(), boat.move_speed); userGUI.status = Judger.getInstance().check(fromCoast, toCoast, boat); }
public void TestJudgerFunction() { //read sample data var data = new SampleData(); for (int i = 1; i <= 10; i++) { data.Datas.Add(new DataPair() { InputData = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\testdata\equation\equation" + i.ToString() + ".in"), OutputData = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\testdata\equation\equation" + i.ToString() + ".out"), }); } data.LimitRAM = 137438953472; data.LimitTime = 1000; //load judge unit var ju = new JudgeUnit(); ju.Code = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\ST33\equation.cpp"); ju.Language = "C++"; var compiler = new Compiler(); compiler.Languages = new List <string>(); compiler.Languages.Add("C"); compiler.Filename = @"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe"; compiler.Argument = "-o \"{Output}\" \"{Filename}\""; compiler.Name = "GNU C++ Compiler"; var judger = new Judger(); judger.Data = data; judger.Unit = ju; var isFinished = false; judger.OnCompiled = (s, e) => { Console.WriteLine("Compilation {0}", e.IsCompilationSucceeded); }; judger.OnJudged = (s, e) => { Console.WriteLine("Judged one,index:{0}", e.Index); }; judger.OnJudgedAll = () => { Console.WriteLine("Index\tRAM\tTime\tExit Code\tResult"); judger.Results.ForEach((r) => { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", r.Index, r.MaximumRAM, r.TotalTime, r.ExitCode, r.Result.ToString()); }); isFinished = true; }; judger.StartJudging(compiler, true); while (!isFinished) { ; } Console.WriteLine(); }
void Awake() { Director director = Director.getInstance(); director.currentSceneController = this; userGUI = gameObject.AddComponent <UserGUI>() as UserGUI; characters = new MyCharacterController[6]; judger = new Judger(); loadResources(); }
void Awake() { Director director = Director.getInstance(); director.currentSceneController = this; u = gameObject.AddComponent <UI>() as UI; actionManager = gameObject.AddComponent <ScenceActionManager>() as ScenceActionManager; judger = gameObject.AddComponent <Judger>() as Judger; characters = new dpGame.CharacterController[6]; loadResources(); }
public void loadResources() { //GameObject water = Instantiate (Resources.Load ("Perfabs/Water", typeof(GameObject)), water_pos, Quaternion.identity, null) as GameObject; //water.name = "water"; fromCoast = new CoastController("from"); toCoast = new CoastController("to"); boat = new BoatController(); judger = new Judger(fromCoast, toCoast, boat); loadCharacter(); }
public bool gaming = true; //用于判断游戏是否正在进行,由于目前还不存在起始界面,所以一开始游戏就开始了 void Awake() { speed = 4; SSDirector director = SSDirector.GetInstance(); director.CurrentSceneController = this; userGui = gameObject.AddComponent <UserGUI>() as UserGUI; director.CurrentSceneController.LoadResource(); judger = gameObject.AddComponent <Judger>() as Judger; actionManager = gameObject.AddComponent <CCActionManager>() as CCActionManager; }
void Awake() { Director director = Director.getInstance(); director.currentSceneController = this; judger = gameObject.AddComponent <Judger>(); patrolFactory = gameObject.AddComponent <PatrolFactory>(); playerArea = 5; patrolActionManager = gameObject.AddComponent <PatrolActionManager>(); gameObject.AddComponent <GameEventManager>(); ui = gameObject.AddComponent <UI>() as UI; }
void Awake() { Director director = Director.getInstance(); director.currentSceneController = this; userGUI = gameObject.AddComponent <UserGUI>() as UserGUI; characters = new ChaCon[6]; loadResources(); actionManager = gameObject.AddComponent <MySceneActionManager>() as MySceneActionManager; //judger = gameObject.AddComponent<Judger>() as Judger; judger = Judger.getInstance(); }
private void Awake() { Director director = Director.getInstance(); director.currentSceneController = this; this.gameObject.AddComponent <DiskFactory>(); this.gameObject.AddComponent <Judger>(); diskFactory = Singleton <DiskFactory> .Instance; ui = gameObject.AddComponent <UserUI>() as UserUI; judger = Singleton <Judger> .Instance; }
void Start() { action = Director.getInstance().currentSceneController as UserAction; style = new GUIStyle(); style.fontSize = 40; style.alignment = TextAnchor.MiddleCenter; buttonStyle = new GUIStyle("button"); buttonStyle.fontSize = 30; judge = new Judger(); }
public bool gaming = true; // 用于判断游戏是否正在进行,由于目前还不存在起始界面,所以一开始游戏就开始了 void Awake() { speed = 4; SSDirector director = SSDirector.GetInstance(); director.CurrentSceneController = this; userGui = gameObject.AddComponent <UserGUI>() as UserGUI; director.CurrentSceneController.LoadResource(); judger = gameObject.AddComponent <Judger>() as Judger; actionManager = gameObject.AddComponent <CCActionManager>() as CCActionManager; graph = new stateGraph(); currState = new stateNode(3, 3, true); }
void Awake() { gameGUI = gameObject.AddComponent <GameGUI>() as GameGUI; actionManager = gameObject.AddComponent <ActionManager>() as ActionManager; preists = new Character[3]; devils = new Character[3]; SSDirector.getInstance().currentScenceController = this; LoadResources(); judger = gameObject.AddComponent <Judger>() as Judger; judger.preists = preists; judger.devils = devils; judger.boat = boat; judger.sceneController = this; }
void Awake() { State s = new State(3, 3, false); tips.DFS(ref s); tips.print(); Director director = Director.getInstance(); director.currentSceneController = this; u = gameObject.AddComponent <UI>() as UI; actionManager = gameObject.AddComponent <ScenceActionManager>() as ScenceActionManager; judger = gameObject.AddComponent <Judger>() as Judger; characters = new dpGame.CharacterController[6]; loadResources(); }
public MainWindow() { OpenContestCommand.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control)); GradeCommand.InputGestures.Add(new KeyGesture(Key.F9)); GotoUserCommand.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control)); InitializeComponent(); setting = new Settings(); setting.Load(); judger = new Judger(); judger.OnUpdateScore += Judger_OnUpdateScore; judger.TreatExitCodeNonZeroAsRTE = setting.TreatExitCodeNonZeroAsRTE; CompilerTemplateManager ctm = new CompilerTemplateManager(); ctm.Load(); ctm.SaveTest(); }
public void ClickCha(ChaCon cha) { if (cha.isOnBoat()) { CoastCon nowCoast; if (boat.getStatus() == -1) { nowCoast = toCoast; // to->-1; from->1 } else { nowCoast = fromCoast; } boat.getOffBoat(cha.getName()); Vector3 end_pos = nowCoast.getEmptyPosition(); //动作分离版本改变 Vector3 middle_pos = new Vector3(cha.getGameObject().transform.position.x, end_pos.y, end_pos.z); //动作分离版本改变 actionManager.moveCha(cha.getGameObject(), middle_pos, end_pos, cha.move_speed); //动作分离版本改变 cha.getOnCoast(nowCoast); nowCoast.getOnCoast(cha); } else // character on coast { CoastCon nowCoast = cha.getCoastCon(); if (boat.getEmptyIndex() == -1) { return; // boat is full } if (nowCoast.getStatus() != boat.getStatus()) { return; // boat is not on the side of character } nowCoast.getOffCoast(cha.getName()); Vector3 end_pos = boat.getEmptyPosition(); //动作分离版本改变 Vector3 middle_pos = new Vector3(end_pos.x, cha.getGameObject().transform.position.y, end_pos.z); //动作分离版本改变 actionManager.moveCha(cha.getGameObject(), middle_pos, end_pos, cha.move_speed); //动作分离版本改变 cha.getOnBoat(boat); boat.getOnBoat(cha); } userGUI.status = Judger.getInstance().check(fromCoast, toCoast, boat); userGUI.tips = AI.getInstance().tip(fromCoast, toCoast, boat); }
/// <summary> /// Dispatch a single job to the given judger /// </summary> protected async ValueTask <bool> DispatchJob(Judger judger, Job job) { var redis = await this.redis.GetDatabase(); await redis.StringSetAsync(FormatJobStdout(job.Id), "", expiry : TimeSpan.FromHours(2), flags : CommandFlags.FireAndForget); await redis.StringSetAsync(FormatJobError(job.Id), "", expiry : TimeSpan.FromHours(2), flags : CommandFlags.FireAndForget); try { await judger.Socket.SendMessage(new NewJobServerMsg() { Job = job }); job.Stage = JobStage.Dispatched; return(true); } catch { return(false); } }
/// <summary> /// 创建问题 /// </summary> /// <param name="doc">所用XML节点</param> public Problem(XmlNode doc) { Title = doc.SelectSingleNode("title").InnerText; ProblemId = int.Parse(doc.SelectSingleNode("id").InnerText); MemoryLimit = int.Parse(doc.SelectSingleNode("memory_limit").InnerText); ExecuteTimeLimit = int.Parse(doc.SelectSingleNode("time_limit").InnerText); // 判答案的工具 var type = doc.SelectSingleNode("judge_type"); string ops = type is null ? "JudgeCore.Judger.CommonJudge" : type.InnerText; var reflect_type = Assembly.GetExecutingAssembly().GetType(ops); var tc = doc.SelectSingleNode("test_cases"); foreach (XmlNode group in tc.ChildNodes) { Judger.Add(Activator.CreateInstance(reflect_type, group) as IJudger); } }
public SelectionGradingMode(Judger judger) { InitializeComponent(); this.problems = judger.GetListProblemName(); users = judger.GetListUserName(); cbProblemGradingProblem.ItemsSource = problems; cbProblemGradingProblem.SelectedIndex = 0; cbUserGradingUser.ItemsSource = users; cbUserGradingUser.SelectedIndex = 0; cbProblemGradingSubmission.ItemsSource = problems; cbProblemGradingSubmission.SelectedIndex = 0; cbUserGradingSubmission.ItemsSource = users; cbUserGradingSubmission.SelectedIndex = 0; }
private void Start() { Director director = Director.getInstance(); director.currentSceneController = this; factory = this.gameObject.AddComponent <ArrowFactory>(); actionManager = this.gameObject.AddComponent <ArrowActionManager>() as ArrowActionManager; ui = this.gameObject.AddComponent <UI>(); judger = this.gameObject.AddComponent <Judger>(); // factory = Singleton<ArrowFactory>.Instance; loadResources(); int x = Random.Range(0, 3); int y = Random.Range(0, 3); x = direc[x]; y = direc[y]; int level = Random.Range(1, 5); wind = new Vector3(x, y, 0) * level; }
private bool TestJudge(HandCardResult a, HandCardResult b, Judger.Result result, int odds = 0) { if (result == Judger.Judge(a, b)) { if (result == Judger.Result.draw) { return(true); } else { if (odds == Logger.GetOdds(result, a, b)) { return(true); } } } Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(result); Console.WriteLine(odds); return(false); }
protected async ValueTask <bool> TryDispatchJobFromDatabase(Judger judger) { using var scope = scopeProvider.CreateScope(); var db = GetDb(scope); var job = await GetLastUndispatchedJobFromDatabase(db); if (job == null) { return(false); } job.Stage = JobStage.Dispatched; await db.SaveChangesAsync(); try { return(await DispatchJob(judger, job)); } catch { job.Stage = JobStage.Queued; await db.SaveChangesAsync(); return(false); } }
void Awake() { gameGUI = gameObject.AddComponent <GameGUI>() as GameGUI; actionManager = gameObject.AddComponent <ActionManager>() as ActionManager; preists = new Character[3]; devils = new Character[3]; SSDirector.getInstance().currentScenceController = this; LoadResources(); judger = gameObject.AddComponent <Judger>() as Judger; judger.preists = preists; judger.devils = devils; judger.boat = boat; judger.sceneController = this; ai = new AISystem(3); gameGUI.onPressTipButton += delegate { int cnt1 = 0, cnt2 = 0; for (int i = 0; i < preists.Length; i++) { if (!preists[i].onLeft) { cnt1++; } } for (int i = 0; i < devils.Length; i++) { if (!devils[i].onLeft) { cnt2++; } } Tuple <int, int> tip = ai.GetNextStep(cnt1, cnt2, boat.onLeft); gameGUI.boatOnLeft = boat.onLeft; gameGUI.tip = tip; }; }
private void Start() { controller = Director.getInstance().currentSceneController as Controller; controller.actionManager = this; judger = controller.judger; }
// readonly HashSet<string> vacantJudgers = new HashSet<string>(); /// <summary> /// Try to use the provided HTTP connection to create a WebSocket connection /// between coordinator and judger. /// </summary> /// <param name="ctx"> /// The provided connection. Must be upgradable into websocket. /// </param> /// <returns> /// True if the websocket connection was made. /// </returns> public async ValueTask <bool> TryUseConnection(HttpContext ctx) { if (ctx.Request.Query.TryGetValue("token", out var auth)) { var tokenEntry = await Authenticate(auth); if (tokenEntry != null) { // A connection id is passed to ensure that the client can safely // replace a previous unfinished connection created by itself. ctx.Request.Query.TryGetValue("conn", out var connId_); var connId = connId_.FirstOrDefault(); var connLock = await connectionLock.LockAsync(); if (connections.TryGetValue(auth, out var lastConn)) { if (lastConn.ConnectionId != null && connId != null && lastConn.ConnectionId == connId) { // replace this session await lastConn.Socket.Close(System.Net.WebSockets.WebSocketCloseStatus.PolicyViolation, "Duplicate connection", CancellationToken.None); connections.Remove(auth); } else { ctx.Response.StatusCode = StatusCodes.Status409Conflict; connLock.Dispose(); return(false); } } connLock.Dispose(); var ws = await ctx.WebSockets.AcceptWebSocketAsync(); var wrapper = new JudgerWebsocketWrapperTy( ws, jsonSerializerOptions, 4096); var judger = new Judger(auth, tokenEntry, wrapper, connId); { using var _ = await connectionLock.LockAsync(); connections.Add(auth, judger); } logger.LogInformation($"Connected to judger {auth}"); /* * Note: * * We do not add judger to judger queue upon creation, * although it should be available. On the contrary, we rely * on the judger to send a ClientStatusMessage to declare it * is ready, and add it to queue at that time. */ try { using (var conn = judger.Socket.Messages.Connect()) using (var subscription = AssignObservables(auth, judger.Socket)) { await wrapper.WaitUntilClose(); } } catch (Exception e) { logger.LogError(e, $"Aborted connection to judger {auth}"); } logger.LogInformation($"Disconnected from judger {auth}"); { using var __ = await queueLock.LockAsync(); if (JudgerQueue.First != null) { var curr = JudgerQueue.First; while (curr != null) { if (curr.Value == auth) { JudgerQueue.Remove(curr); } curr = curr.Next; } } } { using var _ = await connectionLock.LockAsync(); connections.Remove(auth); } return(true); } else { ctx.Response.StatusCode = 401; // unauthorized } } else { ctx.Response.StatusCode = 401; // unauthorized } return(false); }
public void TestJudgerFunction() { //read sample data var data = new SampleData(); for (int i = 1; i <= 10; i++) data.Datas.Add(new DataPair() { InputData = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\testdata\equation\equation" + i.ToString() + ".in"), OutputData = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\testdata\equation\equation" + i.ToString() + ".out"), }); data.LimitRAM = 137438953472; data.LimitTime = 1000; //load judge unit var ju = new JudgeUnit(); ju.Code = File.ReadAllText(@"D:\SamsOfflineCodeJudge.TestData01\ST33\equation.cpp"); ju.Language = "C++"; var compiler = new Compiler(); compiler.Languages = new List<string>(); compiler.Languages.Add("C"); compiler.Filename = @"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe"; compiler.Argument = "-o \"{Output}\" \"{Filename}\""; compiler.Name = "GNU C++ Compiler"; var judger = new Judger(); judger.Data = data; judger.Unit = ju; var isFinished = false; judger.OnCompiled = (s, e) => { Console.WriteLine("Compilation {0}", e.IsCompilationSucceeded); }; judger.OnJudged = (s, e) => { Console.WriteLine("Judged one,index:{0}", e.Index); }; judger.OnJudgedAll = () => { Console.WriteLine("Index\tRAM\tTime\tExit Code\tResult"); judger.Results.ForEach((r) => { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", r.Index, r.MaximumRAM, r.TotalTime, r.ExitCode, r.Result.ToString()); }); isFinished = true; }; judger.StartJudging(compiler, true); while (!isFinished) ; Console.WriteLine(); }