I personally have a few issues with this library. I know the library used in the contest will be different, I hope it has a major speed up. This library is very slow, and written fairly poorly as far as speed goes, and considering that's a factor I am displeased.
I know that the startup wont penalize us, but the move function could be faster. For example, WHY in the world would it loop through all the robots multiple times? It's much faster to store the x,y coordinates as the key of the robots array, and then do simple isset()s on an array in ONE foreach, rather than having to loop multiple times. Especially why in the world would it report the closest robot when it doesn't even make that information available to the program, but just to output it?
The use of double quotes all over the place slows it down. As does using for loops rather than a while loop
php Code:
Original
- php Code |
|
|
|
$i=-1;
while (++$i<$num)
{
// insert code
}
is much faster than:
php Code:
Original
- php Code |
|
|
|
for($i=0; $i<count($array); $i++)
{
// insert code
}
For multiple reasons, checking against a variable is much faster than running a function and checking against its returned value each loop. Preincrimenting is also faster than postincrimenting.
Also, count variables are made, but aren't even used in other places where they could be, and aren't made available.
Example:
php Code:
Original
- php Code |
|
|
|
A robot count is made, but not used where it could be, such as in the output right after that. In addition, it's not made available in the game array, so we can not use that information, and have to waste more time using a count, that can get costly with arrays of 10k units (which that limit is rediculous. I've had start times of 50 seconds by itself, even if move doesnt do all of what start does, thats probably only 20 seconds or so less... 30 seconds a move? Rediculous.)
Also, why use second variables? We have a memory limit, why create secondary variables ($height,$width) rather than using the variable itself, saving memory ($this->game['height']).
I really think the library should be reevaluated (possibly recoded), and redistributed and then a version of that be used for the competition. It's way too slow. Besides, as has been stated, there's an error with the distance formula in some cases anyways.