Implement equals for Point
Fixes bug in distribution of snippet weights: Multiple equal points could be in frontier and unvisited, therefore processed twice. Now set of points adheres to set semantics (compares points by coordinates instead of reference).
This commit is contained in:
parent
e337739b04
commit
c66e87791e
2 changed files with 19 additions and 8 deletions
|
@ -43,7 +43,9 @@ class SnippetAI extends Tactical {
|
|||
def runner(frontier: Set[Point], distance: Int): Unit = {
|
||||
if (frontier.isEmpty) return
|
||||
|
||||
// process the current frontier and build the new ones
|
||||
dbg(s"""Frontier[dist= $distance]: ${frontier.mkString(",")}""")
|
||||
|
||||
// process the current frontier and build the new one
|
||||
val nextFrontier =
|
||||
frontier filterNot { visited(_).get } flatMap { p =>
|
||||
visited(p) put true
|
||||
|
|
|
@ -8,6 +8,15 @@ class Point (val x: Int, val y: Int){
|
|||
def +(direction: Direction): Point = this + direction.delta
|
||||
|
||||
override def toString: String = s"Point{.x=$x, .y=$y}"
|
||||
def canEqual(a: Any) = a.isInstanceOf[Point]
|
||||
override def equals(that: Any): Boolean =
|
||||
that match {
|
||||
case that: Point => ( that.canEqual(this)
|
||||
&& this.x == that.x
|
||||
&& this.y == that.y )
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = 41 * (41 + x) + y
|
||||
}
|
||||
object Point {
|
||||
def apply(x: Int, y: Int) = new Point(x, y)
|
||||
|
|
Loading…
Reference in a new issue