Git Product home page Git Product logo

Comments (7)

magwo avatar magwo commented on September 1, 2024

Nice find, pretty serious bug. Will take a look.

from elevatorsaga.

magwo avatar magwo commented on September 1, 2024

It's kind of sporadic, but I managed to make a test that consistently fails.
https://github.com/magwo/elevatorsaga/blob/floorpassing/test/tests.js#L302

It seems that if you overshoot some certain "magic" amount or something, the bug manifests.

The code that generates the passing_floor events is not very clean. I'd like to make it more simple and obviously correct.

The reason it is complicated, I think, is because sometimes elevators overshoot slightly when stopping at a floor, causing it to pass the floor and then go back down. This is a tiny amount and that should not trigger the passing_floor event again, which complicates the code.

from elevatorsaga.

magwo avatar magwo commented on September 1, 2024

Might have to completely rewrite the code that generates these events.

from elevatorsaga.

magwo avatar magwo commented on September 1, 2024

Now rewritten and kind of fixed. You can still sometimes get multiple events for the same floor when stopping very close to the floor, due to slightly bouncy control system. But all the events should be expected and arguably correct.

from elevatorsaga.

mgiuffrida avatar mgiuffrida commented on September 1, 2024

I'm still seeing this behavior and it does not seem correct. When the elevator is moving from floor 2 to floor 0, on the first "passing_floor" (1) event I direct it to goToFloor(1). This results in several new "passing_floor" (0) events.

Floor 1 has not yet been passed, and floor 0 is not being passed (it is scheduled to be visited after the visit to floor 1).

I should add, the number of redundant passing_floor events is dependent on the timescale. At 1x, there are about 20 extraneous passing_floor(0) events. At 2x, there are about 9 events; at 55x there are 1 or 2.

from elevatorsaga.

magwo avatar magwo commented on September 1, 2024

You are correct. Will investigate.

from elevatorsaga.

magwo avatar magwo commented on September 1, 2024

Code to reproduce:

{
    init: function(elevators, floors) {
        var elevator = elevators[0]; // Let's use the first elevator

        // Whenever the elevator is idle (has no more queued destinations) ...
        elevator.on("idle", function() {
            // let's go to all the floors (or did we forget one?)
            elevator.goToFloor(2);
            elevator.goToFloor(0);
        });

        elevator.on("passing_floor", function(floorNum, direction) {
            console.log("passing floor", floorNum, direction);

            if(floorNum === 1 && direction === "down") {
                elevator.stop();
                elevator.goToFloor(1);
            }
        });
    },
        update: function(dt, elevators, floors) {
            // We normally don't need to do anything here
        }
}

from elevatorsaga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.