From 184c41412a8f0640887696572fe63fc8a2bf53ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Mon, 23 Jan 2023 14:27:54 +0100 Subject: [PATCH] Healing is weighted, lesser health more heal --- src/c/encounter.c | 5 +++-- test/c/test_encounter.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 2e9e547..9904048 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -122,8 +122,9 @@ bool enemyChoosesHeal(enemy* enemy) { int currentHealth = getEnemyHealth(enemy); int maxHealth = getEnemyMaxHealth(enemy); - int healthd20 = map(currentHealth, 0, maxHealth, 0, 20); - return healthd20 <= 10; + int healthd20 = 20 - map(currentHealth, 0, maxHealth, 0, 20); + int rolld20 = randomIntRange(1, 20); + return (healthd20 + rolld20) >= 30; } // Getter/Setter Funktionen diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index c4246de..5ef5b65 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -330,10 +330,25 @@ void test_enemyChoosesHeal(void) int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; //act + randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20 result = enemyChoosesHeal(&test); //assert TEST_ASSERT_TRUE(result); } +void test_enemyDoesNotChoosesHeal(void) +{ + //arange + bool result; + int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; + //act + randomInt_ExpectAndReturn(14); //14%20 = 14 , 14 + 1 = 15 + result = enemyChoosesHeal(&test); + //assert + TEST_ASSERT_FALSE(result); + +} + #endif // TEST