Note that there are some explanatory texts on larger screens.

plurals
  1. POThis method that determines the winner of a Mancala does not work
    primarykey
    data
    text
    <p>Mancala is a fascinating game that I programmed in Java. On the image below we see a Mancala gameboard. For my problem you need to know that a A1-A6,B1-B6 are called pits and the big pits are called kalahs.</p> <p><a href="http://www.pressmantoy.com/instructions/mancala_img1.jpg" rel="nofollow noreferrer">The mancala game http://www.pressmantoy.com/instructions/mancala_img1.jpg</a></p> <p>The pits A1-A6 and right kalah belongs to player A and pits B1-B6 and left kalah to player B. </p> <p>The game ends when all six pits on one side of the gameboard are empty or when there are more than 24 pits in one player's kalah. This is what I tried to program in a boolean method (which returns true if there is a winner so I can use other method to tell who it is):</p> <pre><code>public boolean isThereAWinner() { ArrayList &lt;SuperPit&gt; pitsOfOwner = owner.getmyPits(); ArrayList &lt;SuperPit&gt; pitsOfOpponent = owner.getopponent().getmyPits(); for (int i = 0; i &lt; pitsOfOwner.size(); i++) { if (pitsOfOwner.get(i).isValidPlayOption() == true) return false; } for (int i = 0; i &lt; pitsOfOpponent.size(); i++) { if (pitsOfOpponent.get(i).isValidPlayOption() == true) return false; } if (owner.getKalah().getSeed() &gt; 24) return true; return false; } </code></pre> <p>Where:</p> <pre><code>protected int seed; public int getSeed() { return seed; } public boolean isValidPlayOption() { if (getSeed() &gt; 0) return true; else return false; } </code></pre> <p>The oppositepit() and nextPit() methods work. The myPits ArrayLists contain the pits that belong to the two respective players. </p> <p>I thought that this method should work since if one player no longer has seeds in his pit the game should stop. The method isThereAWinner() is run every time a player makes a move.</p> <p>Unfortunately, the method always returns false. I have no idea why and hope someone here can provide me with some insight.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload