Skip to content

Commit

Permalink
Merge pull request #88 from EntelectChallenge/release/2019.3.2
Browse files Browse the repository at this point in the history
Release/2019.3.2
  • Loading branch information
Mistborn94 committed Sep 2, 2019
2 parents 8aa8752 + 2ec1269 commit 98dedb6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion game-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "za.co.entelect.challenge"
version = "2019.3.1"
version = "2019.3.2"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CommandExecutor(private val player: WormsPlayer,
else -> player.consecutiveDoNothingsCount = 0
}

if (worm.roundsUntilUnfrozen != freezeDuration && worm.roundsUntilUnfrozen > 0) {
if (!command.ignoresBeingFrozen() && worm.roundsUntilUnfrozen != freezeDuration && worm.roundsUntilUnfrozen > 0) {
logger.info { "Tried to execute command $command, but $worm is still frozen for ${worm.roundsUntilUnfrozen} round" }
map.addFeedback(StandardCommandFeedback(command.toString(), 0, player.id, false, "Frozen worms cannot follow your commands",
VisualizerEvent(CommandStrings.NOTHING.string, "frozen", worm, null, null, null)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ interface WormsCommand {
*/
fun execute(gameMap: WormsMap, worm: Worm): CommandFeedback

/**
* Produce true if the command should be executed regardless
* of whether the current worm is frozen.
*/
fun ignoresBeingFrozen(): Boolean {
return false
}

override fun toString(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class SelectCommand(val wormId: Int) : WormsCommand {
}
}

override fun ignoresBeingFrozen(): Boolean {
return true
}

override fun toString(): String = "${CommandStrings.SELECT.string} $wormId"

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class WormsPlayer private constructor(val id: Int,
//Assign living worms to a local variable since it is a computed property
val livingWorms = this.livingWorms
if (livingWorms.isNotEmpty()) {
val nextIndex = (livingWorms.indexOf(currentWorm) + 1) % livingWorms.size
updateCurrentWorm(livingWorms[nextIndex])
val nextWorm = livingWorms.firstOrNull { it.id > currentWorm.id } ?: livingWorms.first()
updateCurrentWorm(nextWorm)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import za.co.entelect.challenge.game.delegate.factory.TEST_CONFIG
import za.co.entelect.challenge.game.engine.command.feedback.StandardCommandFeedback
import za.co.entelect.challenge.game.engine.command.feedback.CommandValidation
import za.co.entelect.challenge.game.engine.factory.TestMapFactory.buildMapWithCellType
import za.co.entelect.challenge.game.engine.command.implementation.SelectCommand
import za.co.entelect.challenge.game.engine.map.CellType
import za.co.entelect.challenge.game.engine.map.Point
import za.co.entelect.challenge.game.engine.player.CommandoWorm
Expand Down Expand Up @@ -39,6 +40,19 @@ class CommandExecutorTest {
verify(command, times(0)).execute(any(), any())
}

@Test
fun test_selectFrozenWorm() {
val worms = listOf(CommandoWorm.build(0, config, Point(1, 1)),
CommandoWorm.build(1, config, Point(1, 2)))
worms[0].setAsFrozen(3)
val player = WormsPlayer.build(1, worms, config)
val command = SelectCommand(1)
val executor = CommandExecutor(player, mockMap, command, config)

executor.execute()
assertEquals(worms[1], player.currentWorm)
}

@Test
fun test_validMove() {
val validCommand: WormsCommand = mock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,46 @@ class WormsPlayerTest {
assertEquals(player.worms[0], player.currentWorm)
}

@Test
fun test_player_wormSelection_All() {
val player = WormsPlayer.build(2, config)
assertEquals(1, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[1], player.currentWorm)
assertEquals(2, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[2], player.currentWorm)
assertEquals(3, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[0], player.currentWorm)
assertEquals(1, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[1], player.currentWorm)
assertEquals(2, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[2], player.currentWorm)
assertEquals(3, player.currentWorm.id)
}

@Test
fun test_player_wormSelection_currentWormDead() {
val player = WormsPlayer.build(2, config)

player.updateCurrentWorm(player.worms[1])
player.worms[1].health = 0;

assertEquals(2, player.currentWorm.id);

player.selectNextWorm();

assertEquals(3, player.currentWorm.id)
}

@Test
fun test_player_dead() {
val player = WormsPlayer.build(0, config)
Expand Down

0 comments on commit 98dedb6

Please sign in to comment.