SimoneCallegarin / ingsw2022-AM07

Progetto di Ingegneria del Software 2021/2022
2 stars 0 forks source link

typos in for? #11

Closed ingconti closed 2 years ago

ingconti commented 2 years ago
      for (int i = 0; i < numberOfPlayers; i++) {
            for (int j = 0; j < maxMovableStudents; j++) {
                **gameTable.getCloud(i).addStudent(gameTable.getBag().draw());**
            }
        }

as I read, inner call uses I soo it is INVARIANT RESPECT J.

Pull I out of loop OR index s wrong!

and pls add explanation

of course no test about it... otherwise You will have caught this.. I presume.

giacomo-carugati commented 2 years ago

In this piece of code we want to add a maximum of 3 or 4 students (maxMovableStudents) on each cloud. Variable j controls how many students has been added to a specific cloud so far; variable i controls which cloud we are referring to in a specific moment. When the boolean expression in the inner for is false it means that the i-th cloud has been filled with students, so we can skip to the next one. Maybe it is not the most elegant and correct way to do it, so we can try to improve it, but we have done two tests up until now (Model > GamePhases > PlanningPhase.java > fillClouds2Players() and fillClouds3Players() ) and the method seems to work. We will provide an explanation in the code as soon as possible.

ingconti commented 2 years ago

so loop add N times ?

a) rewrite it for example:

for (int i = 0; i < numberOfPlayers; i++) { var cloud = gameTable.getCloud(i); for (int j = 0; j < maxMovableStudents; j++) { cloud.addStudent(gameTable.getBag().draw()); } }

and the same for gameTable.getBag().draw())....

you invoke 3 constant methods in a doubler loop..

or B) better:

write emtohod that adds a Number of times

SimoneCallegarin commented 2 years ago

We corrected as you suggested using the first tip.