Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Getting Started

Mateo Silver edited this page Aug 10, 2018 · 11 revisions

This page serves as a getting started guide, helping you get your workspace set up for the competition. These steps will guide you through setting up Eclipse, but you can compete using another IDE (like IntelliJ IDEA). Just note that we are less likely to be able to help you if you do not set up your workspace in the way we instruct here.

Download and install software

The Eclipse IDE depends on having a Java Development Kit (JDK) installed. You can download the Java Development Kit from the Oracle website. Make sure to get the JDK, not a Java Runtime Environment (JRE). After that's installed, you can get Eclipse from the Eclipse downloads page.

Importing the project into Eclipse

After everything is installed, you can import your personal repository into Eclipse. Make sure that you're importing your personal repository, not this one. The name of this repository will be of the form foodfighter-username. If you signed up for the competition before May 18, you should have gotten an email from GitHub about your repository. If you signed up later, you should get an email within 48 hours of signing up. Find your repository on the GitHub website, and click the Clone or download dropdown that appears. Make sure that you're getting it over HTTPS, not SSH. Copy the URL that appears in the text box.

GitHub repository view

With Eclipse open, select File > Import.... Then, under the Maven dropdown, select Check out Maven Projects from SCM and hit the Next button.

Import a Maven project

In the SCM URL dropdown, select git. In the text box to the right, paste the git URL you copied earlier. If git does not appear as an option in the dropdown, click the m2e Marketplace link and install the m2e-egit plugin. If the plugin fails to install see this stackoverflow answer, and replace the URL it says to use with https://repository.takari.io/content/sites/m2e.extras/m2eclipse-egit/0.15.1/N/LATEST/. You should be able to select git once you restart the workspace. Once git is selected and the URL is entered, hit the Next button.

Paste the git repository you copied earlier

Then, hit the Finish button.

A screen with no options that need to change

At this point, the repository should be imported, and it should appear in the Package Explorer (on the left by default).

Troubleshooting

If something here fails, try first cloning the project with git (outside of Eclipse), and then importing the project into Eclipse using the Existing Maven Projects import.

Navigating your repository

In your project (in the Package Explorer) there should be a src/main/java source folder, with an org.bitbrawl.foodfighter package inside. In there, there's a SampleController.java file. This class is the entry point of your code. The playAction method inside determines the action that your controller will play, given the field, the team that the controlled player is on, and the player themselves. Each turn of the game, this method will be called once (for every controller in the game).

You can use information from the field, team, and player to make decisions about what moves to play. For now, let's do a very simple example. Our player will always turn right. In other words, they will do nothing but spin in circles. Modify your playAction method so that it looks like this:

@Override
public Action playAction(Field field, Team team, Player player) {

	return Action.TURN_RIGHT;

}

Testing your controller

DebugTest

In the src/test/java source folder, find the DebugTest class and open it. Run it using the green Run button in the toolbar at the top. You should see a window with your controller spinning on a field, playing against one of the sample players.

A sample field in the middle of a game

FullTest

Additionally, you may notice the FullTest class. When run, this class can be used to test your code as it will be tested in tournament settings. That means that it will be running in a separate JVM from the other players (and the game engine), it will be limited in time (60 seconds) and memory (32 MB), and there will be certain classes that you are restricted from using (like File). It's recommended that you test your code at least once with FullTest before each submission, but it's a bit more involved than DebugTest.

First, you will have to compile your code into a single jar file. To do this, right click on the project in the Project Explorer and select Run As > Maven install.

Now, in the target folder, there should be a jar file. Copy that file and paste it into the testing/players directory. In the src/test/resources folder, there should be a config.json file. You will need to add your controller to the list, and maybe remove unwanted sample players. For example, your config.json file might look something like this:

{
	"numMatches": 1,
	"matchType": "FREE_FOR_ALL",
	"controllers": [
		{
			"name": "hiding",
			"jar": "testing/players/sample-players-1.0.0.jar",
			"mainClass": "org.bitbrawl.foodfight.sample.HidingController"
		},
		{
			"name": "walls",
			"jar": "testing/players/sample-players-1.0.0.jar",
			"mainClass": "org.bitbrawl.foodfight.sample.WallsController"
		},
		{
			"name": "Finn's Controller",
			"jar": "testing/players/foodfighter-finn-1.0.0.jar",
			"mainClass": "org.bitbrawl.foodfighter.SampleController"
		}
	],
	"data": "testing/data"
}

Note that if you there are more players in the list than there are players in the match type (for example, if you have four players in the list for a three-player free-for-all), then players will be randomly selected from the list.

Data from the match (and a generated video of the match) will appear in the testing/data directory. Note that the video can take a while to generate. Note that you will have to refresh the files by right-clicking on the testing directory and selecting Refresh.

To view the video, you can't just double-click the mp4 file of the match, because Eclipse will try to open it in a text editor. Instead, right-click on the file and select Open With... > System Editor.

Changing your controller class

You probably don't want SampleController as the name of the controller class, and you may not want its package to be org.bitbrawl.foodfighter. To change it, you will need to change a few files. To change the package name, right-click on the package in the Package Explorer and select Refactor > Rename..., then choose the new name for the package. You can do the same thing for the class name.

You will also have to change the name in the two config.json files: the one in src/main/resources and the one in src/test/resources. Forgetting to change the config file in src/main/resources will make it so we try to run the wrong class in the competition.

Note that you will need to do the "Maven install" process every time you want to run FullTest with a new version of your code. However, if you're confident that you're not using illegal methods or too much time or memory, then you can choose not to run FullTest.

Adding Javadocs

If you hover over the name of a FoodFight class, you may notice a message saying that no Javadoc be found.

A message saying that the Javadoc couldn't be found

To solve this issue, right-click on your project and select Build Path > Configure Build Path.... Then, in the Libraries tab under the Maven Dependencies dropdown, find foodfight-api-1.0.0.jar. Under that dropdown, select Javadoc location and click the Edit... button on the right.

The Libraries tab

Then, enter the URL http://www.bitbrawl.org/doc/.

Entering the URL

After this, you can hit OK and then Apply and Close. The Javadoc should now appear when you hover over the class name.

Submitting your code

Given all of this setup, the submission should be relatively simple. All you need to do is update the version in the src/main/java/config.json file, and then commit and push your code to the git repository. You can do this within Eclipse by right-clicking on the project in the Package Explorer, and selecting Team > Commit.... Drag all of the desired changes from the Unstaged Changes area to the Staged Changes area, and then hit the Commit and Push... button.

Resubmitting your code

You can submit your code as many times as you'd like. The idea is that you can see the performance of your code against other competitors, and then improve and adapt your strategy.

If you want to resubmit your code after making changes, you will need to commit and push as before. You will most likely want to change the version number first; however, you can choose to leave it if you'd like. If you do change the version number, past versions will not affect the leaderboard, so you're essentially erasing the performance of previous versions.