Skip to content
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

while(true)を撲滅したい #6

Open
Lucky3028 opened this issue Dec 22, 2020 · 1 comment
Open

while(true)を撲滅したい #6

Lucky3028 opened this issue Dec 22, 2020 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@Lucky3028
Copy link
Member

when(defaultRegions.size) {
0 -> for (i in 1..maxDistanceOfSearching()) {
val nextLocation = defaultLocation.clone().apply {
when (direction) {
NORTH -> z -= i
EAST -> x += i
WEST -> x -= i
SOUTH -> z += i
}
}
// ERR: その座標にあるブロックを取得できない
val nextLocBlock = nextLocation.block ?: return Err(BlockNotFoundException)
// SUC: スライダーであるかつSliderTypeが同じならLocationを返し、ERR: でないならループを戻る
if (isSlider(nextLocBlock) && sliderType == getSliderType(nextLocBlock)!!)
return Ok(nextLocation)
}
1 -> {
val defaultRegion = defaultRegions.iterator().next()
var i = 1
while (true) {
val nextLocation = defaultLocation.clone().apply {
when (direction) {
NORTH -> z -= i
EAST -> x += i
WEST -> x -= i
SOUTH -> z += i
}
}
// ERR: 保護が見つからない or 同じ保護で保護されていない
if (getRegions(nextLocation).none { it.id == defaultRegion.id })
return Err(SliderNotFoundInSameRegion)
// ERR: その座標にあるブロックを取得できない
val nextLocBlock = nextLocation.block ?: return Err(BlockNotFoundException)
// SUC: スライダーであるかつSliderTypeが同じなら、Locationを返す
// ERR: そうでないなら、カウンタをインクリメントして再びループ
// `getSliderType(nextLocBlock)`は、`isSlider(nextLocBlock)`の後に指定してあるのでnullにはならない
if (isSlider(nextLocBlock) && sliderType == getSliderType(nextLocBlock)!!)
return Ok(nextLocation)
i++
}
}
else -> return Err(RegionsDuplicatedException)
}

このwhen節の中のwhile(true)を撲滅できれば関数化できるのに...

@Lucky3028 Lucky3028 added the help wanted Extra attention is needed label Dec 24, 2020
@Lucky3028
Copy link
Member Author

保護があろうがなかろうが最大値は決めたほうがよさそう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant