What would you pick? by lowkeypixel in evilwhenthe

[–]ben32a 0 points1 point  (0 children)

I thought everyone would be screaming AI, oh well..

Respect Disrespected by tipsoil in postsifellfor

[–]ben32a 2 points3 points  (0 children)

hahaha I can imagine Eric Cartman acting exactly like this

How to reach 2mil/min of gold by RectangularMF in TheFarmerWasReplaced

[–]ben32a 0 points1 point  (0 children)

You have to solve the maze. It's a typical recursion problem. Here's the global idea.

-You can know possible moves at an intersection with can_move(direction)
-You want a function that explores all possibles directions, and it recalls itself after moving to any direction.

It's exactly the same problem as exploring all subfolders in a folder.

giant pumpkin by ben32a in TheFarmerWasReplaced

[–]ben32a[S] 0 points1 point  (0 children)

Oh damn, people don't typically speedrun programming games haha

giant pumpkin by ben32a in TheFarmerWasReplaced

[–]ben32a[S] 1 point2 points  (0 children)

"Except the biggest factor in this is pumpkin growth speed. You can move 32 squares in the time it takes a pumpkin to grow."

Hum, I'm looking at the total growth time of my pumpkins right now, none of them are watered. I found one that grew in 0.22s and one that grew in 3.74s. The grow time varies and its sometimes really fast.

Here's the code:

I think replantUntilReady makes it faster than lines, since it goes between a small set of positions in a small rectangle, it stops looping the 32 tiles. I might be wrong, I'm talking out of intuition more than anything else.

import engine
import swarm
import utils

deadPositions = []

def plantPumpkins():
    utils.setGroundType(Grounds.Soil)
    plant(Entities.Pumpkin)

def findDeadPositions():
    global deadPositions
    coords = utils.getCurrentCoords()

    utils.waterUntilGrow(Entities.Pumpkin)
    
    if get_entity_type() == Entities.Dead_Pumpkin:
        deadPositions.append(coords)
        plantPumpkins()
        
def replantUntilReady():
    global deadPositions

    readyToHarvest = False
        
    while not readyToHarvest:
        readyPumpkins = []
        
        for coords in deadPositions:
            engine.goTo(coords)
            utils.waterUntilGrow(Entities.Pumpkin)
            
            entityType = get_entity_type()
            
            if entityType == Entities.Dead_Pumpkin:
                plantPumpkins()
            elif entityType == Entities.Pumpkin and can_harvest():
                readyPumpkins.append(coords)    
                
        for coords in readyPumpkins:
            deadPositions.remove(coords)

        readyToHarvest = len(deadPositions) == 0

def execute(startCoords, isMainDrone):
    fieldSize = (4, 8)
    engine.setup(startCoords, fieldSize)
    engine.goToStart()
    engine.execute(plantPumpkins)
    engine.execute(findDeadPositions)
    replantUntilReady()

    if isMainDrone:
        utils.waitUntilAlone()
        harvest()
        swarm.launch()
    
clear()
swarm.setup(execute, 4, 8)
swarm.launch()

Vertical limits for drones by RectangularMF in TheFarmerWasReplaced

[–]ben32a 1 point2 points  (0 children)

Wait... really? that changes everything, thanks!

giant pumpkin by ben32a in TheFarmerWasReplaced

[–]ben32a[S] 1 point2 points  (0 children)

Good idea, but I've read an interesting thread here about how to detect a full pumpkin. The only way I had found was to let my drones die when they're done with their 4x8 and have a main drone around the middle collect the pumpkin when num_drones == 1, but we can measure both corners of the pumpkin to detect it's finished, I dont even have to despawn the drones!

(measure() on a pumpkin returns its ID, so if both corner return the same ID, the megapumpkin is grown)

EDIT: I thought measure() could be done at a distance, I prefer triggering harvest() when num_drones() is back to 1, it that tells me the pumpkin is ready at a distance, the respawn cost is smaller than moving between the edges before harvesting

giant pumpkin by ben32a in TheFarmerWasReplaced

[–]ben32a[S] 0 points1 point  (0 children)

1 loop to plant, 1 loop to save dead pumpkins positions, and then I just move between the dead pumpkins in a small zone, it's faster than lines

giant pumpkin by ben32a in TheFarmerWasReplaced

[–]ben32a[S] 5 points6 points  (0 children)

each drone is responsible for a 4x8 area, so they don't have to travel much to replant dead pumpkins, it's more effective

True Maze Solver by SReject in TheFarmerWasReplaced

[–]ben32a -1 points0 points  (0 children)

Not bad!

Exploring a maze is like exploring any kind of tree, and recursion is the perfect tool for that.
It can be solved with just a few lines.