Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create strategies for the robot #1

Open
6 tasks
santiHerranz opened this issue Oct 7, 2021 · 0 comments
Open
6 tasks

Create strategies for the robot #1

santiHerranz opened this issue Oct 7, 2021 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@santiHerranz
Copy link
Owner

Inputs are:

  • Player position
  • Player speed
  • Player vision layers: Opponent players, Dojo boundaries
  • 30 raycast from the player: from -60º to +60º

Outputs will be:

  • Speed
  • Turning angle

Strategies to implement

  • Face
  • Attack
  • Defense
  • Evade
  • Push
  • Other

Strategy exemple

Strategy.attackDrive = function (player, strategy = {
        name: "ATTACK",
        deltaSpeed: 10 + (Math.random() - 0.5),
        deltaTurn: .8,
        defaultTurn: 20
    }) {
    let speed = 0, turn = 0;
    let maxSpeed = 100;
    let playerLayer = player.visionLayer[VISION_LAYER.PLAYER];

    for (let ray of playerLayer) {
        if (ray.point != null) {
            if (ray.distance < dojo.radius * 2) {
                speed += strategy.deltaSpeed;
                let middle = playerLayer.length / 2;    // Middle of rays beams
                let deltaTurn = Math.abs(playerLayer.length / 2 - ray.index); // Right or left ?
                if (ray.index < middle)
                    turn += -Math.PI / 180 * deltaTurn * strategy.deltaTurn;
                if (ray.index > middle)
                    turn += Math.PI / 180 * deltaTurn * strategy.deltaTurn;
            }
        }
    }

    if (speed > maxSpeed) speed = maxSpeed;

    if (speed == 0 && turn == 0) 
        turn = Math.PI / 180 * strategy.defaultTurn;

    player.name = strategy.name;
    return { speed: speed, turn: turn };
}
@santiHerranz santiHerranz added good first issue Good for newcomers help wanted Extra attention is needed labels Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant