hquxmu / ai-contest

Automatically exported from code.google.com/p/ai-contest
0 stars 0 forks source link

Add PHP support #104

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
PHP starter package is attached.

The only requrement is php5-cli package.

Bot can be run using commands "php MyBot.php" or "/usr/bin/php MyBot.php".

Original issue reported on code.google.com by naktibalda@gmail.com on 10 Sep 2010 at 10:27

Attachments:

GoogleCodeExporter commented 9 years ago
I have been using this and would like to submit my bot as MyBot.php.
I found one small bug in the starter package though. In PlanetWars.php the 
return line of distance reads:

return int(ceil(sqrt($dx * $dx + $dy * $dy)));

When it should read:

return (int)(ceil(sqrt($dx * $dx + $dy * $dy)));

or

return intval(ceil(sqrt($dx * $dx + $dy * $dy)));

since int is not a function.

Original comment by patm%lia...@gtempaccount.com on 11 Sep 2010 at 5:40

GoogleCodeExporter commented 9 years ago
There was another bug,
I used (int) cast for planet coordinates, because I made a wrong assumption 
that it must be an integer.

Original comment by naktibalda@gmail.com on 11 Sep 2010 at 5:16

Attachments:

GoogleCodeExporter commented 9 years ago
I've done some improvements to the code to make it clearer.

Additionally reviewed/rechecked/refactored/fixed/tested and commented as in the 
start package for java. 

I think it can be used AS IS and I hope it's now possible to make it work in 
production.

Original comment by lcfsoft on 17 Sep 2010 at 1:09

Attachments:

GoogleCodeExporter commented 9 years ago
These lines must be added to compile_anything.py

  if language == "Php":
    print "Php scripts need not be compiled"
    for script in safeglob('*.php'):
      os.chmod(script, 0644)
    check_path('MyBot.php')

SQL statement to create entry in languages table:
INSERT INTO languages (`name`, `main_code_file`, `command`) 
VALUES('Php','MyBot.php','php MyBot.php')

Original comment by naktibalda@gmail.com on 17 Sep 2010 at 4:16

GoogleCodeExporter commented 9 years ago
Live on the server.

Original comment by danie...@gmail.com on 17 Sep 2010 at 5:00

GoogleCodeExporter commented 9 years ago
Method distance of  PlanetWars class has a bug 

its fixed 

public function distance($sourcePlanet, $destinationPlanet)
    {
        if (!$sourcePlanet instanceof Planet) {
            $sourcePlanet = $this->getPlanet($sourcePlanet);
        }
        if (!$destinationPlanet instanceof Planet) {
            $destinationPlanet = $this->getPlanet($destinationPlanet);
        }

        $diffX = $sourcePlanet->getX() - $destinationPlanet->getX();
        $diffY = $sourcePlanet->getY() - $destinationPlanet->getY();

        return ceil(sqrt($diffX * $diffX + $diffY * $diffY));
    }

Original comment by arash....@gmail.com on 7 Nov 2010 at 1:20