commit a73984d7008722c51eb0d2ded486e1c6153a6865
parent ccc8a5e9822326c15197e154340e307e18c5a48e
Author: Wilson Gheen <wilson@wilsonrgheen.com>
Date: Thu, 22 Dec 2022 12:55:43 -0600
Add unit test to verify AI cannot beat itself
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/unit_test.c b/unit_test.c
@@ -20,11 +20,13 @@ int main() {
int failures = 0;
int len = sizeof test_boards / sizeof test_boards[0];
int i = 0;
+ int c = 0;
+ /* Testing that particular presets will be correctly interpreted as a draw/win/loss */
while(i < len) {
struct test_board *b = test_boards + (i++);
char actual_result[8];
printf("TEST %d\n", i);
- puts( "--------");
+ puts( "--------");
printf("Testing %s -- expecting '%s' ...\n", b->name, b->expected_result);
set_board(b->name);
char winner = play(get_move_preset_board, NULL);
@@ -40,6 +42,13 @@ int main() {
}
else puts("SUCCESS\n");
}
+ printf("TEST %d\n", ++i);
+ puts( "--------");
+ puts("Pitting our allegedly perfect AI against itself 50 times. Expecting a draw for all executions.");
+ for(c=0; c < 50 && play(get_move_minimax, NULL) == 0; ++c);
+ if(c < 50) failures++, puts("FAILURE\n");
+ else puts("SUCCESS\n");
+
puts("-----------------------------------------------------------");
printf("\n### SUITE %s ###\n", failures ? "FAILURE" : "SUCCESS");
printf("%d tests: %d failed, %d succeeded\n", i, failures, i - failures);