Skip to content

codenjoyme/codenjoy-java-client

Repository files navigation

This project represents a basic java websocket client for the codenjoy platform. It allows you to easily and quickly join the game, developing your unique algorithm, having a configured infrastructure.

What do you need to get started?

To get started, you should define the desired game and enter a value in com.codenjoy.dojo.JavaRunner.GAME. The class can be found under src/main/java/com/codenjoy/dojo.
GAME is a variable declared in JavaRunner Class.
The second important thing is the connection token to the server. After successful authorization on the site, you must copy the url and enter a value in com.codenjoy.dojo.JavaRunner.URL.
URL is a variable declared in JavaRunner Class. This is enough to connect and participate in the competition.

How to run it?

To start a project from the console window, you must first perform build with Maven mvn clean package assembly:single -Pjar-with-dependencies -DskipTests=true. The entry point for starting a project is com.codenjoy.dojo.JavaRunner.main(args).
You can pass the game type and token connection to the server as command-line arguments. Game parameters passed by arguments at startup have a higher priority than those defined in the code.

The archive is run with the command java -jar target/client-exec.jar [<game>] [<url>]

How does it work?

The elements on the map are defined in com.codenjoy.dojo.games.<gamename>.Element. They determine the meaning of a particular symbol. The two important components of the game are the com.codenjoy.dojo.games.<gamename>.Board game board and the com.codenjoy.dojo.games.<gamename>.YourSolver solver.

Every second the server sends a string representation of the current state of the board, which is parsed in an object of class Board. Then the server expects a string representation of your bot's action that is computed by executing YourSolver.get(board).

Using the set of available methods of the Board class, you improve the algorithm of the bot's behavior. You should develop this class, extending it with new methods that will be your tool in the fight. For example, a bot can get information about an element in a specific coordinate by calling AbstractBoard.getAt(x, y) or count the number of elements of a certain type near the coordinate by calling AbstractBoard.countNear(x, y, element), etc.

Business logic testing

Writing tests will allow you to create conclusive evidence of the correctness of the existing code. This is your faithful friend, who is always ready to answer the question: "Is everything working as I expect? The new code did not break my existing logic?".
The com.codenjoy.dojo.client.<gamename>.BoardTest class contains a set of tests that check board tools. Implementation of new methods should be accompanied by writing new tests and checking the results of processing existing ones.
Use com.codenjoy.dojo.games.<gamename>.YourSolverTest.should_when() to check the bot's behavior for a specific game scenario.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages