-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spawn hints in neighborhood of open fields #477
Conversation
Nice! Thanks for your contribution! |
fun hasUncoveredNeighbor( index: Int ): Boolean { | ||
val numOfUncoveredNeighbors = field.getOrNull(index)?.run { | ||
neighborsIds | ||
.map { field[it] } | ||
.filter { !it.isCovered } | ||
.count() | ||
} | ||
return numOfUncoveredNeighbors!! > 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do this, instead:
private fun hasUncoveredNeighbor(area: Area): Boolean {
return area.neighborsIds.map { field[it] }.count { !it.isCovered } > 0
}
val unrevealedMinesWithUncoveredNeighbors = unrevealedMines.filter { | ||
hasUncoveredNeighbor(it.id) | ||
} | ||
val potentialTargets = | ||
if (unrevealedMinesWithUncoveredNeighbors.count() > 0) { | ||
unrevealedMinesWithUncoveredNeighbors | ||
} else { | ||
unrevealedMines | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With that suggestion, you can call here:
val unrevealedMinesWithUncoveredNeighbors = unrevealedMines.filter(::hasUncoveredNeighbor)
val potentialTargets = unrevealedMinesWithUncoveredNeighbors.ifEmpty {
unrevealedMines
}
val nearestTarget = | ||
if (lastX != null && lastY != null) { | ||
unrevealedMines.filter { | ||
potentialTargets.filter { | ||
(lastX - it.posX).absoluteValue < NEAR_MINE_THRESHOLD && | ||
(lastY - it.posY).absoluteValue < NEAR_MINE_THRESHOLD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, I would like to prioritize the mines that are visible in the screen.
@gboehl Your suggestion looks functional. Please, let me know if you will implement the suggestions. I can finish for you if you are ok. |
Thanks for the suggestions! I actually have zero previous experience with kotlin, so this is much appreciated. I added your suggestions and the PR should now be good to go. |
This should close #305 |
This is a proposal to address issue #305. As stated there, hints appear at any random field that is not open and has no marker. Hints out in the void which are not in the neighborhood of any open field are never useful. I thus propose to only show hints that, if possible, are adjacent to a disclosed field.
Thanks for creating this nice app!