-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.php
90 lines (76 loc) · 2.42 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
require_once 'src/Arena.php';
require_once 'src/Map.php';
require_once 'src/Pac.php';
require_once 'src/Pos.php';
require_once 'src/Node.php';
require_once 'src/PositionCollection.php';
require_once 'src/Commands/AbstractCommand.php';
require_once 'src/Commands/MoveCommand.php';
require_once 'src/Commands/SpeedBoostCommand.php';
require_once 'src/Commands/SwitchCommand.php';
require_once 'src/Strategies/AbstractStrategy.php';
require_once 'src/Strategies/ActivateBoostStrategy.php';
require_once 'src/Strategies/AvoidCollisionStrategy.php';
require_once 'src/Strategies/CalculateOptimalRouteStrategy.php';
require_once 'src/Strategies/ChaseStrategy.php';
require_once 'src/Strategies/MoveToClosestPelletStrategy.php';
require_once 'src/Strategies/MoveToSuperPelletsStrategy.php';
require_once 'src/Strategies/RunStrategy.php';
$context = fopen('inputs/input.txt', 'rb');
define('DEBUG', false);
define('DEBUG_VERBOSE', false);
fscanf($context, "%d %d", $width, $height);
$mapData = [];
for ($i = 0; $i < $height; $i++) {
$mapData[] = stream_get_line($context, $width + 1, "\n");
}
$map = new Map($width, $height, $mapData);
$arena = new Arena($map);
while (TRUE) {
fscanf($context, "%d %d", $myScore, $opponentScore);
readPacsData($context, $arena);
readPelletData($context, $arena);
if (DEBUG) {
l((string)$map);
}
echo implode('|', $arena->execute()) . PHP_EOL;
$arena->reset();
}
/**
* @param $context
* @param Arena $arena
*/
function readPacsData($context, Arena $arena): void
{
fscanf($context, "%d", $visiblePacCount);
for ($i = 0; $i < $visiblePacCount; $i++) {
fscanf($context, "%d %d %d %d %s %d %d", $pacId, $mine, $x, $y, $typeId, $speedTurnsLeft, $abilityCooldown);
if (strtolower($typeId) === Pac::TYPE_DEAD) {
continue;
}
$arena->updatePac($pacId, (bool)$mine, new Pos($x, $y), $typeId, $speedTurnsLeft, $abilityCooldown);
}
$arena->resetPacVision();
}
/**
* @param $context
* @param Arena $arena
*/
function readPelletData($context, Arena $arena): void
{
fscanf($context, "%d", $visiblePelletCount);
for ($i = 0; $i < $visiblePelletCount; $i++) {
fscanf($context, "%d %d %d", $x, $y, $value);
$arena->addPellet(new Pos($x, $y), $value);
}
}
/**
* Log values in the coding game console
* @param mixed $var
*/
function l($var): void
{
error_log(var_export($var, true));
}