Kaggle / Kaggle/kaggle-environments
Kore-2022 Java interpreter errors when wrapping
- Dominant language
- JavaScript
- Stars
- 452
- Forks
- 190
- Avg merge
- 31m
- Merged PRs (30d)
- 2
Description
I think I've found a bug when using the Board::next() function when there is a fleet on the edge of the map.
Below is a test I wrote to reproduce, looks like the code that handles positions / indexes is not quite right. I might have a play and see if I can find the bug. Help appreciated though, this would be the nail in the coffin of my java based approach :(
```java
...
import java.util.List;
import kore.Player;
public class BoardTest {
@Test
public void fleetWrapsAroundTheBoard_northSouth() throws IOException {
Board board = getStarterBoard();
int x = board.size / 2;
int playerId = 0;
Point p1 = new Point(x, board.size);
Fleet f1 = new Fleet("f1", 50, Direction.NORTH, p1, 100.0, "N", playerId, board);
final String f1Id = f1.id;
board.addFleet(f1);
Board nextBoard = board.next();
Player player0 = nextBoard.players[playerId];
Fleet nextF1 = List.of(player0.fleets()).stream().filter(fleet -> fleet.id == f1Id).findFirst().get();
Assert.assertEquals("position.x should not change when wrapping", nextF1.position.x, x);
Assert.assertEquals("position.y should wrap to 0", nextF1.position.y, 0);
}
...
```
```
java.lang.ArrayIndexOutOfBoundsException: Index -16 out of bounds for length 961
at kore.Board.getCellAtPosition([Board.java:115]())
at kore.Fleet.cell([Fleet.java:30]())
at kore.Board.addFleet([Board.java:120]())
at test.BoardTest.fleetWrapsAroundTheBoard_northSouth([BoardTest.java:571]())
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke([NativeMethodAccessorImpl.java:62]())
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([DelegatingMethodAccessorImpl.java:43]())
at java.base/java.lang.reflect.Method.invoke([Method.java:566]())
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall([FrameworkMethod.java:59]())
at org.junit.internal.runners.model.ReflectiveCallable.run([ReflectiveCallable.java:12]())
at org.junit.runners.model.FrameworkMethod.invokeExplosively([FrameworkMethod.java:56]())
at org.junit.internal.runners.statements.InvokeMethod.evaluate([InvokeMethod.java:17]())
at org.junit.runners.ParentRunner$3.evaluate([ParentRunner.java:306]())
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate([BlockJUnit4ClassRunner.java:100]())
at org.junit.runners.ParentRunner.runLeaf([ParentRunner.java:366]())
at org.junit.runners.BlockJUnit4ClassRunner.runChild([BlockJUnit4ClassRunner.java:103]())
at org.junit.runners.BlockJUnit4ClassRunner.runChild([BlockJUnit4ClassRunner.java:63]())
at org.junit.runners.ParentRunner$4.run([ParentRunner.java:331]())
at org.junit.runners.ParentRunner$1.schedule([ParentRunner.java:79]())
at org.junit.runners.ParentRunner.runChildren([ParentRunner.java:329]())
at org.junit.runners.ParentRunner.access$100([ParentRunner.java:66]())
at org.junit.runners.ParentRunner$2.evaluate([ParentRunner.java:293]())
at org.junit.runners.ParentRunner$3.evaluate([ParentRunner.java:306]())
at org.junit.runners.ParentRunner.run([ParentRunner.java:413]())
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run([JUnit4TestReference.java:89]())
at org.eclipse.jdt.internal.junit.runner.TestExecution.run([TestExecution.java:40]())
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests([RemoteTestRunner.java:529]())
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests([RemoteTestRunner.java:756]())
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run([RemoteTestRunner.java:452]())
```
Contributor guide
Research direction
Start with the BoardTest.fleetWrapsAroundTheBoard_northSouth reproduction, then inspect Board.getCellAtPosition and Board.addFleet, where the stack trace shows the negative index, along with Fleet.cell. Verify the Board.next() path for edge fleets and run the test; done means no exception and the fleet wraps with x unchanged and y equal to 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100