Present second version with valid Spots output

master
Peter Babič 8 years ago
parent b613806eaa
commit 36494332a0
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 255
      .idea/workspace.xml
  2. 11
      index.php
  3. 110
      src/Coffee/Table.php
  4. 43
      src/Coffee/Tile.php
  5. 129
      tests/Coffee/TableTest.php
  6. 20
      tests/Coffee/TileTest.php

@ -4,10 +4,13 @@
<option name="ANALYZE_TEST_SOURCES" value="false" />
</component>
<component name="ChangeListManager">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Repair acidentaly refactored Position and PositionTest">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Present second version with valid Spots output">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Spot.php" afterPath="$PROJECT_DIR$/src/Coffee/Spot.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/SpotTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/SpotTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.php" afterPath="$PROJECT_DIR$/index.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Table.php" afterPath="$PROJECT_DIR$/src/Coffee/Table.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/TableTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/TableTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/TileTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
</list>
<ignored path="coffeetable.iws" />
<ignored path=".idea/workspace.xml" />
@ -36,21 +39,19 @@
<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.481482">
<caret line="21" column="39" selection-start-line="21" selection-start-column="39" selection-end-line="21" selection-end-column="39" />
<state vertical-scroll-proportion="-19.333334">
<caret line="29" column="0" selection-start-line="29" selection-start-column="0" selection-end-line="29" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Table.php" pinned="false" current-in-tab="false">
<file leaf-file-name="Table.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-64.888885">
<caret line="130" column="8" selection-start-line="130" selection-start-column="8" selection-end-line="130" selection-end-column="8" />
<folding>
<marker date="1458515533520" expanded="true" signature="534:1283" placeholder="..." />
</folding>
<state vertical-scroll-proportion="3.268595">
<caret line="119" column="0" selection-start-line="119" selection-start-column="0" selection-end-line="119" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
@ -58,18 +59,18 @@
<file leaf-file-name="TableTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="9.333333">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<state vertical-scroll-proportion="-12.666667">
<caret line="27" column="0" selection-start-line="27" selection-start-column="0" selection-end-line="27" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="true">
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.1550802">
<caret line="68" column="42" selection-start-line="68" selection-start-column="42" selection-end-line="68" selection-end-column="42" />
<state vertical-scroll-proportion="10.296296">
<caret line="20" column="6" selection-start-line="20" selection-start-column="6" selection-end-line="20" selection-end-column="6" />
<folding />
</state>
</provider>
@ -78,18 +79,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="-10.37037">
<caret line="109" column="42" selection-start-line="109" selection-start-column="42" selection-end-line="109" selection-end-column="42" />
<state vertical-scroll-proportion="-6.5925927">
<caret line="51" column="24" selection-start-line="51" selection-start-column="24" selection-end-line="51" selection-end-column="24" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<file leaf-file-name="Position.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.592592">
<caret line="54" column="49" selection-start-line="54" selection-start-column="49" selection-end-line="54" selection-end-column="49" />
<state vertical-scroll-proportion="-12.814815">
<caret line="190" column="19" selection-start-line="190" selection-start-column="19" selection-end-line="190" selection-end-column="19" />
<folding />
</state>
</provider>
@ -108,8 +109,18 @@
<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="-42.666668">
<caret line="70" column="5" selection-start-line="70" selection-start-column="5" selection-end-line="70" selection-end-column="5" />
<state vertical-scroll-proportion="34.185184">
<caret line="37" column="12" selection-start-line="37" selection-start-column="12" selection-end-line="37" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
</file>
<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="-12.962963">
<caret line="41" column="17" selection-start-line="41" selection-start-column="17" selection-end-line="41" selection-end-column="17" />
<folding />
</state>
</provider>
@ -155,22 +166,23 @@
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Spot.php" />
<option value="/usr/share/nginx/html/coffeetable/index.php" />
<option value="$PROJECT_DIR$/composer.json" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/Output.php" />
<option value="$PROJECT_DIR$/tests/Coffee/OutputTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Map.php" />
<option value="/usr/share/nginx/html/coffeetable/tests/Coffee/TableTest.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TableTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/MapTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/tests/Coffee/PositionTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Position.php" />
<option value="$PROJECT_DIR$/tests/Coffee/SpotTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TableTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="/usr/share/nginx/html/coffeetable/tests/Coffee/TileTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/src/Coffee/Table.php" />
</list>
</option>
</component>
@ -800,38 +812,44 @@
<option name="project" value="LOCAL" />
<updated>1458516167633</updated>
</task>
<option name="localTasksCounter" value="47" />
<task id="LOCAL-00047" summary="Implement Spot.setNumber">
<created>1458516661818</created>
<option name="number" value="00047" />
<option name="project" value="LOCAL" />
<updated>1458516661818</updated>
</task>
<option name="localTasksCounter" value="48" />
<servers />
</component>
<component name="TestHistory">
<history-entry file="Tests - 2016.03.21 at 00h 11m 51s.xml">
<history-entry file="Tests - 2016.03.21 at 00h 54m 14s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 12m 13s.xml">
<history-entry file="Tests - 2016.03.21 at 00h 54m 21s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 18m 37s.xml">
<history-entry file="Tests - 2016.03.21 at 00h 54m 50s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 20m 13s.xml">
<history-entry file="Tests - 2016.03.21 at 00h 57m 18s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 20m 28s.xml">
<history-entry file="Tests - 2016.03.21 at 00h 57m 40s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 21m 22s.xml">
<history-entry file="Tests - 2016.03.21 at 01h 07m 42s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 24m 29s.xml">
<history-entry file="Tests - 2016.03.21 at 01h 13m 27s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 24m 44s.xml">
<history-entry file="Tests - 2016.03.21 at 01h 13m 55s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 28m 36s.xml">
<history-entry file="Tests - 2016.03.21 at 01h 17m 37s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.21 at 00h 30m 36s.xml">
<history-entry file="Tests - 2016.03.21 at 01h 19m 31s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
@ -850,7 +868,7 @@
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17222223" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="TODO" 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="6" side_tool="false" content_ui="tabs" />
<window_info id="Messages" 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="7" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" 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="12" side_tool="true" content_ui="tabs" />
<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" />
@ -887,8 +905,6 @@
<component name="VcsManagerConfiguration">
<option name="CHECK_NEW_TODO" value="false" />
<option name="USE_COMMIT_MESSAGE_MARGIN" value="true" />
<MESSAGE value="Decouple Map, Position and Tile even more" />
<MESSAGE value="Change positioning system to start at [1, 1] not [0, 0]" />
<MESSAGE value="Implement Map.visitedTile as private Tile[]" />
<MESSAGE value="Normalize Position bounds for rows and columns" />
<MESSAGE value="Implement Map.getTileByPosition and do some refactoring" />
@ -912,7 +928,9 @@
<MESSAGE value="Modify Spot so it now contains Tiles instead of Positions" />
<MESSAGE value="Implement map.structuredTiles" />
<MESSAGE value="Repair acidentaly refactored Position and PositionTest" />
<option name="LAST_COMMIT_MESSAGE" value="Repair acidentaly refactored Position and PositionTest" />
<MESSAGE value="Implement Spot.setNumber" />
<MESSAGE value="Present second version with valid Spots output" />
<option name="LAST_COMMIT_MESSAGE" value="Present second version with valid Spots output" />
<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" />
@ -921,36 +939,24 @@
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="php">
<url>file://$PROJECT_DIR$/tests/Coffee/TableTest.php</url>
<line>19</line>
<option name="timeStamp" value="45" />
<url>file://$PROJECT_DIR$/src/Coffee/Tile.php</url>
<line>102</line>
<option name="timeStamp" value="47" />
</line-breakpoint>
<line-breakpoint enabled="true" type="php">
<url>file://$PROJECT_DIR$/index.php</url>
<line>22</line>
<option name="timeStamp" value="48" />
</line-breakpoint>
</breakpoints>
<breakpoints-dialog>
<breakpoints-dialog />
</breakpoints-dialog>
<option name="time" value="46" />
<option name="time" value="49" />
</breakpoint-manager>
<watches-manager>
<configuration name="PhpLocalRunConfigurationType">
<watch expression="$map-&gt;getUnVisitedTiles()" language="PHP" />
<watch expression="$map-&gt;getNeighboursOfTile($currentTile)" language="PHP" />
</configuration>
<configuration name="PHPUnitRunConfigurationType">
<watch expression="$map-&gt;getUnVisitedTiles()" language="PHP" />
<watch expression="$map-&gt;getNeighboursOfTile($currentTile)" language="PHP" />
</configuration>
</watches-manager>
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="72" column="20" selection-start-line="72" selection-start-column="20" selection-end-line="72" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
@ -987,9 +993,7 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="69" column="5" selection-start-line="69" selection-start-column="5" selection-end-line="69" selection-end-column="5" />
<folding>
<marker date="1458515533520" expanded="true" signature="534:1283" placeholder="..." />
</folding>
<folding />
</state>
</provider>
</entry>
@ -1012,9 +1016,7 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="69" column="5" selection-start-line="69" selection-start-column="5" selection-end-line="69" selection-end-column="5" />
<folding>
<marker date="1458515533520" expanded="true" signature="534:1283" placeholder="..." />
</folding>
<folding />
</state>
</provider>
</entry>
@ -1037,9 +1039,7 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="87" column="47" selection-start-line="87" selection-start-column="47" selection-end-line="87" selection-end-column="47" />
<folding>
<marker date="1458515533520" expanded="true" signature="534:1283" placeholder="..." />
</folding>
<folding />
</state>
</provider>
</entry>
@ -1185,21 +1185,6 @@
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7222222">
<caret line="102" column="26" selection-start-line="102" selection-start-column="26" selection-end-line="102" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-15.037037">
<caret line="43" column="55" selection-start-line="43" selection-start-column="55" selection-end-line="43" selection-end-column="55" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.35185185">
@ -1248,92 +1233,114 @@
</state>
</provider>
</entry>
<entry file="phar:///usr/share/webapps/bin/phpunit.phar/phpunit/Framework/TestCase.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.33333334">
<caret line="802" column="0" selection-start-line="802" selection-start-column="0" selection-end-line="802" selection-end-column="0" />
<state vertical-scroll-proportion="-14.592592">
<caret line="54" column="49" selection-start-line="54" selection-start-column="49" selection-end-line="54" selection-end-column="49" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/PositionTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-8.481482">
<caret line="21" column="39" selection-start-line="21" selection-start-column="39" selection-end-line="21" selection-end-column="39" />
<state vertical-scroll-proportion="0.19251336">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-64.888885">
<caret line="130" column="8" selection-start-line="130" selection-start-column="8" selection-end-line="130" selection-end-column="8" />
<folding>
<marker date="1458515533520" expanded="true" signature="534:1283" placeholder="..." />
</folding>
<state vertical-scroll-proportion="-15.814815">
<caret line="35" column="1" selection-start-line="35" selection-start-column="1" selection-end-line="35" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<entry file="phar:///usr/share/webapps/bin/phpunit.phar/phpunit/Framework/TestCase.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="9.333333">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<state vertical-scroll-proportion="0.22860962">
<caret line="990" column="0" selection-start-line="990" selection-start-column="0" selection-end-line="990" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<entry file="file:///usr/share/nginx/html/coffeetable/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.592592">
<caret line="54" column="49" selection-start-line="54" selection-start-column="49" selection-end-line="54" selection-end-column="49" />
<state vertical-scroll-proportion="0.18130842">
<caret line="23" column="20" selection-start-line="23" selection-start-column="20" selection-end-line="23" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/PositionTest.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.19251336">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<state vertical-scroll-proportion="-12.962963">
<caret line="41" column="17" selection-start-line="41" selection-start-column="17" selection-end-line="41" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-42.666668">
<caret line="70" column="5" selection-start-line="70" selection-start-column="5" selection-end-line="70" selection-end-column="5" />
<state vertical-scroll-proportion="-6.5925927">
<caret line="51" column="24" selection-start-line="51" selection-start-column="24" selection-end-line="51" selection-end-column="24" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7112299">
<state vertical-scroll-proportion="-12.814815">
<caret line="190" column="19" selection-start-line="190" selection-start-column="19" selection-end-line="190" selection-end-column="19" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-10.37037">
<caret line="109" column="42" selection-start-line="109" selection-start-column="42" selection-end-line="109" selection-end-column="42" />
<state vertical-scroll-proportion="34.185184">
<caret line="37" column="12" selection-start-line="37" selection-start-column="12" selection-end-line="37" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/SpotTest.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-15.814815">
<caret line="35" column="1" selection-start-line="35" selection-start-column="1" selection-end-line="35" selection-end-column="1" />
<state vertical-scroll-proportion="-12.666667">
<caret line="27" column="0" selection-start-line="27" selection-start-column="0" selection-end-line="27" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="2.4411216">
<caret line="134" column="0" selection-start-line="134" selection-start-column="0" selection-end-line="134" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.1550802">
<caret line="68" column="42" selection-start-line="68" selection-start-column="42" selection-end-line="68" selection-end-column="42" />
<state vertical-scroll-proportion="10.296296">
<caret line="20" column="6" selection-start-line="20" selection-start-column="6" selection-end-line="20" selection-end-column="6" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-19.333334">
<caret line="29" column="0" selection-start-line="29" selection-start-column="0" selection-end-line="29" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="3.268595">
<caret line="119" column="0" selection-start-line="119" selection-start-column="0" selection-end-line="119" selection-end-column="0" />
<folding />
</state>
</provider>

@ -14,16 +14,19 @@ try {
$table = new Table($map);
echo '<table>';
foreach ($table->getTiles() as $row) {
echo '<table>' . "\n";
foreach ($table->getStructuredTiles() as $row) {
echo '<tr>' . "\n";
/** @var Tile $tile */
foreach ($row as $tile) {
echo '<td>' . $tile->getSpotNumber() . '</td>' . "\n";
$formattedTile = $tile->getSpotNumber() == 0 ? '' : $tile->getSpotNumber();
echo '<td>' . $formattedTile . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>';
echo '</table>' . "\n";
// echo 'Najväčšia kávová kaluž je s číslom '.$table->getLargestSpot()->ge
}
catch (\Exception $e) {

@ -38,39 +38,15 @@ class Table extends Map {
parent::__construct($description);
// if (is_null($this->currentSpot)) {
// $tiles = $this->getTiles();
// }
// else {
// $tiles = $this->currentSpot->getQueuedTiles();
// }
//
// foreach ($tiles as $rowIndex => $row) {
// foreach ($row as $columnIndex => $tile) {
// /** @var Tile $tile */
// $tile->visit();
// if ($tile->isRepresentingSpot()) {
// foreach ($this->getNeighboursOfTile($tile) as $neighbourIndex => $neighbourTile) {
// $neighbourTile->visit();
//
// if ($tile->isRepresentingSpot()) {
//
// }
// }
// }
// }
//
// }
$this->expandSpotsRecursively();
}
// /**
// * @return Spot[]
// */
// public function getSpots() {
// return $this->spots;
// }
/**
* @return Spot[]
*/
public function getSpots() {
return $this->spots;
}
/**
* @return int
@ -86,31 +62,13 @@ class Table extends Map {
return $this->largestSpot;
}
// /**
// * @param Tile $searchedPosition
// * @return int|string
// */
// public function getSpotNumberByPosition(Tile $searchedPosition) {
// // Linear search
// // TODO: try to find a faster way
// foreach ($this->getSpots() as $spotIndex => $spot) {
// foreach ($spot->getTiles() as $position) {
// if ($searchedPosition->isTheSamePosition($position)) {
// return $spotIndex;
// }
// }
// }
//
// return '';
// }
/**
* @param Tile|null $tile
*/
protected function expandSpotsRecursively($tile = null) {
$tiles = $this->getTilePool($tile);
foreach ($tiles as $currentTile) {
// Either get Tiles from Map if root or from neighbours if called recursively with argument
foreach ($this->getTilePool($tile) as $currentTile) {
/** @var Tile $currentTile */
if (!$currentTile->isVisited()) {
@ -118,12 +76,14 @@ class Table extends Map {
if ($currentTile->isRepresentingSpot()) {
// Either form a new Spot or add current Tile to the existing one
$this->updateCurrentSpot($currentTile);
// TODO: Replace recursion by iteration
$this->expandSpotsRecursively($currentTile);
$this->addCurrentSpot(); // (to this table)
// No other neighbouring tiles were found
$this->finishCurrentSpot();
}
}
@ -131,10 +91,25 @@ class Table extends Map {
}
}
/**
* @param $tile
* @return Tile[]
*/
protected function getTilePool($tile = null) {
if (is_null($tile)) {
$tiles = $this->getTiles();
return $tiles;
}
else {
$tiles = $this->getNeighboursOfTile($tile);
return $tiles;
}
}
/**
* @param Tile $tile
*/
protected function updateCurrentSpot(Tile $tile) {
private function updateCurrentSpot(Tile $tile) {
if (is_null($this->currentSpot)) {
$this->currentSpot = new Spot($tile);
}
@ -143,40 +118,21 @@ class Table extends Map {
}
}
/**
* @return bool
*/
protected function addCurrentSpot() {
private function finishCurrentSpot() {
// Do the finishing process only on the started Spots
if (is_null($this->currentSpot)) {
return false;
return;
}
$this->updateLargestSpot();
// The Spots are numbered from 1
$this->currentSpot->setNumber($this->getSpotsCount() + 1);
$this->spots[] = $this->currentSpot;
$this->currentSpot = null;
return true;
}
/**
* @param $tile
* @return Tile[]
*/
protected function getTilePool($tile = null) {
if (is_null($tile)) {
$tiles = $this->getTiles();
return $tiles;
}
else {
$tiles = $this->getNeighboursOfTile($tile);
return $tiles;
}
}
/**
* Just a wrapper to have it neat and clean
*/
protected function updateLargestSpot() {
private function updateLargestSpot() {
if (is_null($this->largestSpot)) {
$this->largestSpot = $this->currentSpot;
}

@ -7,11 +7,6 @@ namespace Coffee;
*
* @package Coffee
*/
/**
* Class Tile
*
* @package Coffee
*/
class Tile extends Position {
/**
@ -23,15 +18,19 @@ class Tile extends Position {
* Default option
*/
const REPRESENTS_VOID = 0;
/**
* Tiles are inherently unvisited
*/
const DEFAULT_VISITED_STATE = false;
/**
* @var integer
*/
private $representation;
/**
* Tiles are inherently unvisited
* @var bool
*/
private $visited = false;
private $visited = self::DEFAULT_VISITED_STATE;
/**
* Zero means that the tile is not in the spot
* @var int
@ -41,19 +40,25 @@ class Tile extends Position {
/**
* Tile constructor.
*
* @param $row
* @param $column
* @param $tileRepresentation
* @param $row
* @param $column
* @param int $tileRepresentation
* @param bool $visited
* @throws \Exception
*/
public function __construct($row, $column, $tileRepresentation = self::REPRESENTS_VOID) {
public function __construct($row, $column, $tileRepresentation = self::REPRESENTS_VOID, $visited = self::DEFAULT_VISITED_STATE) {
if (!$this->isRepresentingSpot() && !$this->isRepresentingVoid()) {
throw new \Exception('The map contains invalid representations');
throw new \Exception('The map description contains invalid representations.');
}
if (!is_bool($visited)) {
throw new \Exception('The visited argument must be boolean.');
}
parent::__construct($row, $column);
$this->representation = $tileRepresentation;
$this->visited = $visited;
}
/**
@ -83,13 +88,13 @@ class Tile extends Position {
public function isRepresentingVoid() {
return $this->representation == self::REPRESENTS_VOID;
}
/**
* @return Tile
*/
public function getPosition() {
return new Tile($this->getRow(), $this->getColumn());
}
//
// /**
// * @return Tile
// */
// public function getPosition() {
// return new Tile($this->getRow(), $this->getColumn());
// }
/**
* @return int

@ -41,57 +41,61 @@ class TableTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(4, $table->getSpotsCount());
}
// public function testOneSmallSpot() {
// $table = new Table([
// [0, 1, 1],
// [0, 0, 0],
// [0, 0, 0],
// [0, 0, 0],
// ]);
//
// $spot = new Spot(new Tile(1, 2));
// $spot->addTile(new Tile(1, 3));
//
// $this->assertEquals([$spot], $table->getSpots());
// }
//
// public function testOneLargeSpot() {
// $table = new Table([
// [0, 1, 1],
// [0, 0, 1],
// [0, 1, 0],
// [1, 0, 0],
// ]);
//
// $spot = new Spot(new Tile(1, 2));
// $spot->addTile(new Tile(1, 3));
// $spot->addTile(new Tile(2, 3));
// $spot->addTile(new Tile(3, 2));
// $spot->addTile(new Tile(4, 1));
//
// $this->assertEquals([$spot], $table->getSpots());
// }
//
// public function testMultipleLargeSpots() {
// $table = new Table([
// [0, 1, 1, 0, 0],
// [0, 0, 1, 0, 1],
// [0, 1, 0, 0, 1],
// [1, 0, 0, 1, 0],
// ]);
//
// $spotA = new Spot(new Tile(1, 2));
// $spotA->addTile(new Tile(1, 3));
// $spotA->addTile(new Tile(2, 3));
// $spotA->addTile(new Tile(3, 2));
// $spotA->addTile(new Tile(4, 1));
//
// $spotB = new Spot(new Tile(2, 5));
// $spotB->addTile(new Tile(3, 5));
// $spotB->addTile(new Tile(4, 4));
//
// $this->assertEquals([$spotA, $spotB], $table->getSpots());
// }
public function testOneSmallSpot() {
$table = new Table([
[0, 1, 1],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
]);
$spot = new Spot($this->newVisitedTile(1, 2));
$spot->addTile($this->newVisitedTile(1, 3));
$spot->setNumber(1);
$this->assertEquals([$spot], $table->getSpots());
}
public function testOneLargeSpot() {
$table = new Table([
[0, 1, 1],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
]);
$spot = new Spot($this->newVisitedTile(1, 2));
$spot->addTile($this->newVisitedTile(1, 3));
$spot->addTile($this->newVisitedTile(2, 3));
$spot->addTile($this->newVisitedTile(3, 2));
$spot->addTile($this->newVisitedTile(4, 1));
$spot->setNumber(1);
$this->assertEquals([$spot], $table->getSpots());
}
public function testMultipleLargeSpots() {
$table = new Table([
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 1],
[0, 1, 0, 0, 1],
[1, 0, 0, 1, 0],
]);
$spotA = new Spot($this->newVisitedTile(1, 2));
$spotA->addTile($this->newVisitedTile(1, 3));
$spotA->addTile($this->newVisitedTile(2, 3));
$spotA->addTile($this->newVisitedTile(3, 2));
$spotA->addTile($this->newVisitedTile(4, 1));
$spotA->setNumber(1);
$spotB = new Spot($this->newVisitedTile(2, 5));
$spotB->addTile($this->newVisitedTile(3, 5));
$spotB->addTile($this->newVisitedTile(4, 4));
$spotB->setNumber(2);
$this->assertEquals([$spotA, $spotB], $table->getSpots());
}
public function testLargestSpotSize() {
$table = new Table([
@ -104,16 +108,15 @@ class TableTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(6, $table->getLargestSpot()->getSize());
}
// public function testSpotNumberByPosition() {
// $table = new Table([
// [0, 1, 1, 0, 0],
// [1, 1, 1, 0, 1],
// [0, 0, 1, 0, 1],
// [1, 0, 0, 0, 0],
// ]);
//
// $position = new Tile(4, 1);
//
// $this->assertEquals(2, $table->getSpotNumberByPosition($position));
// }
/**
* Wrapper for a visited tile to reduce repetition. This logic does not fit into the Spot class.
*
* @param $row
* @param $column
* @return Tile
*/
protected function newVisitedTile($row, $column) {
return new Tile($row, $column, Tile::REPRESENTS_SPOT, true);
}
}

@ -19,16 +19,16 @@ class TileTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($tile->isRepresentingVoid());
}
public function testGetPosition() {
$row = 2;
$column = 2;
$tile = new Tile($row, $column, Tile::REPRESENTS_VOID);
$position = new Tile($row, $column);
$this->assertEquals($position, $tile->getPosition());
}
// public function testGetPosition() {
// $row = 2;
// $column = 2;
//
// $tile = new Tile($row, $column, Tile::REPRESENTS_VOID);
// $position = new Tile($row, $column);
//
// $this->assertEquals($position, $tile->getPosition());
//
// }
public function testIsVisited() {
$tile = new Tile(2, 2, Tile::REPRESENTS_SPOT);

Loading…
Cancel
Save