collision detection – Need help improving my Flow Field and Unit Avoidance code so that the units can properly surround a unit instead of getting stuck

My setup is like this. Every update my movement system moves all of the units on the field. They use some Boid logic to avoid eachother, and a flow field that directs them towards each other. This is the result. https://imgur.com/a/CaUpfT7

My general setup is to calculate 2 flow fields, one for each player. From every field on the map (32×32 fields) I calculate the vector that points towards the closest enemy. Now this is a fine approach but I’d like to somehow take into consideration obstacles somehow (without another round of for loops)? Or should I handle that in my movement system avoidance? I was maybe thinking of doing A* once a unit is close enough to the enemy but all of these systems together seem rather hacky and overkill.

Here is some code. Firstly how I create the flowfields (kinda costly, will look into a way to optimize it further, don’t really need every single tile, can probably merge 2 or 3 together)

func (g *Grid) Update() {
    g.entityPositions(0) = g.entityPositions(0)(:0)
    g.entityPositions(1) = g.entityPositions(1)(:0)
    entities := g.world.GetEntityManager().GetEntities()
    posComps := g.world.GetObjectPool().Components("PositionComponent")

    for _, ent := range entities {
        g.entityPositions(ent.PlayerTag) = append(g.entityPositions(ent.PlayerTag), posComps(ent.Index).(components.PositionComponent).Position)
    }

    for x := 0; x <= g.MaxWidth/FlowTileSize; x++ {
        for y := 0; y <= g.MaxHeight/FlowTileSize; y++ {

            curPosVector := engine.Vector{X: float32(x * 32), Y: float32(y * 32)}
            // find closest tile to this one for both players
            minDist := float32(100000.0)
            minIndx := -1
            for indx, pos := range g.entityPositions(0) {
                d := engine.GetDistanceIncludingDiagonal(pos, curPosVector)
                if d < minDist {
                    minIndx = indx
                    minDist = d
                }
            }

            //  fmt.Printf("CurPos : %v, enemyPos : %v,  direction %v n", curPosVector, g.entityPositions(0)(minIndx), g.entityPositions(0)(minIndx).Subtract(curPosVector).Normalize())
            g.flowTiles(1)(x)(y).Direction = g.entityPositions(0)(minIndx).Subtract(curPosVector).Normalize()

            minDist1 := float32(100000.0)
            minIndx1 := -1
            for indx, pos := range g.entityPositions(1) {
                d := engine.GetDistanceIncludingDiagonal(pos, curPosVector)
                if d < minDist1 {
                    minIndx1 = indx
                    minDist1 = d
                }
            }

            g.flowTiles(0)(x)(y).Direction = g.entityPositions(1)(minIndx1).Subtract(curPosVector).Normalize()
        }
    }
}

And my movement code. A lot of code but just basic allignnment cohesion/ separation. With added 2 look ahead vectors to steer away from the collision.

        desiredDirection := world.Grid.GetDesiredDirectionAt(positionComp.Position, tag)
        direction := movementComp.Direction
        maxSpeed = movementComp.MovementSpeed

        //Avoidance
        nearbyEntities := helper.GetNearbyEntities(100, world, index)

        avoidance := engine.Zero()
        avoidance = avoidance.Add(alignment(world, nearbyEntities, direction).MultiplyScalar(alignmentCoef))
        avoidance = avoidance.Add(cohesion(world, nearbyEntities, direction, positionComp.Position).MultiplyScalar(cohesionCoef))
        avoidance = avoidance.Add(separation(world, nearbyEntities, direction, positionComp.Position).MultiplyScalar(separationCoef))


        //Checking ahead of us whether or not we'll encounter something
        lookAheadVectorLong := direction.Add(desiredDirection).MultiplyScalar(maxSpeed * 2.5)
        lookAheadVectorShort := direction.Add(desiredDirection).MultiplyScalar(maxSpeed)
        maxAvoidanceForce := float32(1.0)

        checkPosShort := positionComp.Position.Add(lookAheadVectorShort)
        checkPosLong := positionComp.Position.Add(lookAheadVectorLong)

        collidedIndexShort := world.Grid.IsPositionFree(index, checkPosShort, positionComp.BoundingBox)
        collidedIndexLong := world.Grid.IsPositionFree(index, checkPosLong, positionComp.BoundingBox)

        if collidedIndexShort != -1 {
            direction = engine.Zero()
            avoidance = checkPosShort.Subtract(world.ObjectPool.Components("PositionComponent")(collidedIndexShort).(components.PositionComponent).Position).Normalize()
            avoidance = avoidance.MultiplyScalar(maxAvoidanceForce * 1.5)
        } else if collidedIndexLong != -1 {
            direction = direction.MultiplyScalar(breakingForce)
            avoidance = checkPosShort.Subtract(world.ObjectPool.Components("PositionComponent")(collidedIndexLong).(components.PositionComponent).Position).Normalize()
            avoidance = avoidance.MultiplyScalar(maxAvoidanceForce * 1.2)
        }

        direction = desiredDirection
        direction = direction.Add(avoidance).Normalize()

        positionComp.Position = positionComp.Position.Add(direction.MultiplyScalar(maxSpeed))

        positionComp.Position.X = engine.Constraint(positionComp.Position.X, 0, 799)
        positionComp.Position.Y = engine.Constraint(positionComp.Position.Y, 0, 511)

        movementComp.Direction = direction.Normalize()

        world.ObjectPool.Components("PositionComponent")(index) = positionComp
        world.ObjectPool.Components("MovementComponent")(index) = movementComp

        fmt.Printf("I %d am at %vn", index, positionComp.Position)
    }

}

func limit(p engine.Vector, lim float32) engine.Vector {
    if p.X > lim {
        p.X = lim
    } else if p.X < -lim {
        p.X = -lim
    }
    if p.Y > lim {
        p.Y = lim
    } else if p.Y < -lim {
        p.Y = -lim
    }
    return p
}
func alignment(world *game.World, siblings ()int, velocity engine.Vector) engine.Vector {
    avg := engine.Vector{X: 0, Y: 0}
    total := float32(0.0)

    for _, siblingIndex := range siblings {
        avg = avg.Add(world.ObjectPool.Components("MovementComponent")(siblingIndex).(components.MovementComponent).Direction)
        total++
    }
    if total > 0 {
        avg = avg.DivideScalar(total)
        avg = avg.Normalize().MultiplyScalar(maxSpeed)
        avg = avg.Subtract(velocity)
        avg = limit(avg, maxForce)
        return avg
    }
    return engine.Vector{X: 0.0, Y: 0.0}

}

func cohesion(world *game.World, siblings ()int, velocity engine.Vector, position engine.Vector) engine.Vector {
    avg := engine.Vector{X: 0, Y: 0}
    total := float32(0)

    for _, siblingindex := range siblings {

        avg = avg.Add(world.ObjectPool.Components("PositionComponent")(siblingIndex).(components.PositionComponent).Position)
        total++

    }
    if total > 0 {
        avg = avg.MultiplyScalar(1.0 / total * cohesionCoef)
        avg = avg.Subtract(position)
        avg = avg.Normalize().MultiplyScalar(maxSpeed)
        avg = avg.Subtract(velocity)
        avg = limit(avg, maxForce)
        return avg
    }
    return engine.Vector{X: 0.0, Y: 0.0}
}

func separation(world *game.World, siblings ()int, velocity engine.Vector, position engine.Vector) engine.Vector {
    avg := engine.Vector{X: 0, Y: 0}
    total := float32(0)

    for _, siblingIndex := range siblings {
        siblingPos := world.ObjectPool.Components("PositionComponent")(siblingIndex).(components.PositionComponent).Position
        d := position.Distance(siblingPos)
        if d < desiredSeperation {
            diff := position.Subtract(siblingPos)
            diff = diff.Normalize()
            diff = diff.DivideScalar(d)
            avg = avg.Add(diff)
            total++
        }
    }
    if total > 0 {
        avg.DivideScalar(total)
    }

    if total > 0 {
        avg = avg.MultiplyScalar(1.0 / total * separationCoef)
        avg = avg.Normalize().MultiplyScalar(maxSpeed)
        avg = avg.Subtract(velocity)
        avg = limit(avg, maxForce)
    }
    return avg
}

What I am trying to achieve is:

Units not mashing into each other and just positioning themselves in a free spot around their target.

What are my problems :

  1. Make the flow field direct them away from collision rather than just towards closest unit.
  2. Make it work with the current system without adding too many nested loops and awful checks.
  3. I am doing the avoidance correctly? I have a desired direction that I get from the flow field (that directs me towards closest enemy), then I add avoidance to it to avoid any other units in the area.

My units move really well up untill the point of collision/ going to a spot next to a target. I am not sure how to implemenent that behaviour yet.

(This is my forth iteration of the movement system. I went from pure boid, to grid based, to A*, to this. So I tried a lot of variations and this going surrounding behaviour has been bugging me every time.)

Custom engine (server) written in Golang and then dispatched to Godot for the visuals. Performance is not my concern, but this is a server, so I am more mindful of that, I could probably brute force it but I’d rather hear some better take on it.

Any suggestion/article/ video is greatly appreciated !!

Using the same Power Automate approval flow in many SharePoint document libraries

I have a working workflow in Power Automate connected to one document library. The approvers are listed in a special SharePoint group for that document library.

This workflow is using my user connections to run, but the recommendation of my organization is to use a special service account to avoid problems when a person is leaving the organization.
So I will recreate the workflow using the new credentials/connections of the service account.

The workflow is now so popular that I have been asked to add it to 20 other document libraries. If I make twenty copies of the workflows I am seeing the risk that I will get a lot of maintenance work.
For instance, if I need to add functionality I am afraid I have to do the same work in twenty different workflows.

So, can I parameterize the names of the document libraries (and its approver group)? Or are there any tricks with the deployment of the workflows that can help me (for instance Pnp PowerShell)?
What is best practice for using the same workflow for several document libraries?

excel – MS Flow stops working when I update the file in SharePoint

I have a MS Flow that updates a list in SharePoint from an Excel file that I manually upload.
Whenever I upload a new file, the MS Flow stops working, see, inside the Excel file I have a table, that I pull from another system, then the file is uploaded to a site inside SharePoint. Every time I upload a new file I have to update the MS Flow to grab the “new” file, the file is always named the same as the previous one.

This is the error that shows every time I update the file:

No table was found with the name '{235AC59A-72C7-4A62-B137-00E0B394AB3E}'.
clientRequestId: xxx-xx-xxx-xxx-xxx
serviceRequestId: xxx-xx-xx-xxx-xxx

The table is named “Table 1” before the file is updated, after that, it is shown as below.

enter image description here

object oriented – Scalable architecture design for managing data flow in C++ using an Observer design pattern

What I need

I need a suitable and scalable solution to manage data flow between the classes in my C++ program.

Why I need it

Upon new feature requests, I’m continually adding new classes to the program. I initially registered callback functions to classes and injected a dependency to the class via an interface:

Callback Sequence

Now, as the program scales, this is becoming quite difficult to maintain and keep track of where and when my data is flowing between class instances.

My Proposed solution

I’ve now redesigned the system to use an Observer pattern. I have a central event hub (Observable) to which I can subscribe my various services (Observers) to:

UML Design

Note: I’ve also implemented this as an example on OneCompiler and the code is also available as a gist.

I can also pass the event hub to the classes if they will also need to push notifications.

The new data flow will now be:

New data flow Sequence

What I want to know

Before I embark on a refactoring mission I would like to know:

  • Is the observer pattern as I’ve implemented it in the example, a scalable solution to manage the data flow between my classes?
  • If not, what is a better alternative to ensure I can pass data between different sections of my program on an event-driven basis?

Thanks in advance for the help.

tensorflow – How to create and train a object counting CNN model using tensor flow and keras in Python

Hi I’m new to deep learning, machine learning stuff, and new to the python language.

I have the https://github.com/poppinace/mtc/blob/master/README.md dataset.

I need to make and train a (tassel) object counting DCNN model using this data set.

So far I have issues such as I can not load and feed the .mat file in this data set to the model as the first step. I believe the counting model looks like regression-based counting because the .mat files contain the location of the tassels.

Are there similar projects that I can refer, to develop the solution that I’m expecting?

What are the suggestions you can give to me?

power automate – How to design a flow which can control other independent flows without building child-parent relation

How can we in MS flow control the execution of other flows?
To be more specific:
How can we do the followings in a flow:

1 -Check the status of other flows? e,g, running, idle
2- If they are running, for how long they are running?
3- Turn the other flows on or off?
4-a bit greedy, but can we check the value of a variable in other flows if they are in a running state? (e.g. Can we check the variable 'var_a' of flow B which is in the running state while we are in flow A (no child-parent relation between these flows)?

graph theory – Necessary and sufficient condition for determining unique max flow

In the network flow problem, I’m trying to prove the following statement: $f’$ is an unique maximum flow if and only if the residual graph $G_{f’}$ is a directed acyclic graph.

For the forward direction, I will use contrapositive. If residual graph $G_{f’}$ has a cycle, then we can push flow along the cycle in $G_{f’}$, and augment the flow in the original graph $G$
Since sending flow or subtracting flow along cycle does not change the total flow of $f’$, so we have a different flow, say $f”$ with same flow value, which is $val(f’) =val(f”)$.

Conversely, suppose $f’$ and $f”$ are both max flow, then I want to prove the residual graph $ G_{f”}$ has a cycle. Consider $f’ -f”$ in $G_{f”}$, but I was wondering why $f’-f”$ will give a cycle in $G_{f”}$?

Can I get some help for the converse direction?

powershell – How to modify the same attribute of multiple lists with exact schemas in Sharepoint online through coding or ms flow

I have several lists with the same exact schemas in SharePoint Online. How can I do the following?

1- How to add/remove a column to/from all of them?

2- How to add/remove an option to a choice/multichoice column?

I think there should be a way to accomplish this in C#/Python or through Powershell. I prefer coding as it makes life much easier and faster. MS flow is fine.

Please let me know if it would be better to break this question into two seprate questions.

powershell – How to modify the same attribute of multiple lists with exact schema in Sharepoint online through coding or ms flow

I have several lists with the same exact schema in SharePoint Online. How can I do the following?

1- Add to add/remove a column to/from all of them?
2- How to add/remove an option to a choice/multichoice column?

I think there should be a way to accomplish this in C#/Python or through Powershell. I prefer coding as it makes life much easier and faster. MS flow is fine.

Please let me know if it would be better to break this question into two seprate questions.

sharepoint online – How to Identify and Terminate a Specific Approval Workflow from Another Flow

I’m creating an approval workflow using Power Automate for SharePoint Online.

I would like the workflow to be closed when the user presses the “Cancel” button in PowerApps while waiting for the first approver to approve.
In order to do this, I think I need to create another Flow that will work when the “Cancel” button is pressed.

Is there any way to find the workflow that is pending?
I would be very grateful for any idea/pointers.