2 * AI Testing Module -- ai-test.c
4 * http://cmancala.sourceforge.net
5 * $Source: /cvsroot/cmancala/mancala/src/Attic/ai-test.c,v $
7 * $Date: 2003/12/29 05:49:52 $
16 static void print_board(int *aiBoard, int *humanBoard);
18 int main(int argc, char **argv) {
20 int *aiBoard, *humanBoard;
24 aiBoard = (int *) calloc(BOARD_MAX+1, sizeof(int));
25 humanBoard = (int *) calloc(BOARD_MAX+1, sizeof(int));
27 printf("Hello and welcome to the mancala ai-test program.\n");
28 printf("If you liked these bugs, please check out http://cmancala.sourceforge.net\n");
29 printf("for more fine specimens. Thanks! -kr\n");
31 if ((argv[1] != NULL) && (argc == 2)) {
32 if ((data = fopen((char *) argv[1], "r")) == NULL) {
33 printf("Cannot open file %s...\n", (char *) argv[1]);
37 /* Store hypothetical board layouts to test AI with */
38 for(i=0;i<=BOARD_MAX;i++)
39 if (fscanf(data, "%d", (aiBoard + i)) == EOF) {
40 printf("Reached end of file...\n");
44 for(i=0;i<=BOARD_MAX;i++)
45 if (fscanf(data, "%d", (humanBoard + i)) == EOF) {
46 printf("Reached end of file...\n");
52 else if ((argv[1] != NULL) && (argc >= (BOARD_MAX*2 + 3))) {
53 for (i=0; i<=BOARD_MAX; i++)
54 *(aiBoard + i) = **(argv + i + 1) - 48;
55 for (i=0; i<=BOARD_MAX; i++)
56 *(humanBoard + i) = **(argv + i + (BOARD_MAX+2)) - 48;
60 for (i=0; i<=BOARD_MAX; i++) {
61 printf("aiBoard[%d] = ", i);
62 scanf("%d", &aiBoard[i]);
64 for (i=0; i<=BOARD_MAX; i++) {
65 printf("humanBoard[%d] = ", i);
66 scanf("%d", &humanBoard[i]);
73 print_board(aiBoard, humanBoard);
76 printf("Dave: Let's test out the AI!\n");
77 if ((current_move = aiMove(aiBoard, humanBoard)) == 0)
78 printf("HAL: I'm sorry, Dave. I can't do that.\n");
80 printf("HAL: All my circuits are operational.\n");
81 printf("HAL: I'm going to move from hole %d.\n", current_move);
82 printf("HAL: I'm sorry, Dave. You've lost.\n");
86 if (current_move == 1)
97 /* Print board layout to stdout. */
98 static void print_board(int *aiBoard, int *humanBoard) {
101 printf("\nHuman AI\n");
102 printf(" %d\n", *aiBoard);
103 for (i=1; i<=BOARD_MAX; i++)
104 printf("%d - %d %d - %d\n", ((BOARD_MAX + 1) - i),
105 *(humanBoard + ((BOARD_MAX + 1) - i)), *(aiBoard + i), i);
106 printf(" %d\n\n", *humanBoard);