bump up version number
[mancala] / src / ai-init.c
1 /*  
2  *  AI Initialization Routine -- ai-init.c
3  *  Kevin Riggle
4  *  http://cmancala.sourceforge.net
5  *  $Source: /cvsroot/cmancala/mancala/src/Attic/ai-init.c,v $
6  *  $Revision: 1.3.2.1 $
7  *  $Date: 2003/12/29 05:49:52 $
8  *
9  */
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include "mancala.h"
14 #include "ai-init.h"
15
16 /* Initialize everything needed by the ai function */
17
18 int aiInit(
19         int *aiBoard, int *humanBoard, char *filename, 
20         int (*aifunc)(int *aiBoard, int *humanBoard, int depth, FILE *log)
21 ) {
22
23         int aiBoardTemp[BOARD_MAX+1], humanBoardTemp[BOARD_MAX+1];
24         int bestmove, k;
25         FILE *log;
26
27         /* open a log file */
28         if ((log = fopen(filename, "w")) == NULL) {
29                 printf("Cannot open %s...\n", filename);
30                 return 1; 
31         }
32
33         /* make a temporary copy of the boards */
34         for (k=0; k<=BOARD_MAX; k++) {
35                 aiBoardTemp[k] = aiBoard[k];
36                 humanBoardTemp[k] = humanBoard[k];
37         }
38
39         /* call the function in question */
40         bestmove = (*aifunc)(aiBoardTemp, humanBoardTemp, 0, log);
41
42         /* clean up and return the best move */
43         fflush(log);
44         fclose(log);
45
46         return bestmove;
47
48 }
49
50 /* End ai-init.c */