/onbrowserjudge

Judge system that runs on the browser.

Primary LanguageHTMLMIT LicenseMIT

OnBrowserJudge - Judge system that runs on the browser.

日本語説明

Usage

First, download the set of files. (Code → Download ZIP)

When using templates

The following four files are used.

  • template_[langname].html
  • onbrowserjudge.js
  • [langname].js
  • style.css

You only need to rewrite template_[langname].html. The file name should also be changed.

Title, Problem Statement, Constraints, Input and Output

Feel free to rewrite the HTML. In the case of using templates, MathJax is loaded, so you can also use mathematical expressions using LaTeX format, etc. However, there is no problem even if it is written in plain HTML.

Sample Input, Sample Output

<pre id="sample1_input"  class="sample">123</pre>
<pre id="sample1_output" class="sample">456</pre>

As shown above, describe sample input and output in pre elements with the id ~_input and ~_output. The "~" part can be anything, but you must use the same for _input and _output.

If the class attribute sample is given, a copy button will be automatically added.

Test Case

<pre id="testcase1_input"  class="testcase">123</pre>
<pre id="testcase1_output" class="testcase">456</pre>

As with the sample input and output, the input and output values should be described using pre elements with the id ~_input ~_output. In the case of using templates, the class attribute testcase will make them disappear.

These are the only places to rewrite. You can actually run it! (You don't have to upload it anywhere, you can even run it locally to try it out)

If no template is used

If no template is used (or the template is substantially rewritten), the HTML must include the following as a minimum.

  • <script src="onbrowserjudge.js"></script>
  • <script> OnBrowserJudge.workerFile = "[langname].js" </script>
    • These two must be written in this order.
  • One or more pairs of pre elements with the id ~_input ~_output.
  • A button element with the id run.
  • A function named OnBrowserJudge.getProgram() to retrieve the program to run.

As long as you have the above, you are free to rewrite the rest. For more information, please refer to the template files and examples.

Other settings

You can make various changes by defining the following values.

OnBrowserJudge.dict

Translation dictionary. Please refer to the template files and examples for details.

OnBrowserJudge.timeLimit

Sets the time in milliseconds before TLE.

OnBrowserJudge.process(program, casename, input)

The program is processed through this function before being executed. By defining this function, you can create problems that (appear to) use other than standard input/output.

The following is an example of how to make a problem of the form "properly define the method collatz(n)".

OnBrowserJudge.process = (program, casename, input) => program + "\n\n" + "puts collatz(gets.to_i)"

OnBrowserJudge.assertEqual(expected, actual)

Normally, an "example output" value (expected) and an actual output value (actual) are correct only when they match exactly (ignoring trailing blanks), but this function allows for more flexible matching decisions.

OnBrowserJudge.congratulations()

This function is executed when a correct answer is given. For example, if you set up the following, When you answer correctly, "Congratulations!" will be displayed as an alert.

  OnBrowserJudge.congratulations = () => { alert("Congratulations!") }

License

MIT License.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/onbrowserjudge