Ocean of Code - Puzzle discussion

Feel free to ask questions and give your feedback. The game was created by @G-Rom @Illedan and @eulerscheZahl

https://www.codingame.com/multiplayer/bot-programming/ocean-of-code

We’ve pushed every AIs from the contest into the new arena. Enjoy!
:slight_smile:

Strategies forum thread

3 Likes

Hello everyone. I’m writing here because this is not strategies-related question.
I’m having an issue with timeouts with this kind of warning, it happens for about 10% of all of my games.
I tried to check if there’s still something left available in the input stream, but it seems it’s empty.
Would love to hear if anyone encountered such a problem, because so far I wasn’t able to figure out what’s wrong.
Here is an example of my situation:

This is just a warning and shouldn’t make you timeout. There is no other info in the console?

1 Like

This warning should be reworded to also include the possibility you’re writing too many outputs. That’s another possibility where you can go wrong.

1 Like

I’ve turned off all of my debug - which consisted of 2 maps displaying all possible locations for me & opponent, as well as a single line with some handy debugging information for myself. I’m not really sure where my issue lies but if I turn off all of my debug output I don’t get any of those timeouts, so that definitely helped. I was just really confused because this warning only displays when I run the game manually via “play my code” button (on submit window it just shows timeout and no additional info) - and that required on average about 20 tries to get this message pop up. Thank you very much for all the insight - I guess I’ll know how to deal with it slighty better in future :slight_smile:

I’ve had this discussion with Julien actually and we agreed it’s a specific case of the aforementioned warning.

@Gabbek you get the warning only when you timeout? To me, they are two different things. You code might timeout because it takes too much time to write all those debug messages. And imo, the warning should not pop because of the timeout. I need to check that with Julien

I’ll try to clarify: I do get the warning only when I’m in main window by using “play my code” button. If I view my submitted game (the smaller window, where you can see all of your games) - then there’s only a timeout indicated on one of the turns, in my case it was always the 3rd turn, so the first one after the 1 second initial turn. It could be the case that I was calculating quite a lot and all but final debug messages would make me timeout - as I had my “think” (main logic), then debug display, and then I would write my result for the turn. I’ll try to do some more digging because I don’t want to misinform you.

Edit: One more word about the warning not popping up - I have never seen this warning in any other games and I had quite a lot of timeouts on some of my other bots :smiley: so those are probably 2 different things which just happened to be combined in this case - that’s my current guess.

What are logic from tackling from island and out of the map

Hello, I’ve been having very strange errors on this game. My code gives answers that it shouldn’t give. And to make sure I’ve commented one, and I made sure it is not being used on any other part of the code. But, this instruction is still issued in the game as you’ll be able to see in the images below. Apart of that, I’ve been having an error, that I’ve solved in the past, the problem was that more than one instruction was being printed. But this time I’m really sure that is not the case. Could it be a memory error?

image
image

It prints debug messages where it is not supposed to.
image

As you can see ont he next image the -##### Move W 0- was supposed to be printed on the if else that fprints MSG debug_1

image

Thank you!

Finally was able to discover the problem. Apparently surface action must go alone? Well, it worked for me.

Hello, i’m searching the documentation of the games, for example all the differents actions, but i can’t find it.

Also, i can’t find the input data that tell me where are the island.
Finally, why is all my cd (except for torpedo) at -1 ?

Have you read the puzzle statement, which should contain the information you ask about?

I have problem with forward declaration of class,

this is sample code with that problem

class GameState;

// Class representing the submarine
class Submarine {
public:
  // Constructor
  Submarine(Position position)
      : mPosition(position), mHitPoints(3), mTorpedoCooldown(0),
        mSonarCooldown(0), mSilenceCooldown(0), mMines(0) {}
  // Update the submarine's position
  void update(Position position);

  // Get the next action for the submarine
  Action getNextAction(const GameState &gameState, const Opponent &opponent);

  // Getter for the submarine's position and hit points
  Position getPosition() const { return mPosition; }
  int getHitPoints() const { return mHitPoints; }

  Position mPosition;
  int mHitPoints;
  int mTorpedoCooldown;
  int mSonarCooldown;
  int mSilenceCooldown;
  int mMines;
  // Helper function to determine the direction to move towards a target
  // position
  Direction getMoveDirection(const GameState &gameState, const Position &targetPos);

  // Helper function to determine the farthest direction in which we can move
  // silently
  Direction getFarthestDirection( const GameState &gameState, int maxDist) {
    Direction farthestDir = Direction::NONE;
    int farthestDist = -1;
    for (int d = 0; d < 4; d++) {
      Direction dir = static_cast<Direction>(d);
      int dist = 0;
      Position pos = mPosition;

      while (dist < maxDist) {
        Position nextPos = pos;

        switch (dir) {
        case Direction::NORTH:
          nextPos.y -= 1;
          break;
        case Direction::EAST:
          nextPos.x += 1;
          break;
        case Direction::SOUTH:
          nextPos.y += 1;
          break;
        case Direction::WEST:
          nextPos.x -= 1;
          break;
        default:
          break;
        }

        // Stop searching if we hit an island or a previous position
        bool isIsland = gameState.isIsland[nextPos.y][nextPos.x];

        if (nextPos.x < 0 || nextPos.x >= 15 || nextPos.y < 0 ||
            nextPos.y >= 15 || isIsland ||
            nextPos == mPosition) {
          break;
        }

        pos = nextPos;
        dist++;
      }

      // Update farthest direction if the distance is greater than the previous
      // farthest distance
      if (dist > farthestDist) {
        farthestDir = dir;
        farthestDist = dist;
      }
    }

    return farthestDir;
  }

  // Helper function to determine the closest sector that has not been sonared
  // yet
  int getClosestUnsonaredSector(const GameState &gameState);

  // Helper function to determine the next position to move to
  Position getNextPosition(const GameState &gameState,
                           const Opponent &opponent);
};

and problem is with this line

bool isIsland = gameState.isIsland[nextPos.y][nextPos.x];

gameState.isIsland[…][…] dot between gameState and isIsland errror say

/tmp/Answer.cpp: In member function ‘Direction Submarine::getFarthestDirection(const GameState&, int)’:
/tmp/Answer.cpp:195:25: error: invalid use of incomplete type ‘const class GameState’
195 | bool isIsland = gameState.isIsland[nextPos.y][nextPos.x];
| ^~~~~~~~~
/tmp/Answer.cpp:135:7: note: forward declaration of ‘class GameState’
135 | class GameState;

I thik forward declaration should work, especially that I am using this class passing in function, and in other places in my code, there are no problems with that. Only this line make problem.

I think i have solved problem, I did move function body outside of the class, and put lower where is reqired class definition.

I am confused by this line in the code. What does it do? Also i cannot find the input for islands.
for i in range(height):
line = input()

Your code is not indented/formatted properly. Please use the </> button on the formatting toolbar in the future.

If you’re confused about what line represents, you may read the statement, which explains what all the inputs are.

Also, you may add debug statements in the code to see what input() has read, e.g.

for i in range(height):
    line = input()
    print(line, file = sys.stderr, flush = True)

The above code will show the value of line in the console error output.

Thank you that worked.

I need help. I created a code in python 3 that is suppose to figure out were my enemy is. But it doesn’t work.

It is properly indented in my scrip but I couldn’t figure out how to make it appear that way.