[gcompris] awale activity, fixes some bugs especially party end.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] awale activity, fixes some bugs especially party end.
- Date: Sat, 14 Dec 2013 15:48:24 +0000 (UTC)
commit 236c6caa8508ec10fe726b6417af8fd0ebb1e26a
Author: Nicolas Adenis-Lamarre <nicolas adenis lamarre gmail com>
Date: Sat Dec 14 16:47:25 2013 +0100
awale activity, fixes some bugs especially party end.
src/awele-activity/awele.c | 8 ++++--
src/awele-activity/awele_utils.c | 42 ++++++++++++++++++++++++++++++++-----
2 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/src/awele-activity/awele.c b/src/awele-activity/awele.c
index f827f20..5fe75d5 100644
--- a/src/awele-activity/awele.c
+++ b/src/awele-activity/awele.c
@@ -650,9 +650,11 @@ static gboolean to_computer(gpointer data)
} else {
/* computer hungry but human can't give it beans */
/* Human player win by catching all the beans left. */
+ updateNbBeans (0);
+ updateCapturedBeans ();
gamewon = TRUE;
- sublevel_finished = TRUE;
- gc_bonus_display(TRUE, GC_BONUS_FLOWER);
+ sublevel_finished = (staticAwale->CapturedBeans[HUMAN] > 24);
+ gc_bonus_display(sublevel_finished, GC_BONUS_FLOWER);
}
} else {
/* computer can't play. Why? human is hungry and i cannot give it
@@ -660,7 +662,7 @@ static gboolean to_computer(gpointer data)
/* if human has 24 beans, it's draw (human win in gcompris) */
/* if not, all staying are captured by computer and computer win */
gamewon = TRUE;
- sublevel_finished = (staticAwale->CapturedBeans[HUMAN] == 24);
+ sublevel_finished = (staticAwale->CapturedBeans[HUMAN] > 24);
gc_bonus_display(sublevel_finished, GC_BONUS_FLOWER);
}
diff --git a/src/awele-activity/awele_utils.c b/src/awele-activity/awele_utils.c
index 2fecb67..5d1befc 100644
--- a/src/awele-activity/awele_utils.c
+++ b/src/awele-activity/awele_utils.c
@@ -63,7 +63,8 @@ AWALE *moveAwale(short int hole, AWALE * aw)
return NULL;
}
- short int nbBeans, j, last;
+ short int nbBeans, i, j, last, start, end;
+ gboolean canGive;
tempAw = g_malloc(sizeof(AWALE));
@@ -106,13 +107,42 @@ AWALE *moveAwale(short int hole, AWALE * aw)
/* Grand Slam case */
//g_warning("Grand Slam: no capture");
g_free(tempAw);
+ tempAwGs->player = switch_player(tempAwGs->player);
return tempAwGs;
} else{
- /* No capture and opponent hungry -> forbidden */
- //g_warning("isOpponentHungry %s TRUE",(tempAw->player == HUMAN)? "HUMAN" : "COMPUTER" );
- g_free(tempAw);
- g_free(tempAwGs);
- return NULL;
+ /* 2 cases
+ - or the player was able to give a bean to the opponent -> this move must be done
+ - or the player was not able to give a bean to the opponent -> he kept all the beans
+ */
+ canGive = FALSE;
+ start = (aw->player == HUMAN)? START_COMPUTER : START_HUMAN;
+ end = (aw->player == HUMAN)? END_COMPUTER : END_HUMAN;
+ for(i=start; i<=end; i++)
+ {
+ if(NBHOLE/2-(i-start) <= aw->board[i]) // enough beans to be able to give
+ {
+ canGive = TRUE;
+ }
+ }
+
+ if(canGive)
+ {
+ /* No capture and opponent hungry -> forbidden */
+ //g_warning("isOpponentHungry %s TRUE",(tempAw->player == HUMAN)? "HUMAN" : "COMPUTER" );
+ g_free(tempAw);
+ g_free(tempAwGs);
+ return NULL;
+ } else
+ {
+ /* No capture and opponent hungry, but cannot give */
+ for(i=start; i<=end; i++)
+ {
+ tempAw->CapturedBeans[switch_player(tempAw->player)] += aw->board[i];
+ tempAw->board[i] = 0;
+ }
+ g_free(tempAwGs);
+ return tempAw;
+ }
}
}
else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]