X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmancala.c;fp=src%2Fmancala.c;h=0000000000000000000000000000000000000000;hb=1adeebe9572cc4441d114687606e45cde11f5b2b;hp=951bf37620e1be6ede95f8c1ae63abe9b70570be;hpb=860de21ec6c253290ab3fc213cb11f350b193d05;p=mancala diff --git a/src/mancala.c b/src/mancala.c deleted file mode 100644 index 951bf37..0000000 --- a/src/mancala.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Mancala Common Source Module -- mancala.c - * Kevin Riggle - * http://cmancala.sourceforge.net - * $Source: /cvsroot/cmancala/mancala/src/Attic/mancala.c,v $ - * $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 -#include -#include "mancala.h" - -/* Set up the game board. */ -void gameInit(int *aiBoard, int *humanBoard) { - - int i; - - *aiBoard = *humanBoard = 0; - - for (i=1; i<=BOARD_MAX; i++) - *(aiBoard + i) = *(humanBoard + i) = INITIAL_STONES; - -} - -/* Has the game been won by someone? */ -int gameWon(int *aiBoard, int *humanBoard) { - - int aiTotal, humanTotal, i; - - aiTotal = humanTotal = 0; - - /* Sum the stones on each side... */ - for (i=1; i<=BOARD_MAX; i++) { - aiTotal = aiTotal + *(aiBoard + i); - humanTotal = humanTotal + *(humanBoard + i); - } - - /* If one side has none, return accordingly. */ - if (aiTotal == 0 || humanTotal == 0) { - /* Calculate the final score. */ - for (i=1; i<=BOARD_MAX; i++) { - *aiBoard = *aiBoard + *(aiBoard + i); - *humanBoard = *humanBoard + *(humanBoard + i); - *(aiBoard + i) = *(humanBoard + i) = 0; - } - return 1; - } - else - return 0; - -} - -/* Make a move, and return the position of the last stone! */ -int move(int *activeBoard, int *passiveBoard, int move) { - - int *currentPosition, stones; - - currentPosition = activeBoard + move; - - stones = *(activeBoard + move); - 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; - } - else{ - printf("move from empty hole...\n"); - /* return 0 so human can make a move again */ - return 0; - } - -} - -int rand_btw(int min, int max) { - - int range; - - range = (max - min) + 1; - - return ((rand() % range) + min); - -} - -/* End mancala.c */