Skip to content

Instantly share code, notes, and snippets.

@ungarst
Created March 13, 2013 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ungarst/5150263 to your computer and use it in GitHub Desktop.
Save ungarst/5150263 to your computer and use it in GitHub Desktop.
The moves seed method in board
public boolean moveSeeds(int playerToMove, int houseNumber) {
int seedsInHand, currentPlayer, currentHouse;
if (_players[playerToMove].seedsInHouse(houseNumber) == 0) {
}
// get seeds from players house
// number of seeds
// set seeds in that house to be zero
seedsInHand = _players[playerToMove].seedsInHouse(houseNumber);
_players[playerToMove].emptyHouse(houseNumber);
currentPlayer = playerToMove;
currentHouse = houseNumber;
// Distribute the seeds
//
// while there are still seeds in the hand
// if you are not at the store of another player
// place a seed in the house you are at
// move on to the next house/store
while (seedsInHand > 0) {
//move on to the next house
currentHouse = (currentHouse + 1) % (NUM_HOUSES + 1);
if (currentHouse == 0)
currentPlayer = (currentPlayer + 1) % NUM_PLAYERS;
if (!(currentPlayer != playerToMove && currentHouse == NUM_HOUSES)) {
_players[currentPlayer].incrementHouse(currentHouse);
seedsInHand -= 1;
}
}
// move finishes in the players store so they get another go.
if (currentHouse == NUM_HOUSES && currentPlayer == playerToMove)
return false;
if (currentPlayer == playerToMove && _players[currentPlayer].seedsInHouse(currentHouse) == 1 &&
NUM_PLAYERS%2 == 0) {
int oppositePlayer, oppositeHouse;
oppositePlayer = (NUM_PLAYERS/2 + currentPlayer) % NUM_PLAYERS;
oppositeHouse = NUM_HOUSES - 1 - currentHouse;
/*if (_players[oppositePlayer].seedsInHouse(oppositeHouse) > 1) {*/
// take its seed and the seed of the opposite house
int seedsToAdd;
// empty current house
seedsToAdd = 1;
_players[currentPlayer].emptyHouse(currentHouse);
oppositePlayer = (NUM_PLAYERS/2 + currentPlayer) % NUM_PLAYERS;
oppositeHouse = NUM_HOUSES - 1 - currentHouse;
seedsToAdd += _players[oppositePlayer].seedsInHouse(oppositeHouse);
_players[oppositePlayer].emptyHouse(oppositeHouse);
_players[currentPlayer].incrStoreValue(seedsToAdd);
/*}*/
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment