2 * AI Source Module -- ai.c
4 * http://cmancala.sourceforge.net
5 * $Source: /cvsroot/cmancala/mancala/src/Attic/ai.c,v $
7 * $Date: 2003/12/29 05:49:52 $
16 /* Return the computer's move. */
17 int aiMove(int *aiBoard, int *humanBoard) {
19 int BestCapture, CapturePoints, BestMove, MoveSize, Test, i;
21 BestCapture = CapturePoints = BestMove = MoveSize = Test = i = 0;
23 /* printf("HAL: I'm thinking, Dave...\n"); */
24 /* Loop through possible moves... */
25 for(i=1;i<=BOARD_MAX;i++) {
26 /* ...only if there is any move to make! */
27 if (aiBoard[i] != 0) {
28 /* Calculate position of final stone */
29 Test = i - (aiBoard[i] % ((2 * BOARD_MAX)+1));
31 /* If this move ends on my home, take it. */
34 /* If it doesn't but a capture does occur... */
35 else if ((Test>0) && (aiBoard[Test] == 0)) {
36 /* ...that's the best we've seen so far, store the info. */
37 if (humanBoard[(BOARD_MAX + 1) - Test] > CapturePoints) {
39 CapturePoints = humanBoard[(BOARD_MAX + 1) - Test];
42 /* If neither happen, but this is larger than previous, record it. */
43 if (aiBoard[i] > MoveSize) {
45 MoveSize = aiBoard[i];
50 /* If we have a good capture, take it. */
54 /* Otherwise, move the largest concentration of stones. */