From 2b502a39c643a3909f9066f88eab8d864685a1fb Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 10 Jan 2011 18:19:10 -0800 Subject: [PATCH] fix mod-by-zero error when iq == 2 --- xwords4/common/engine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xwords4/common/engine.c b/xwords4/common/engine.c index 43b88417d..ae85b2fd0 100644 --- a/xwords4/common/engine.c +++ b/xwords4/common/engine.c @@ -392,7 +392,10 @@ normalizeIQ( EngineCtxt* engine, XP_U16 iq ) engine->nMovesToSave = 1; } else { XP_U16 count = NUM_SAVED_ENGINE_MOVES * iq / 100; - engine->nMovesToSave = 1 + (XP_RANDOM() % count); + engine->nMovesToSave = 1; + if ( count > 0 ) { + engine->nMovesToSave += XP_RANDOM() % count; + } } XP_LOGF( "%s: set nMovesToSave=%d (iq=%d; NUM_SAVED_ENGINE_MOVES=%d)", __func__, engine->nMovesToSave, iq, NUM_SAVED_ENGINE_MOVES );