[four-in-a-row] Modified tests of AIs competing against each other.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row] Modified tests of AIs competing against each other.
- Date: Fri, 18 Jul 2014 21:46:06 +0000 (UTC)
commit 6ebcb42d8adaad9bb7f8374906cac8fba0ba7904
Author: Nikhar Agrawal <nikharagrawal2006 gmail com>
Date: Sat Jul 19 00:26:00 2014 +0530
Modified tests of AIs competing against each other.
https://bugzilla.gnome.org/show_bug.cgi?id=732136
src/test-ai.vala | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/test-ai.vala b/src/test-ai.vala
index 2b50b89..b34b02e 100644
--- a/src/test-ai.vala
+++ b/src/test-ai.vala
@@ -20,6 +20,8 @@
*/
const int NUMBER_GAMES = 5;
+const int MAXIMUM_GAMES = 100;
+const int THRESHOLD_DENOMINATOR = 4;
/* Tests if the AI makes moves so as to take up immediate horizontal wins. The argument to playgame function
is the sequence of moves
made until now. The return value of playgame function is the column number in which the AI should move.*/
@@ -178,25 +180,45 @@ private int test_ai_vs_ai (string easier, string harder)
return easier_wins;
}
+/* Repeatedly contest between the two AI until either easier win ratio is less than a threshold
+ or maximum numbers of contests have been played.*/
+private void repeat_contests (string easier, string harder, out int games_contested, out int easy_wins)
+{
+ easy_wins = test_ai_vs_ai (easier, harder);
+ games_contested = NUMBER_GAMES;
+
+ while (games_contested <= MAXIMUM_GAMES && easy_wins > games_contested/THRESHOLD_DENOMINATOR)
+ {
+ easy_wins += test_ai_vs_ai (easier, harder);
+ games_contested += NUMBER_GAMES;
+ }
+}
+
private void test_easy_vs_medium ()
{
- int easy_wins = test_ai_vs_ai ("a0","b0");
+ int easy_wins;
+ int games_contested;
+ repeat_contests ("a0", "b0", out games_contested, out easy_wins);
- assert (easy_wins <= NUMBER_GAMES/2);
+ assert (easy_wins <= games_contested/THRESHOLD_DENOMINATOR);
}
private void test_easy_vs_hard ()
{
- int easy_wins = test_ai_vs_ai ("a0","c0");
+ int easy_wins;
+ int games_contested;
+ repeat_contests ("a0", "c0", out games_contested, out easy_wins);
- assert (easy_wins <= NUMBER_GAMES/2);
+ assert (easy_wins <= games_contested/THRESHOLD_DENOMINATOR);
}
private void test_medium_vs_hard ()
{
- int medium_wins = test_ai_vs_ai ("b0","c0");
+ int medium_wins;
+ int games_contested;
+ repeat_contests ("b0", "c0", out games_contested, out medium_wins);
- assert (medium_wins <= NUMBER_GAMES/2);
+ assert (medium_wins <= games_contested/THRESHOLD_DENOMINATOR);
}
public int main (string[] args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]