diff --git a/.gitignore b/.gitignore index 34051033..88f4a054 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +.bloop/ +.metals/ +.vscode/ +project/.bloop/ +project/metals.sbt +project/project/ + .DS_Store .idea/* scaladoc/ diff --git a/src/main/scala/scatan/mvc/model/map/Hexagon.scala b/src/main/scala/scatan/mvc/model/map/Hexagon.scala index 9d3ed91d..b487a95a 100644 --- a/src/main/scala/scatan/mvc/model/map/Hexagon.scala +++ b/src/main/scala/scatan/mvc/model/map/Hexagon.scala @@ -1,11 +1,28 @@ package scatan.mvc.model.map +/** An Hexagon in the space rapresented by 3 coordinates. + */ trait Hexagon: def row: Int def col: Int def slice: Int + + /** @return + * the set of all neighbours + */ def neighbours: Set[Hexagon] + + /** Neighborhood means that two Hexagon are far away 1 in coordinate system + * @param another + * Hexagon to test on + * @return + * true if another is a neighbour of this hexagon + */ def isNeighbour(another: Hexagon): Boolean + + /** @return + * the distance from the center + */ def layer: Int object Hexagon: diff --git a/src/test/scala/scatan/mvc/model/map/HexagonTest.scala b/src/test/scala/scatan/mvc/model/map/HexagonTest.scala index 600d99cf..6b558fb4 100644 --- a/src/test/scala/scatan/mvc/model/map/HexagonTest.scala +++ b/src/test/scala/scatan/mvc/model/map/HexagonTest.scala @@ -17,15 +17,15 @@ class HexagonTest extends BaseTest with ScalaCheckPropertyChecks: forAll { (r: Int, c: Int, s: Int) => val hexagon1 = Hexagon(r, c, s) val hexagon2 = Hexagon(r, c, s) - hexagon1 should equal(hexagon2) + hexagon1 shouldBe hexagon2 } } it should "respect the identity law in order to be a Monoid" in { forAll { (r: Int, c: Int, s: Int) => val hexagon = Hexagon(r, c, s) - hexagon |+| Monoid[Hexagon].empty should be(hexagon) - Monoid[Hexagon].empty |+| hexagon should be(hexagon) + hexagon |+| Monoid[Hexagon].empty shouldBe hexagon + Monoid[Hexagon].empty |+| hexagon shouldBe hexagon } } @@ -33,13 +33,23 @@ class HexagonTest extends BaseTest with ScalaCheckPropertyChecks: forAll { (r1: Int, c1: Int, s1: Int, r2: Int, c2: Int, s2: Int) => val hexagon1 = Hexagon(r1, c1, s1) val hexagon2 = Hexagon(r2, c2, s2) - hexagon1 |+| hexagon2 should be(hexagon2 |+| hexagon1) + hexagon1 |+| hexagon2 shouldBe (hexagon2 |+| hexagon1) } } it should "have 6 neighbours" in { forAll { (r: Int, c: Int, s: Int) => val hexagon = Hexagon(r, c, s) - hexagon.neighbours.size should equal(6) + hexagon.neighbours should have size 6 } } + + "An Hexagon in the center" should "be in layer 0" in { + val centeredHexagon = Hexagon(0, 0, 0) + centeredHexagon.layer shouldBe 0 + } + + it should "have neighbours at layer 1" in { + val centeredHexagon = Hexagon(0, 0, 0) + all(centeredHexagon.neighbours.map(_.layer)) shouldBe 1 + }