Skip to content

Commit

Permalink
DRAW-197 fix: 마피아 Vote -> InferAnswer 로직 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Jul 30, 2024
1 parent 0cd6f23 commit 8f3f270
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.broker.WebSocketBroadcaster
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoBody
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitMessage
import com.xorker.draw.websocket.message.response.dto.toResponse
import java.time.LocalDateTime
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ internal class MafiaPhasePlayGameProcessor(

val gameOption = gameInfo.gameOption

val nextTurn = phase.nextTurn(gameOption.round, gameOption.turnCount)
val room = gameInfo.room
val nextTurn = phase.nextTurn(gameOption.round - 1, room.size() - 1)

if (nextTurn == null) {
nextStep.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class MafiaPhasePlayVoteProcessor(

if (candidate.first == mafiaPlayer.userId) {
winStep.invoke()
return
}
}
loseStep.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xorker.draw.mafia.MafiaGameInfo
import com.xorker.draw.mafia.MafiaGameRepository
import com.xorker.draw.mafia.MafiaPhase
import com.xorker.draw.mafia.MafiaPhaseMessenger
import com.xorker.draw.mafia.assert
import com.xorker.draw.mafia.assertIs
import com.xorker.draw.room.RoomId
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -94,7 +95,7 @@ internal class MafiaPhaseService(

val phase = synchronized(gameInfo) {
val votePhase = gameInfo.phase
assertIs<MafiaPhase.Vote>(votePhase)
assert<MafiaPhase.Vote, MafiaPhase.InferAnswer>(votePhase)
mafiaPhaseEndGameProcessor.endGame(gameInfo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data class MafiaGameOption(
val round: Int = 2, // 전체 라운드 수
val turnTime: Duration = Duration.ofSeconds(5), // 턴 당 최대 시간
val turnCount: Int = 2, // 턴 당 최대 획 수
val voteTime: Duration = Duration.ofMinutes(10), // 투표 시간
val answerTime: Duration = Duration.ofMinutes(10), // 정답 입력 시간
val voteTime: Duration = Duration.ofSeconds(10), // 투표 시간
val answerTime: Duration = Duration.ofSeconds(10), // 정답 입력 시간
)
11 changes: 11 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ inline fun <reified T : MafiaPhase> assertIs(phase: MafiaPhase) {
throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T::class}, 요청값: $phase")
}
}

@OptIn(ExperimentalContracts::class)
inline fun <reified T1 : MafiaPhase, reified T2 : MafiaPhase> assert(phase: MafiaPhase) {
contract {
returns() implies (phase is T1 || phase is T2)
}

if (phase !is T1 && phase !is T2) {
throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T1::class} or ${T2::class}, 요청값: $phase")
}
}

0 comments on commit 8f3f270

Please sign in to comment.