Implement Map.getNeighboursOfTile

master
Peter Babič 8 years ago
parent 84c8dd2ef7
commit fc82f617e9
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 103
      .idea/workspace.xml
  2. 13
      index.php
  3. 8
      src/Coffee/Map.php
  4. 29
      tests/Coffee/MapTest.php

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Refactor Map.getTiles and Map.getUn">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Refactor Map.getTiles and Map.getUnvisitedTiles">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.php" afterPath="$PROJECT_DIR$/index.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Map.php" afterPath="$PROJECT_DIR$/src/Coffee/Map.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Tile.php" afterPath="$PROJECT_DIR$/src/Coffee/Tile.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/MapTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/MapTest.php" />
</list>
<ignored path="coffeetable.iws" />
@ -34,8 +34,8 @@
<file leaf-file-name="index.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-8.666667">
<caret line="13" column="2" selection-start-line="13" selection-start-column="2" selection-end-line="13" selection-end-column="2" />
<state vertical-scroll-proportion="-12.0">
<caret line="18" column="2" selection-start-line="18" selection-start-column="2" selection-end-line="18" selection-end-column="2" />
<folding />
</state>
</provider>
@ -61,11 +61,11 @@
</provider>
</entry>
</file>
<file leaf-file-name="Position.php" pinned="false" current-in-tab="false">
<file leaf-file-name="Position.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="155" column="44" selection-start-line="155" selection-start-column="44" selection-end-line="155" selection-end-column="44" />
<state vertical-scroll-proportion="0.33214286">
<caret line="175" column="23" selection-start-line="175" selection-start-column="23" selection-end-line="175" selection-end-column="23" />
<folding />
</state>
</provider>
@ -84,18 +84,18 @@
<file leaf-file-name="Map.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-27.037037">
<caret line="97" column="5" selection-start-line="97" selection-start-column="5" selection-end-line="97" selection-end-column="5" />
<state vertical-scroll-proportion="-10.37037">
<caret line="114" column="38" selection-start-line="114" selection-start-column="38" selection-end-line="114" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="true">
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7459893">
<caret line="31" column="69" selection-start-line="31" selection-start-column="69" selection-end-line="31" selection-end-column="69" />
<state vertical-scroll-proportion="-12.666667">
<caret line="100" column="50" selection-start-line="100" selection-start-column="50" selection-end-line="100" selection-end-column="50" />
<folding />
</state>
</provider>
@ -114,7 +114,7 @@
<file leaf-file-name="Tile.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="8.777778">
<state vertical-scroll-proportion="22.592592">
<caret line="30" column="0" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
<folding />
</state>
@ -124,8 +124,8 @@
<file leaf-file-name="TileTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-22.37037">
<caret line="36" column="44" selection-start-line="36" selection-start-column="44" selection-end-line="36" selection-end-column="44" />
<state vertical-scroll-proportion="-16.074074">
<caret line="38" column="0" selection-start-line="38" selection-start-column="0" selection-end-line="38" selection-end-column="0" />
<folding />
</state>
</provider>
@ -176,11 +176,11 @@
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/tests/Coffee/PositionTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Position.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/tests/Coffee/MapTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
</list>
</option>
</component>
@ -683,38 +683,44 @@
<option name="project" value="LOCAL" />
<updated>1458247367801</updated>
</task>
<option name="localTasksCounter" value="26" />
<task id="LOCAL-00026" summary="Refactor Map.getTiles and Map.getUnvisitedTiles">
<created>1458249166277</created>
<option name="number" value="00026" />
<option name="project" value="LOCAL" />
<updated>1458249166277</updated>
</task>
<option name="localTasksCounter" value="27" />
<servers />
</component>
<component name="TestHistory">
<history-entry file="Tests - 2016.03.17 at 21h 52m 22s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 08m 10s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 21h 53m 08s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 08m 54s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 21h 53m 58s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 24m 26s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 21h 54m 27s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 31m 45s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 21h 57m 44s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 33m 59s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 21h 57m 54s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 34m 05s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 22h 03m 41s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 40m 31s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 22h 07m 50s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 44m 16s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 22h 08m 10s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 45m 27s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 22h 08m 54s.xml">
<history-entry file="Tests - 2016.03.17 at 22h 45m 31s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
@ -729,7 +735,7 @@
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.23441397" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" x="0" y="355" width="1446" height="188" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.23441397" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" x="0" y="355" width="1446" height="188" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24964234" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
@ -782,7 +788,8 @@
<MESSAGE value="Implement Map.getTileByPosition and do some refactoring" />
<MESSAGE value="Implement Tile.representsVoid" />
<MESSAGE value="Implement Tile.isVisited" />
<option name="LAST_COMMIT_MESSAGE" value="Implement Tile.isVisited" />
<MESSAGE value="Refactor Map.getTiles and Map.getUnvisitedTiles" />
<option name="LAST_COMMIT_MESSAGE" value="Refactor Map.getTiles and Map.getUnvisitedTiles" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REARRANGE_BEFORE_PROJECT_COMMIT" value="true" />
@ -1136,50 +1143,50 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="155" column="44" selection-start-line="155" selection-start-column="44" selection-end-line="155" selection-end-column="44" />
<state vertical-scroll-proportion="-12.0">
<caret line="18" column="2" selection-start-line="18" selection-start-column="2" selection-end-line="18" selection-end-column="2" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-22.37037">
<caret line="36" column="44" selection-start-line="36" selection-start-column="44" selection-end-line="36" selection-end-column="44" />
<state vertical-scroll-proportion="22.592592">
<caret line="30" column="0" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="8.777778">
<caret line="30" column="0" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
<state vertical-scroll-proportion="-16.074074">
<caret line="38" column="0" selection-start-line="38" selection-start-column="0" selection-end-line="38" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-27.037037">
<caret line="97" column="5" selection-start-line="97" selection-start-column="5" selection-end-line="97" selection-end-column="5" />
<state vertical-scroll-proportion="-12.666667">
<caret line="100" column="50" selection-start-line="100" selection-start-column="50" selection-end-line="100" selection-end-column="50" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-8.666667">
<caret line="13" column="2" selection-start-line="13" selection-start-column="2" selection-end-line="13" selection-end-column="2" />
<state vertical-scroll-proportion="-10.37037">
<caret line="114" column="38" selection-start-line="114" selection-start-column="38" selection-end-line="114" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7459893">
<caret line="31" column="69" selection-start-line="31" selection-start-column="69" selection-end-line="31" selection-end-column="69" />
<state vertical-scroll-proportion="0.33214286">
<caret line="175" column="23" selection-start-line="175" selection-start-column="23" selection-end-line="175" selection-end-column="23" />
<folding />
</state>
</provider>

@ -14,11 +14,14 @@ try {
//
// $table = new Table();
//
// foreach ($map->getUnVisitedTiles() as $unVisitedTile) {
//// $map->vi
// foreach ($unVisitedTile->getNeighbouringPositions() as $neighbouringPosition) {
// $tile = $map->getTileByPosition($neighbouringPosition);
//// if
// foreach ($map->getUnVisitedTiles() as $currentTile) {
// $currentTile->visit();
//
// if ($currentTile->isRepresentingSpot()) {
// foreach ($currentTile->getNeighbouringPositions() as $neighbouringPosition) {
// $neighbouringTile = $map->getTileByPosition($neighbouringPosition);
// $neighbouringTile->visit();
// }
// }
// }
}

@ -110,6 +110,14 @@ class Map {
return $array;
}
public function getNeighboursOfTile(Tile $tile) {
$neighbouringTiles = [];
foreach ($tile->getNeighbouringPositions() as $neighbouringPosition) {
$neighbouringTiles[] = $this->getTileByPosition($neighbouringPosition);
}
return array_values(array_filter($neighbouringTiles));
}
/**
* @return int
*/

@ -72,18 +72,39 @@ class MapTest extends \PHPUnit_Framework_TestCase {
}
public function testWidth() {
// Even the non-rectangular map descriptions are possible
$description = [
[0, 1, 0],
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0,],
[0, 0, 0]
[0, 0, 0, 1],
[0, 0, 0, 1]
];
$map = new Map($description);
$this->assertEquals(4, $map->getWidth());
}
public function testNeighboursOfTile() {
$description = [
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 1]
];
$map = new Map($description);
$position = new Position(4, 4);
$tile = $map->getTileByPosition($position);
$neighbours = [
new Tile(4, 3, Tile::REPRESENTS_VOID),
new Tile(3, 3, Tile::REPRESENTS_VOID),
new Tile(3, 4, Tile::REPRESENTS_SPOT),
];
$this->assertEquals($neighbours, $map->getNeighboursOfTile($tile));
}
// public function testValidPosition() {
// $description = [
// [0, 1, 0, 1],

Loading…
Cancel
Save