Few bugs/questions

Hi guys

First off, let me say great work on the new forum, and I love the new challenge… seems super simple, but it really isn’t :grin:

First thing I would like to mention is that there seems to be a problem with the validation of ship placement. The reference bot often also fails to place his ships, and after mine failed many times I decided to test it manually. I took the place.txt file, and placed the ships manually on a Excel sheet, paying close attention to use the Direction modifiers as they are coded in the Game Engine. It works out every time, but the Game Engine fails with errors like Cell(9,1) has no neighbours to the east, which regardless of whether East is left or right, there should be a cell there!

The questions I mentioned:

  1. There is a Ships collection in the OpponentMap field of the state.json file, but it always contains all 5 ships regardless of whether you sink an opponents ship or not. The official rules for Battleships specifies that when an opponent sinks one of your ships, you have to say “Hit! You sunk my Carrier” or whatever. Is hiding what ships have been sunk intentional? If so, why have the Ships collection in the OpponentMap at all?

  2. Reading through the rules, it doesn’t seem forbidden to write out state information between rounds.Will this be allowed, or is it only an oversight in the rules?

  3. Since the bots are run in parallel (as far as I can tell from the BotRunner implementation), wouldn’t it be possible for someone to “cheat” and read the state.json file from the opponents working directory? Something akin to this:

    var opponentStateFilename = myWorkingDirectory + “…” + (playerKey == “A” ? “B” : “A”) + “\state.json”;
    using (var file = new StreamReader(opponentStateFilename))
    {
    jsonText = file.ReadToEnd();
    }

Thanks

Excuse my blonde moment, :rolling_eyes:

Only noticed now that the Ships collection isn’t a collection of the Ship Types, but actually holds information about whether each one has been destroyed. Disregard question 1 please

Hi sschocke,

Sorry about the confusion about the ships collection in the OppenentMap, glad you managed to figure it out :slight_smile: With regards to other questions:

  1. You will be allowed to keep state within your bots execution directory, every time your bot starts a match the files in your bot directory will be persisted for the entire match so you are more than welcome to store state files there so long as you stay within in the tournament rules.
  2. The bots are not supposed to run in parallel and I don’t believe they do, it will always be executed sequentially with the files being only available to the bot currently executed (When the game engine is running in tournament mode). If this is not the case however we will have to investigate this and make the required changes in the game engine.

Thanks Hennie, great news about being allowed to keep state during a match.

Regarding the parallel execution, I think you may be correct. There is a Thread started up each round for each player, but I missed the part where the Thread is joined until it is finished executing.

Any ideas on the ship placement bug I described?

Hi sschocke,

We will investigate the ship placement issue with the Game Engine and get back to you once a fix has been released.

Here are some placement examples that failed for me:

21-04-2017 20:48:06:409 - E: Failed to process command PlaceShipCommand for player GustavGameEngine.Exceptions.InvalidCommandException: There was a problem during the placement of player’s Gustav ships, the round will be played over —> System.InvalidOperationException: This cell does not have a neighbour in the West direction
at Domain.Maps.Cell.Neighbour(Direction direction) in W:\Projects\100k\2017\Github\2017-Batteships\GameEngine\Battleships\Domain\Maps\Cell.cs:line 71

21-04-2017 20:48:06:362 - I: Output from bot: Placement instructions:
21-04-2017 20:48:06:362 - I: Output from bot: Carrier 1 4 West
21-04-2017 20:48:06:362 - I: Output from bot: Battleship 9 2 North
21-04-2017 20:48:06:362 - I: Output from bot: Cruiser 2 9 West
21-04-2017 20:48:06:362 - I: Output from bot: Submarine 5 0 North
21-04-2017 20:48:06:362 - I: Output from bot: Destroyer 7 5 North
21-04-2017 20:48:06:362 - I: Output from bot:
21-04-2017 20:48:06:362 - I: Output from bot:
21-04-2017 20:48:06:362 - I: Output from bot: RRR~~~
21-04-2017 20:48:06:362 - I: Output from bot: ~~~~~~~~~~
21-04-2017 20:48:06:362 - I: Output from bot: ~~~~~~~~~~
21-04-2017 20:48:06:362 - I: Output from bot: ~~~~~D
21-04-2017 20:48:06:362 - I: Output from bot: ~~~~~D~B
21-04-2017 20:48:06:362 - I: Output from bot: ~CCCCC
~B
21-04-2017 20:48:06:362 - I: Output from bot: ~~~~~~~~~B
21-04-2017 20:48:06:362 - I: Output from bot: ~~~S~B
21-04-2017 20:48:06:362 - I: Output from bot: ~S
21-04-2017 20:48:06:362 - I: Output from bot: ~S

21-04-2017 20:48:08:350 - E: Failed to process command PlaceShipCommand for player GustavGameEngine.Exceptions.InvalidCommandException: There was an issue during the placement of the ships —> System.InvalidOperationException: Can’t place an occupant on this cell as there is already one present.
at Domain.Maps.Cell.Place(Direction direction, Ship ship) in W:\Projects\100k\2017\Github\2017-Batteships\GameEngine\Battleships\Domain\Maps\Cell.cs:line 81
at Domain.Ships.Ship.Place(Point point, Direction direction, PlayerMap playerMap) in W:\Projects\100k\2017\Github\2017-Batteships\GameEngine\Battleships\Domain\Ships\Ship.cs:line 76

21-04-2017 20:48:08:334 - I: Output from bot: Placement instructions:
21-04-2017 20:48:08:334 - I: Output from bot: Carrier 9 4 North
21-04-2017 20:48:08:334 - I: Output from bot: Battleship 4 2 West
21-04-2017 20:48:08:334 - I: Output from bot: Cruiser 3 1 North
21-04-2017 20:48:08:334 - I: Output from bot: Submarine 4 0 West
21-04-2017 20:48:08:334 - I: Output from bot: Destroyer 3 6 North
21-04-2017 20:48:08:334 - I: Output from bot:
21-04-2017 20:48:08:334 - I: Output from bot:
21-04-2017 20:48:08:334 - I: Output from bot: ~~~~~~~~~~
21-04-2017 20:48:08:334 - I: Output from bot: ~~~~~C
21-04-2017 20:48:08:334 - I: Output from bot: ~D
~C
21-04-2017 20:48:08:334 - I: Output from bot: ~D
~C
21-04-2017 20:48:08:334 - I: Output from bot: ~~~~~~~~~C
21-04-2017 20:48:08:334 - I: Output from bot: ~C
21-04-2017 20:48:08:334 - I: Output from bot: ~R

21-04-2017 20:48:08:334 - I: Output from bot: ~RBBBB
21-04-2017 20:48:08:334 - I: Output from bot: ~R

21-04-2017 20:48:08:334 - I: Output from bot: ~~SSS~

Placements by the reference bot also often fails with the same kinds of errors.

21-04-2017 20:48:07:376 - E: Failed to process command PlaceShipCommand for player JohnGameEngine.Exceptions.InvalidCommandException: There was a problem during the placement of player’s John ships, the round will be played over —> System.InvalidOperationException: This cell does not have a neighbour in the East direction
at Domain.Maps.Cell.Neighbour(Direction direction) in W:\Projects\100k\2017\Github\2017-Batteships\GameEngine\Battleships\Domain\Maps\Cell.cs:line 71
at Domain.Ships.Ship.CanPlace(Point point, Direction direction, PlayerMap playerMap) in W:\Projects\100k\2017\Github\2017-Batteships\GameEngine\Battleships\Domain\Ships\Ship.cs:line 90

Hi Gustav,

I think I see the issue, please see the explanation below. Also, I’ve created a new issue on the Github page, you can view progress on it here.

From my understanding based on the commands you gave both the cruiser and carrier will fail, the game engine will take the coordinates you gave and place the ship blocks in the direction you specified from that coordinate. Also, the map coordinate are on a Cartesian coordinate system, meaning 0,0 is the bottom left of the map.

So for example, the Carrier will start to place at (X:1,Y4) then the next block would be (X:0, Y:4) and then (X:-1,Y:4) which is why the game engine is giving the error.

This is the way it is supposed to work anyways, if not then there is most certainly a bug in the game engine.

So, if I understand correctly, what you are saying is that I have east and west the wrong way round. Thanks for pointing that out. Looking at this now, I am not sure what I was thinking. Thank you very much.