Reputation: 6316
I don't understand this code can you explain me
grid
is an int[][]
distbest
is initialized
double distbest
int turn = 60;
if (g > 1)
this.grid = turn(distbest * turn).grid;
else
this.grid = turn(-distbest * turn).grid;
Upvotes: 2
Views: 223
Reputation: 89209
This section:
turn(distbest * turn)
means that there's a function turn
that returns an object that contains grid
that takes a double as a parameter. What's not shown in the code is the return type.
Hence, what I can say, is that the function is declared something like
Grid turn(double d);
where Grid
(ficticious) has a public
attribute of int[][] grid
(that's why turn(distbest * turn).grid
is possible).
I'm basing all this from the sample code listed above. The other turn
is a parameter.
Upvotes: 0
Reputation: 162849
In addition to the turn
variable which is an int
type, there must also be a int[][] turn(double)
method which is not shown. It's generally considered bad practice to name methods the same as variables because it causes exactly the type of confusion you're experiencing. If possible, considerer renaming either the variable or the method.
Upvotes: 1
Reputation: 346536
The code is pretty straightforward, so what about it do you not understand?
Perhaps what's confusing you is the double use of turn
as both a variable name and a method name - turn(distbest * turn)
is a method call, and the grid
field of the returned object is the assigned to this.grid
.
Upvotes: 3