bump up version number
[mancala] / src / ai-test.c
1 /*  
2  *  AI Testing Module -- ai-test.c
3  *  Kevin Riggle
4  *  http://cmancala.sourceforge.net
5  *  $Source: /cvsroot/cmancala/mancala/src/Attic/ai-test.c,v $
6  *  $Revision: 1.8.2.1 $
7  *  $Date: 2003/12/29 05:49:52 $
8  *
9  */
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include "ai.h"
14 #include "mancala.h"
15
16 static void print_board(int *aiBoard, int *humanBoard);
17
18 int main(int argc, char **argv) {
19
20   int *aiBoard, *humanBoard;
21   int current_move, i;
22   FILE *data;
23
24   aiBoard = (int *) calloc(BOARD_MAX+1, sizeof(int));
25   humanBoard = (int *) calloc(BOARD_MAX+1, sizeof(int));
26
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");
30
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]);
34       return 1;
35     }
36
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");
41                 return 1; 
42         }
43
44     for(i=0;i<=BOARD_MAX;i++)
45       if (fscanf(data, "%d", (humanBoard + i)) == EOF) {
46                 printf("Reached end of file...\n");
47                 return 1;
48         }
49
50     fclose(data);
51   }
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;
57   }
58   else {
59  
60         for (i=0; i<=BOARD_MAX; i++) {
61                 printf("aiBoard[%d] = ", i);
62                 scanf("%d", &aiBoard[i]);
63         }
64         for (i=0; i<=BOARD_MAX; i++) {
65                 printf("humanBoard[%d] = ", i);
66                 scanf("%d", &humanBoard[i]);
67         }
68   }
69
70   free(aiBoard);
71   free(humanBoard);
72
73   print_board(aiBoard, humanBoard);
74
75   /* Test it! */
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");
79   else {
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");
83   }
84
85   /* AskIgor Testing 
86   if (current_move == 1)
87     printf("pass\n");
88   else
89     printf("fail\n");
90   */
91
92   return 0;
93
94 }
95
96
97 /* Print board layout to stdout. */
98 static void print_board(int *aiBoard, int *humanBoard) {
99   int i;
100
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);
107
108 }
109
110 /* End ai-test.c */