Skip to content

zen0wu/topcoder-greed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Greed

The missing topcoder arena plugin for algorithm contest.

Greed is good

  • No CodeProcessor+FileEdit+blah, no tons of jars, just Greed
  • Dead simple configuration, just set your workspace, end of story
  • Keeping stuff in workspace enabling seamless migration between OS and environments
  • Testing code. Unit-testing code. Reading-data testing code.
  • Fully customizable
    • File structure
    • Code generation
    • Templates, templates, templates. You define, I generate!
  • Multi language support, including
    • Java
    • C++
    • C#, thanks to @jbransen
    • Python, thanks to @wookayin

Downloads

Go to Releases page.

Quick start

  1. Go to [Downloads], and download the single Greed jar. The binary is compatible with Java 1.6+.

  2. Open Topcoder arena -> Login -> Options -> Editor -> Add
    Add greed
    Done! Remember to check Default and At startup.

  3. Click Configure.
    Configure greed
    Fill in your workspace full path, make sure it's a existing directory.

  4. All set! Go get your rating! Greed UI

Go rock with config

Everything in greed is configuable.

Greed is bundled with some default config, which should be enough for most of you. But if you're not satisfied, go set.

Start with creating a file called greed.conf under your workspace root.

Things you can do with this config,

greed.codeRoot

Change where your code is stored, via greed.codeRoot = ???, this path is relative to your workspace root. Default set to ${Contest.Name}, which means a folder with the name of the current contest under your workspace root.

greed.language.<lang>

This is the configuration object for a specific language, including its template definitions, template to use when submitting, and other language specific settings.

Available language keys are cpp, java, csharp, and python.

Templates sequence

The key is greed.language.<lang>.templates. This is the templates generated by Greed, and any dependent templates will also be generated first (Yup, you're right, by topological order).

The default templates for each language are [filetest, source, problem-desc].

  • The filetest template uses filetest templates, which depends on testcase template. It reads data from the testcase output, and test your program with them. Bind to a piece of code in the source template.
  • The source template generates class and method signature from the problem definition
  • The testcase template outputs test data file to ${Problem.Name}.sample.
    Pay attention to its format since it's important when adding your own testcase.
    • Each testcase is identified by a labeling line which starts with --
    • Each line represents a parameter or the output.
    • If the data itself is an array, there should be multiple lines. Leading with a line with its length, and following by several lines with each of its content.
    • The input and output are separated by an empty line. (Actually, this line is ignored no matter what's in it, you can see its details in the filetest templates).
  • The problem-desc template generates the problem statement into a web page.

Unit test

Another official template is unittest, but disabled by default. This kind of template generates unit test code leveraging UT framework like junit for Java, nunit for C#, and unittest for Python. To use it, set as the following (available for Java, C#, and Python):

greed.language.<lang>.templates = [source, unittest, problem-desc]

This idea was orignally proposed by @tomtung. You can use the unittest code in your favorite IDE, like the following

Resharper NUnit Debugging

Legacy test

Older versions of Greed write test code and test data into code, which makes the generated code a bit messy. However, it's left for backward compatibility and users who actually like it.

greed.language.<lang>.templates = [test, source, problem-desc]

Template definition

Magic here!

You can define your own template type, using the templateDef key under greed.language.<lang>.

Here's what you're going to do.

  • Specify the overwrite behaviour (force, backup or skip)
  • Set the outputKey or outputFile, using variables like ${Problem.Name}, ${Contest.Name}
  • Write your awesome template
  • Set the templateFile to your template (relative path to your workspace)
  • If you like, use some code transformers to cleanup your translated code

You can also add afterFileGen actions to execute scripts or programs after the template generation. Extreme flexibility is given. Here's an possible example of some awesome template def.

greed.language.cpp.templateDef {
    awesome {
        overwrite = skip
        outputFile = "${Contest.Name}/${Problem.Name}.cool"
        templateFile = my-awesome-template.tmpl
        afterFileGen {
            execute = /usr/bin/python
            arguments = [ scripts/awesome-script.py, "${GeneratedFileName}", "${Contest.Name}/somewhere" ]
            timeout = 5
        }
    }
}

Remember to add your template key (awesome in this example) to the templates sequence for this language, or at least make another template in the sequence depends on it.

Want to learn more?

Go to wiki.

You'll learn how to config all the functionalities, like

  • How to write your own templates (Yeh!) and provided templates
  • Advanced features like template dependency, template options, template engines
  • All available binded info in config, like ${Problem.Score}
  • Setting the begin cut and end cut format and other language specific configurations

Build Instructions

The Greed plugin uses gradle as a build system. If you want to build the plugin from the source, invoke the command

./gradlew build     # in *NIX
gradlew.bat build   # or, in windows

to compile, test, and build a JAR archive (including dependencies) that can run in the arena. The produced JAR is located at the directory 'build/libs'.

Bug Tracker

When you encounter a bug and want to see detailed log, add the following to your greed.conf.

greed.logging.logLevel = DEBUG

You can also see the logs by opening the javaws console when launching the arena. Usually this can be enabled in the system-wide java control panel.

Java Web Start Console Setting

For bugs and new features, raise issues here. Please, with the detailed logs, and the problem you're solving and the room you're in, to better identify the problem.

Or, consider contribution!

Contribute to me

Any help is helpful and greatly appreciated.

You can contribute in 2 ways:

  1. Fork, code, and send a pull request. Oh, you're not familiar with this style, well, you should. Read this article.
  2. Be a collaborator, contact @shivawu

License

Copyright 2012-2013 Greed

Licensed under Apache License, Version 2.0. You may obtain a copy of the license in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.