* $Revision: 1.4.2.1 $
* $Date: 2003/12/29 05:49:52 $
*
+ * Copyright (C) 2003, 2004 Kevin Riggle
+ * Copyright (C) 2009 Reto Zingg
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details, a copy of which may be found in
+ * the file COPYING provided in the main directory of this release.
+ *
*/
#include <stdlib.h>
currentPosition = activeBoard + move;
- /* Pick up the stones. */
stones = *(activeBoard + move);
- *(activeBoard + move) = 0;
-
- /* Loop for each stone. */
- for (; stones>0; stones--) {
-
- /* Move to the next board location. */
- if (currentPosition == activeBoard)
- currentPosition = passiveBoard + BOARD_MAX;
- else if (currentPosition == passiveBoard + 1)
- currentPosition = activeBoard + BOARD_MAX;
- else
- currentPosition--;
-
- /* Drop a stone. */
- (*currentPosition)++;
-
+ if (stones > 0){
+ /* Pick up the stones. */
+ *(activeBoard + move) = 0;
+
+ /* Loop for each stone. */
+ for (; stones>0; stones--) {
+ /* Move to the next board location. */
+ if (currentPosition == activeBoard)
+ currentPosition = passiveBoard + BOARD_MAX;
+ else if (currentPosition == passiveBoard + 1)
+ currentPosition = activeBoard + BOARD_MAX;
+ else
+ currentPosition--;
+ /* Drop a stone. */
+ (*currentPosition)++;
+ }
+
+ /* If the last stone lands on an empty hole... */
+ if (*currentPosition == 1 && activeBoard < currentPosition &&
+ currentPosition <= (activeBoard + BOARD_MAX)) {
+ /* ...calculate the position of the opposite hole... */
+ int oppHole = (BOARD_MAX + 1) - (currentPosition - activeBoard);
+ /* ...and make the capture. */
+ *activeBoard = *activeBoard + *(passiveBoard + oppHole);
+ printf("Captured %d stones.\n", *(passiveBoard + oppHole));
+ *(passiveBoard + oppHole) = 0;
+ }
+
+ return currentPosition - activeBoard;
}
-
- /* If the last stone lands on an empty hole... */
- if (*currentPosition == 1 && activeBoard < currentPosition &&
- currentPosition <= (activeBoard + BOARD_MAX)) {
-
- /* ...calculate the position of the opposite hole... */
- int oppHole = (BOARD_MAX + 1) - (currentPosition - activeBoard);
-
- /* ...and make the capture. */
- *activeBoard = *activeBoard + *(passiveBoard + oppHole);
- printf("Captured %d stones.\n", *(passiveBoard + oppHole));
- *(passiveBoard + oppHole) = 0;
+ else{
+ printf("move from empty hole...\n");
+ /* return 0 so human can make a move again */
+ return 0;
}
-
- return currentPosition - activeBoard;
}