diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 0000000..820375f
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 9d4c15c..ed0f4e0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,11 +2,12 @@
-
-
-
-
+
+
+
+
+
@@ -35,8 +36,8 @@
-
-
+
+
@@ -45,8 +46,8 @@
-
-
+
+
@@ -55,38 +56,28 @@
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -95,8 +86,8 @@
-
-
+
+
@@ -132,13 +123,13 @@
-
+
+
+
-
-
-
+
@@ -188,12 +179,81 @@
+
+ Assignment issuesJavaScript
+
+
+ Bitwise operation issuesJavaScript
+
+
+ Code StylePHP
+
+
+ Code quality toolsJavaScript
+
+
+ Code style issuesJavaScript
+
+
+ CoffeeScript
+
+
+ Control flow issuesJavaScript
+
+
+ Data flow issuesJavaScript
+
+
+ Error handlingJavaScript
+
+
+ General
+
+
+ GeneralJavaScript
+
+
+ GeneralPHP
+
+
+ JavaScript
+
+
+ JavaScript function metricsJavaScript
+
+
+ JavaScript validity issuesJavaScript
+
PHP
+
+ PHPDocPHP
+
+
+ Potentially confusing code constructsJavaScript
+
+
+ Probable bugsCoffeeScript
+
+
+ Probable bugsJavaScript
+
+
+ Probable bugsPHP
+
+
+ Spelling
+
UndefinedPHP
+
+ XML
+
+
+ XPath
+
@@ -228,6 +288,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -280,21 +355,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -302,8 +362,8 @@
-
-
+
+
@@ -384,37 +444,44 @@
1458074387240
+
+ 1458136416618
+
+
+ 1458136416618
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -424,23 +491,23 @@
-
-
+
-
+
+
+
-
@@ -468,6 +535,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -730,65 +853,65 @@
-
+
-
-
+
-
+
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
diff --git a/src/Coffee/Table.php b/src/Coffee/Table.php
index d3002f4..e509178 100644
--- a/src/Coffee/Table.php
+++ b/src/Coffee/Table.php
@@ -20,7 +20,7 @@ class Table {
/**
* @var array
*/
- private $remainingTiles = [];
+ private $remainingPositions = [];
/**
* @var int
@@ -31,6 +31,10 @@ class Table {
* @var int
*/
private $width = 0;
+ /**
+ * @var Spot[]
+ */
+ private $spots = [];
/**
* Table constructor.
@@ -45,7 +49,14 @@ class Table {
$this->height = $this->calculateMapHeight($coffeeMap);
$this->width = $this->calculateMapWidth($coffeeMap);
- $this->remainingTiles = $coffeeMap;
+ $this->remainingPositions = $coffeeMap;
+
+// foreach ($this->remainingPositions as $rowIndex => $tableRow) {
+// foreach ($tableRow as $columnIndex => $containsCoffee) {
+// if ($containsCoffee)
+// $tile = new Tile($columnIndex, $rowIndex);
+// }
+// }
}
/**
@@ -65,8 +76,8 @@ class Table {
/**
* @return array
*/
- public function getRemainingTiles() {
- return $this->remainingTiles;
+ public function getRemainingPositions() {
+ return $this->remainingPositions;
}
/**
@@ -100,15 +111,42 @@ class Table {
* @return bool
*/
public function isValidForTile(Tile $tile) {
- if ($tile->getX() < 0 || $tile->getY() < 0) {
+ if ($tile->getColumn() < 0 || $tile->getRow() < 0) {
return false;
}
// Dimensions start from 1 but coordinates from 0, need to compensate
- if ($tile->getX() > ($this->getWidth() - 1) || $tile->getY() > ($this->getHeight() - 1)) {
+ if ($tile->getColumn() > ($this->getWidth() - 1) || $tile->getRow() > ($this->getHeight() - 1)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @param Spot $spot
+ * @return bool
+ */
+ public function addSpot(Spot $spot) {
+ if (is_null($spot)) {
return false;
}
+ $this->spots[] = $spot;
return true;
}
+
+ /**
+ * @return Spot[]
+ */
+ public function getSpots() {
+ return $this->spots;
+ }
+
+ /**
+ * @return int
+ */
+ public function getSpotsCount() {
+ return count($this->spots);
+ }
}
\ No newline at end of file
diff --git a/src/Coffee/Tile.php b/src/Coffee/Tile.php
index ebf03e0..70b1a1a 100644
--- a/src/Coffee/Tile.php
+++ b/src/Coffee/Tile.php
@@ -12,49 +12,49 @@ class Tile {
/**
* @var int
*/
- private $X = 0;
+ private $column = 0;
/**
* @var int
*/
- private $Y = 0;
+ private $row = 0;
/**
- * @param $X
- * @param $Y
+ * @param $column
+ * @param $row
*/
- function __construct($X, $Y) {
- $this->X = $X;
- $this->Y = $Y;
+ function __construct($column, $row) {
+ $this->column = $column;
+ $this->row = $row;
}
/**
* @return int
*/
- public function getX() {
- return $this->X;
+ public function getColumn() {
+ return $this->column;
}
/**
* @return int
*/
- public function getY() {
- return $this->Y;
+ public function getRow() {
+ return $this->row;
}
/**
* @param Tile $tile
* @return bool
*/
- public function isTheSameX(Tile $tile) {
- return $this->getX() == $tile->getX();
+ public function isTheSameColumn(Tile $tile) {
+ return $this->getColumn() == $tile->getColumn();
}
/**
* @param Tile $tile
* @return bool
*/
- public function isTheSameY(Tile $tile) {
- return $this->getY() == $tile->getY();
+ public function isTheSameRow(Tile $tile) {
+ return $this->getRow() == $tile->getRow();
}
/**
@@ -62,180 +62,63 @@ class Tile {
* @return bool
*/
public function isTheSameTile(Tile $tile) {
- return $this->isTheSameX($tile) && $this->isTheSameY($tile);
+ return $this->isTheSameColumn($tile) && $this->isTheSameRow($tile);
}
/**
* @return Tile
*/
public function getNorthEastTile() {
- return new Tile($this->getX() + 1, $this->getY() - 1);
+ return new Tile($this->getColumn() + 1, $this->getRow() - 1);
}
/**
* @return Tile
*/
public function getEastTile() {
- return new Tile($this->getX() + 1, $this->getY());
+ return new Tile($this->getColumn() + 1, $this->getRow());
}
/**
* @return Tile
*/
public function getSouthEastTile() {
- return new Tile($this->getX() + 1, $this->getY() + 1);
+ return new Tile($this->getColumn() + 1, $this->getRow() + 1);
}
/**
* @return Tile
*/
public function getSouthTile() {
- return new Tile($this->getX(), $this->getY() + 1);
+ return new Tile($this->getColumn(), $this->getRow() + 1);
}
/**
* @return Tile
*/
public function getSouthWestTile() {
- return new Tile($this->getX() - 1, $this->getY() + 1);
+ return new Tile($this->getColumn() - 1, $this->getRow() + 1);
}
/**
* @return Tile
*/
public function getWestTile() {
- return new Tile($this->getX() - 1, $this->getY());
+ return new Tile($this->getColumn() - 1, $this->getRow());
}
/**
* @return Tile
*/
public function getNorthWestTile() {
- return new Tile($this->getX() - 1, $this->getY() - 1);
+ return new Tile($this->getColumn() - 1, $this->getRow() - 1);
}
/**
* @return Tile
*/
public function getNorthTile() {
- return new Tile($this->getX(), $this->getY() - 1);
+ return new Tile($this->getColumn(), $this->getRow() - 1);
}
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isNorthOf(Tile $tile) {
-// return $this->isTheSameX($tile) && $this->isInRowNorthOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isSouthOf(Tile $tile) {
-// return $this->isTheSameX($tile) && $this->isInRowSouthOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isEastOf(Tile $tile) {
-// return $this->isTheSameY($tile) && $this->isInColumnEastOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isWestOf(Tile $tile) {
-// return $this->isTheSameY($tile) && $this->isInColumnWestOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isNorthEastOf(Tile $tile) {
-// return $this->isInRowNorthOf($tile) && $this->isInColumnEastOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isNorthWestOf(Tile $tile) {
-// return $this->isInRowNorthOf($tile) && $this->isInColumnWestOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isSouthEastOf(Tile $tile) {
-// return $this->isInRowSouthOf($tile) && $this->isInColumnEastOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isSouthWestOf(Tile $tile) {
-// return $this->isInRowSouthOf($tile) && $this->isInColumnWestOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-//
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// public function isNeighborOf(Tile $tile) {
-// // Guard; not necessary but to be completely clear
-// if ($this->isTheSameTile($tile)) {
-// return false;
-// }
-//
-// return
-// $this->isNorthOf($tile) || $this->isSouthOf($tile) ||
-// $this->isEastOf($tile) || $this->isWestOf($tile) ||
-// $this->isNorthEastOf($tile) || $this->isNorthWestOf($tile) ||
-// $this->isSouthEastOf($tile) || $this->isSouthWestOf($tile);
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// protected function isInRowNorthOf(Tile $tile) {
-// return ($this->getY() - $tile->getY()) == 1;
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// protected function isInRowSouthOf(Tile $tile) {
-// return ($this->getY() - $tile->getY()) == -1;
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// protected function isInColumnEastOf(Tile $tile) {
-// return ($this->getX() - $tile->getX()) == 1;
-// }
-//
-// /**
-// * @param Tile $tile
-// * @return bool
-// */
-// protected function isInColumnWestOf(Tile $tile) {
-// return ($this->getX() - $tile->getX()) == -1;
-// }
+
}
\ No newline at end of file
diff --git a/tests/TableTest.php b/tests/TableTest.php
index a3053c8..d7fbca6 100644
--- a/tests/TableTest.php
+++ b/tests/TableTest.php
@@ -16,7 +16,7 @@ class TableTest extends \PHPUnit_Framework_TestCase {
];
$table = new Table($tableMap);
- $this->assertEquals($tableMap, $table->getRemainingTiles());
+ $this->assertEquals($tableMap, $table->getRemainingPositions());
}
public function testHeight() {
@@ -64,4 +64,33 @@ class TableTest extends \PHPUnit_Framework_TestCase {
$tile = new Tile(2, 1);
$this->assertFalse($table->isValidForTile($tile));
}
+
+ public function testGetSpots() {
+ $tableMap = [
+ [0, 1],
+ [1, 0],
+ ];
+
+ $tile = new Tile(0, 0);
+ $spot = new Spot();
+ $table = new Table($tableMap);
+ $spot->addTile($tile);
+ $table->addSpot($spot);
+ $this->assertEquals([$spot], $table->getSpots());
+ }
+
+ public function testSpotsCount() {
+ $tableMap = [
+ [0, 1],
+ [1, 0],
+ ];
+
+ $tile = new Tile(0, 0);
+ $spot = new Spot();
+ $table = new Table($tableMap);
+ $spot->addTile($tile);
+ $table->addSpot($spot);
+ $table->addSpot($spot);
+ $this->assertEquals(2, $table->getSpotsCount());
+ }
}
diff --git a/tests/TileTest.php b/tests/TileTest.php
index d2bdea7..271e7be 100644
--- a/tests/TileTest.php
+++ b/tests/TileTest.php
@@ -10,14 +10,14 @@ class TileTest extends \PHPUnit_Framework_TestCase {
$tileA = new Tile(2, 2);
$tileB = new Tile(2, 2);
- $this->assertTrue($tileA->isTheSameX($tileB));
+ $this->assertTrue($tileA->isTheSameColumn($tileB));
}
public function testTheSameY() {
$tileA = new Tile(2, 2);
$tileB = new Tile(2, 2);
- $this->assertTrue($tileA->isTheSameY($tileB));
+ $this->assertTrue($tileA->isTheSameRow($tileB));
}
public function testTheSameTile() {
@@ -91,67 +91,4 @@ class TileTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($northTileA->isTheSameTile($NorthTileB));
}
-// public function testNorthOf() {
-// $tileA = new Tile(2, 2);
-// $tileB = new Tile(2, 1);
-//
-// $this->assertTrue($tileA->isNorthOf($tileB));
-// }
-//
-// public function testSouthOf() {
-// $tileA = new Tile(2, 1);
-// $tileB = new Tile(2, 2);
-//
-// $this->assertTrue($tileA->isSouthOf($tileB));
-// }
-//
-// public function testEastOf() {
-// $tileA = new Tile(2, 2);
-// $tileB = new Tile(1, 2);
-//
-// $this->assertTrue($tileA->isEastOf($tileB));
-// }
-//
-// public function testWestOf() {
-// $tileA = new Tile(1, 2);
-// $tileB = new Tile(2, 2);
-//
-// $this->assertTrue($tileA->isWestOf($tileB));
-// }
-//
-// public function testNorthEastOf() {
-// $tileA = new Tile(2, 2);
-// $tileB = new Tile(1, 1);
-//
-// $this->assertTrue($tileA->isNorthEastOf($tileB));
-// }
-//
-// public function testNorthWestOf() {
-// $tileA = new Tile(1, 2);
-// $tileB = new Tile(2, 1);
-//
-// $this->assertTrue($tileA->isNorthWestOf($tileB));
-// }
-//
-// public function testSouthEastOf() {
-// $tileA = new Tile(2, 1);
-// $tileB = new Tile(1, 2);
-//
-// $this->assertTrue($tileA->isSouthEastOf($tileB));
-// }
-//
-// public function testSouthWestOf() {
-// $tileA = new Tile(1, 1);
-// $tileB = new Tile(2, 2);
-//
-// $this->assertTrue($tileA->isSouthWestOf($tileB));
-// }
-//
-// public function testNeighborOf() {
-// $tileA = new Tile(1, 1);
-// $tileB = new Tile(2, 2);
-//
-// $this->assertTrue($tileA->isNeighborOf($tileB));
-// }
-
}
\ No newline at end of file