Simple wood farm
It's a simple wood farm for the beginning of the game.
def best_move(d1, n1, d2, n2):
d, n = ((d1, n1), (d2, n2))[n2 < n1]
for _ in range(n):
move(d)
def nav(x2, y2):
x1, y1 = get_pos_x(), get_pos_y()
n = get_world_size()
best_move(East, (x2 - x1) % n, West, (x1 - x2) % n)
best_move(North, (y2 - y1) % n, South, (y1 - y2) % n)
n = 6
set_world_size(n)
while True:
for y in range(n):
for x in range(n):
nav(x, y)
p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush
if can_harvest():
harvest()
plant(p)
Let's check some interesting moments.
First of all, I like nav function a lot. It allows to write a clean and concise code. Write once, use forever. Until you need a heavy optimization, but it's a different story.
n = 6
set_world_size(n)
I have quite an advanced farm, these lines shrink it back into the "beginning of the game" state. In the beginning of the game you had better use
n = get_world_size()
while True:
Let's repeat our harvesting.
for y in range(n):
for x in range(n):
nav(x, y)
We traverse the whole board.
p = Entities.Tree
if (x + y) % 2:
p = Entities.Bush
a chessboard pattern for bushes and trees. Allows trees to grow fast.
if can_harvest():
harvest()
quite an important trick. Prevents young trees from being chopped down. Without this "if" one can chop a tree without getting a reward for it.
plant(p)
plant the plant again.
Happy woodchopping!!!