# How to make ship scan its environment?

#1

Hey there, I am an absolute beginner in AI. I just completed a beginners course in Web Dev, but that about it. Anyone know how I woud make the ship scan say a 5 *5 area around it and then go where it has the max amount of hailte and then return?

#2

To my knowledge, there is no direct way. However, you can still do it the hard way:

pos = ship.position
max = 0
for i in range(pos.x - 2, pos.x + 2):
for j in range(pos.y - 2, pos.y + 2):
if game_map[Position(i,j)].halite_amout > max:
max = game_map[Position(i,j)].halite_amount
max_pos = Position(i,j)

That should gives you the maximum halite and the position of this cell. You can then navigate to it using:

naive_navigate(ship, max_pos)

I hope this helped. Maybe the codes contains some errors, I wrote them on the fly, but try to fix it and the logic should be correct.

#3

Adding onto cxpox’s answer you can add more artificial intelligence to your search by adding a heuristic search element to each spot’s amount, for example by adding the cost of movement to spot, how much it would cost to return from that spot to the nearest drop off. This can be used to approximate the opportunity cost of moving to one square vs another, as the full equation of the expected cost of each square for each ship might take more than the 2 seconds allow.

#4

You can use something like:

``````def get_search_radius(ship, radius):
""" returns a list of all positions within square radius of a ship """
``````def get_search_radius(ship, radius, game_map):