PLEASE can do this in NETBEAN I need that way thank very much
Mancala is a family of board games played around the world, sometimes called \"sowing\"
games, or \"count-and-capture\" games, which describes the gameplay. The Kalah variant was
imported to the United States in 1940. This game favors the starting player, who will always win
the three-seed to six-seed versions with perfect play. As a result, this variant is usually
considered a children\'s game. mancalaBoard Rules The game provides a Kalah board and a
number of seeds or counters. The board has 12 small pits, called houses, on each side; and a big
pit, called an end zone, at each end. The object of the game is to capture more seeds than one\'s
opponent. At the beginning of the game, four seeds are placed in each house. This is the
traditional method. Each player controls the six houses and their seeds on the player\'s side of the
board. The player\'s score is the number of seeds in the store to their right. Players take turns
sowing their seeds. On a turn, the player removes all seeds from one of the houses under their
control. Moving counter-clockwise, the player drops one seed in each house in turn, including
the player\'s own store but not their opponent\'s. If the last sown seed lands in an empty house
owned by the player, and the opposite house contains seeds, both the last seed and the opposite
seeds are captured and placed into the player\'s store. If the last sown seed lands in the player\'s
store, the player gets an additional move. There is no limit on the number of moves a player can
make in their turn. When one player no longer has any seeds in any of their houses, the game
ends. The other player moves all remaining seeds to their store, and the player with the most
seeds in their store wins. It is possible for the game to end in a draw. Requirements The project
name shall be _GEM_Mancala Create a JSP-based application using MVC architecture that
implements the Mancala game as described above The application must display: The game board
current player indicator current number of seeds in each pit current scores (number of seeds in
each house) game over indicator winner indicator a quit button The game cannot use old-style
scriptlet tags (<% %>), expression tags (<%= %>) or declaration tags (<%! %>) mancalaStamp
Solution
New File
Save file as Gboard.java
Inthiswe will build the game board and all ofit\'sproperties
It includes:
Each player\'s pots, with player ownership (although we can do this in the LinkList/Array
classes.
We should also have win conditions, pot placement in the window, and pool placement.
Possibly we should have the score and what not placed in here too referenced from the
LinkList/Array classes.
package main;
import java.util.Random;
public class GBoard {
private int STANDARDBEADS = 3;
private int m_bowls[];
private int player1Pool;
private int player2Pool;
private int SelectOn, currentPlayer;
private boolean running;
Random rand = new Random();
privat.
PLEASE can do this in NETBEAN I need that way thank very muchManca.pdf
1. PLEASE can do this in NETBEAN I need that way thank very much
Mancala is a family of board games played around the world, sometimes called "sowing"
games, or "count-and-capture" games, which describes the gameplay. The Kalah variant was
imported to the United States in 1940. This game favors the starting player, who will always win
the three-seed to six-seed versions with perfect play. As a result, this variant is usually
considered a children's game. mancalaBoard Rules The game provides a Kalah board and a
number of seeds or counters. The board has 12 small pits, called houses, on each side; and a big
pit, called an end zone, at each end. The object of the game is to capture more seeds than one's
opponent. At the beginning of the game, four seeds are placed in each house. This is the
traditional method. Each player controls the six houses and their seeds on the player's side of the
board. The player's score is the number of seeds in the store to their right. Players take turns
sowing their seeds. On a turn, the player removes all seeds from one of the houses under their
control. Moving counter-clockwise, the player drops one seed in each house in turn, including
the player's own store but not their opponent's. If the last sown seed lands in an empty house
owned by the player, and the opposite house contains seeds, both the last seed and the opposite
seeds are captured and placed into the player's store. If the last sown seed lands in the player's
store, the player gets an additional move. There is no limit on the number of moves a player can
make in their turn. When one player no longer has any seeds in any of their houses, the game
ends. The other player moves all remaining seeds to their store, and the player with the most
seeds in their store wins. It is possible for the game to end in a draw. Requirements The project
name shall be _GEM_Mancala Create a JSP-based application using MVC architecture that
implements the Mancala game as described above The application must display: The game board
current player indicator current number of seeds in each pit current scores (number of seeds in
each house) game over indicator winner indicator a quit button The game cannot use old-style
scriptlet tags (<% %>), expression tags (<%= %>) or declaration tags (<%! %>) mancalaStamp
Solution
New File
Save file as Gboard.java
Inthiswe will build the game board and all ofit'sproperties
It includes:
Each player's pots, with player ownership (although we can do this in the LinkList/Array
classes.
We should also have win conditions, pot placement in the window, and pool placement.
2. Possibly we should have the score and what not placed in here too referenced from the
LinkList/Array classes.
package main;
import java.util.Random;
public class GBoard {
private int STANDARDBEADS = 3;
private int m_bowls[];
private int player1Pool;
private int player2Pool;
private int SelectOn, currentPlayer;
private boolean running;
Random rand = new Random();
private XY[] m_bowlLocations;
private XY m_tileSize;
private String gameState;
// variables for distributing
private int nextBowl, distributionCounter;
private boolean steal, extraTurn;
private AI ai
int GMode;
// Initializer
public GBoard(boolean randomize, int Mode) {
initializeGame(randomize);
player1Pool = 6;
player2Pool = 13;
GMode = Mode;
}
private void initializeGame(boolean randomize) {
m_bowls = new int[14];
m_bowlLocations = new XY[14];
m_tileSize = new XY();
if (randomize)
RandomizeBowls();
else
fillBowls();
initializeBowlPoisitions();
3. currentPlayer = 1;
SelectOn = 0;
running = true;
gameState = "Playing";
ai = new AI(m_bowls);
GMode = 0;
}
// Reset Game board
public void ResetGBoard() {
for (int i = 0; i < 14; i++) {
m_bowls[i] = 0;
}
SelectOn = 0;
currentPlayer = 0;
running = false;
}
// Fills all bowls with a standard number of beads
private void fillBowls() {
for (int i = 0; i < 14; i++) {
if ((i + 1) % 7 == 0)
m_bowls[i] = 0;
else
m_bowls[i] = STANDARDBEADS; // 3 beads per each bowl is the
// standard
}
}
// Fill all bowls with at least one bead, and add to them randomly to fill
// all bowls with random beads
private void RandomizeBowls() {
// keep track of total beads
int totalBeads = 0;
// fill all bowls with at least one bead
for (int i = 0; i < 14; i++) {
if ((i + 1) % 7 == 0)
m_bowls[i] = 0;
else {
4. m_bowls[i] = 2;
totalBeads+=2;
}
}
// fill random bowls with more beads
int index;
while (totalBeads < STANDARDBEADS * 12) {
index = rand.nextInt(14);
if (!((index + 1) % 7 == 0)) {
m_bowls[index]++;
totalBeads++;
}
}
}
private void initializeBowlPoisitions() {
m_tileSize.set(60, 60);
// initialize all XY locations for bowls
for (int i = 0; i < m_bowlLocations.length; i++) {
m_bowlLocations[i] = new XY();
}
int x = m_tileSize.getX() * 2;
int y = m_tileSize.getY();
for (int i = 12; i > 6; i--) {
m_bowlLocations[i].set(x, y);
x += m_tileSize.getX();
}
x = m_tileSize.getX() * 2;
y = m_tileSize.getX() * 3;
for (int i = 0; i < 6; i++) {
m_bowlLocations[i].set(x, y);
x += m_tileSize.getX();
}
m_bowlLocations[13].set(m_tileSize.getX(), m_tileSize.getY() * 2);
m_bowlLocations[6].set(m_tileSize.getX() * 8, m_tileSize.getY() * 2);
}
private boolean distributeOnce(int index) {
5. nextBowl++;
// if the next bowl is greater than the size of the array, then loop to
// the beginning of the array
if (nextBowl >= getGameSize()) {
nextBowl = 0;
}
m_bowls[index]--;
m_bowls[nextBowl]++;
distributionCounter--;
if (distributionCounter <= 0) {
gameState = "Playing";
return true;
} else {
gameState = "Distributing";
return false;
}
}
private void initiateDistributionInstance(int index) {
nextBowl = index;
distributionCounter = m_bowls[index];
}
private void GameLogic() {
// check if last bowl was empty
steal = false;
extraTurn = false;
if (nextBowl == 6 || nextBowl == 13)
extraTurn = true;
if (m_bowls[nextBowl] == 1 && nextBowl != 6 && nextBowl != 13)
steal = true;
// prevent player from stealing from himself
if (((nextBowl > 6 && currentPlayer == 1) || (nextBowl < 6 && currentPlayer == 2)))
steal = false;
// prevent player from getting an extra turn when landing in opposing pool
if (((nextBowl == 6 && currentPlayer == 2) || (nextBowl == 13 && currentPlayer == 1)))
extraTurn = false;
// if true find opposite bowl and steal pieces in that bowl, and reward them to the current player
6. if (steal) {
int oppositeBowl = 12 - nextBowl;
if (m_bowls[oppositeBowl] != 0) {
if (oppositeBowl < 6) {
m_bowls[13] += m_bowls[oppositeBowl];
} else if (oppositeBowl > 6) {
m_bowls[6] += m_bowls[oppositeBowl];
}
m_bowls[oppositeBowl] = 0;
System.out.println("STEAL!");
}
}
if (extraTurn) {
System.out.println("Extra Turn!");
} else {
SwitchCurrentPlayer();
gameState = "Playing";
System.out.println("Players switched");
}
}
private void MoveSelectOnRight() {
if (currentPlayer == 1) {
if (SelectOn < 5)
SelectOn++;
} else if (currentPlayer == 2) {
if (SelectOn > 7)
SelectOn--;
}
}
private void MoveSelectOnLeft() {
if (currentPlayer == 1) {
if (SelectOn > 0)
SelectOn--;
} else if (currentPlayer == 2) {
if (SelectOn < 12)
SelectOn++;
7. }
}
private void SwitchCurrentPlayer() {
if (currentPlayer == 1) {
currentPlayer = 2;
SelectOn = 7;
} else if (currentPlayer == 2) {
currentPlayer = 1;
SelectOn = 0;
}
}
public int getSelectOn() {
return SelectOn;
}
private boolean checkGameOverCondition() {
// check player 1
boolean GameOver = true, flag = false;
for (int i = 0; i < 6; i++) {
if (m_bowls[i] != 0) {
flag = true;
// if any bowls contain a number that is not 0 return false
}
if (flag)
GameOver = false;
}
if (GameOver)
return GameOver;
// Check player 2
GameOver = true;
flag = false;
for (int i = 7; i < 13; i++) {
if (m_bowls[i] != 0) {
flag = true;
}
if (flag)
GameOver = false;
8. }
return GameOver; // if no bowls contained a non-zero number return true
}
public boolean isRunning() {
return running;
}
public void update(int input) {
if (gameState != "Distributing")
handleGMode();
ai.update(m_bowls);
if (gameState == "Playing") {
handleInput(input);
} else if (gameState == "Distributing") {
handleDistribution(getSelectOn());
} else if (gameState == "AI")
handleAI(currentPlayer);
running = !checkGameOverCondition();
}
private void handleGMode() {
if (GMode == 0) {
gameState = "Playing";
} else if (GMode == 1) {
if (currentPlayer == 1)
gameState = "Playing";
if (currentPlayer == 2)
gameState = "AI";
} else if (GMode == 2) {
gameState = "AI";
}
}
private void handleDistribution(int index) {
boolean flag;
System.out.println(gameState);
flag = distributeOnce(index);
if (flag)
GameLogic();
9. Sleep(500);
}
public void handleInput(int input) {
switch (input) {
case 'A':
MoveSelectOnLeft();
break;
case 'D':
MoveSelectOnRight();
break;
case ' ':
if (m_bowls[getSelectOn()] != 0) {
gameState = "Distributing";
initiateDistributionInstance(getSelectOn());
}
break;
case 'I':
ai.displayArrays();
break;
}
}
public void DisplayWinner() {
if (m_bowls[player1Pool] == m_bowls[player2Pool])
System.out.println("Tie Game!");
else {
int winner;
if (m_bowls[player1Pool] > m_bowls[player2Pool])
winner = 1;
else
winner = 2;
System.out.println("Player " + winner + " Wins!");
}
}
private boolean AIMove(int index) {
boolean flag = false;
if (SelectOn < index)
10. SelectOn++;
if (SelectOn > index)
SelectOn--;
else if (SelectOn == index)
flag = true;
return flag;
}
private void handleAI(int Player) {
boolean flag = false;
System.out.println(gameState);
if (Player == 1) {
flag = AIMove(ai.getPlayer1Decision());
}
if (Player == 2) {
flag = AIMove(ai.getPlayer2Decision());
}
if (flag) {
gameState = "Distributing";
initiateDistributionInstance(getSelectOn());
}
if (gameState == "AI") {
Sleep(500);
}
}
public void Sleep(long SleepTime) {
try {
Thread.sleep(SleepTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getBowl(int index) {
if (index == SelectOn)
return "(" + m_bowls[index] + ")";
else
11. return " " + m_bowls[index];
}
public int getBowlLocationX(int index) {
return m_bowlLocations[index].getX();
}
public int getBowlLocationY(int index) {
return m_bowlLocations[index].getY();
}
public int getGameSize() {
return m_bowls.length;
}
public String getGameState() {
return gameState;
}
}
Save file as AI.java
package main;
public class AI {
private boolean ExtraTurnAvailable[];
private boolean StealAvailable[];
private boolean StealReachable[];
private boolean ExtraTurnSetupAvailable[];
private boolean LargestBowl[];
private int DecisionPriority[];
private boolean StealRuin[];
private int P1Decision, P2Decision;
private int GameBoard[];
public AI(int a_bowls[]) {
ExtraTurnAvailable = new boolean[14];
StealAvailable = new boolean[14];
StealReachable = new boolean[14];
ExtraTurnSetupAvailable = new boolean[14];
LargestBowl = new boolean[14];
StealRuin = new boolean[14];
DecisionPriority = new int[14];
initializeArrays();
12. P1Decision = 0;
P2Decision = 7;
GameBoard = new int[14];
updateGameBoard(a_bowls);
}
public void initializeArrays() {
for (int i = 0; i < ExtraTurnAvailable.length; i++) {
ExtraTurnAvailable[i] = false;
StealAvailable[i] = false;
StealReachable[i] = false;
ExtraTurnSetupAvailable[i] = false;
LargestBowl[i] = false;
StealRuin[i] = false;
DecisionPriority[i] = 0;
}
}
public void updateGameBoard(int a_bowls[]) {
for (int i = 0; i < a_bowls.length; i++) {
GameBoard[i] = a_bowls[i];
}
}
public void update(int a_bowls[]) {
updateGameBoard(a_bowls);
Evaluate();
makeDecision();
}
private void Evaluate() {
// check entire board for extra turns
initializeArrays();
// check entire board for extra turns
EvaluateExtraTurns();
// check row for steals
EvaluateSteals();
// if a steal is available, check if there are any bowls that can reach it
EvaluateReachableSteals();
// find out which bowls set up extra turns
13. EvaluateExtraTurnSetupOpportunities();
// find out which bowl sets up an optimum steal
EvaluateLargestBowl();
// find out where to ruin steal opportunities
EvaluateStealRuinOpportunities();
// find out where to ruin extra turns
EvaluateExtraTurnRuinOpportunities();
}
private void EvaluateExtraTurns() {
for (int i = 0; i < 13; i++) {
if (i != 6 && i != 13) {
if (i < 6) {
if (GameBoard[i] == 5 - i + 1) {
ExtraTurnAvailable[i] = true;
}
}
if (i > 6) {
if (GameBoard[i] == 12 - i + 1) {
ExtraTurnAvailable[i] = true;
}
}
}
}
}
private void EvaluateSteals() {
for (int i = 0; i < 13; i++) {
if (i != 6 && i != 13) {
if (GameBoard[i] == 0 && GameBoard[12 - i] > 0) {
StealAvailable[i] = true;
}
}
}
}
private void EvaluateReachableSteals() {
for (int i = 0; i < 13; i++) {
if (StealAvailable[i] == true) {
14. if (i < 6) {
for (int c = i; c >= 0; c--) {
if (GameBoard[c] == i - c && GameBoard[c] != 0) {
StealReachable[c] = true;
}
}
}
if (i > 6) {
for (int c = i; c > 6; c--) {
if (GameBoard[c] == i - c && GameBoard[c] != 0) {
StealReachable[c] = true;
}
}
}
}
}
}
private void EvaluateExtraTurnSetupOpportunities() {
for (int i = 0; i < 13; i++) {
if (i != 6 && i != 13) {
if (i < 6) {
for (int c = 0; c < 6; c++) {
if (i < c && GameBoard[c] == 5 - c
&& GameBoard[i] >= c - i) {
ExtraTurnSetupAvailable[i] = true;
}
}
if (i > 6) {
for (int c = 7; c < 12; c++) {
if (i < c && GameBoard[c] == 12 - c
&& GameBoard[i] >= c - i) {
ExtraTurnSetupAvailable[i] = true;
}
}
}
}
15. }
}
}
private void EvaluateLargestBowl() {
// find the bowl with the greatest number of beads on both sides
int LargestValueIndex1 = 0, LargestValueIndex2 = 7;
for (int i = 0; i < 6; i++) {
if (GameBoard[i] >= GameBoard[LargestValueIndex1])
LargestValueIndex1 = i;
}
for (int i = 7; i < 13; i++) {
if (GameBoard[i] >= GameBoard[LargestValueIndex2])
LargestValueIndex2 = i;
}
LargestBowl[LargestValueIndex1] = true;
LargestBowl[LargestValueIndex2] = true;
}
private void EvaluateStealRuinOpportunities() {
// check if any bowls can reach a steal reachable bowl
for (int i = 0; i < 13; i++) {
if (StealReachable[i] == true) {
if (i > 6) {
for (int c = i; c >= 0; c--) {
if (GameBoard[c] == i - c && GameBoard[c] != 0) {
StealRuin[c] = true;
}
}
}
if (i < 6) {
for (int c = 7; c < 12; c++) {
if (GameBoard[c] + c > 13 && GameBoard[c] != 0) {
if (GameBoard[c] + c - 13 == i) {
StealRuin[GameBoard[c] + c - 13] = true;
}
}
}
16. }
}
}
}
private void EvaluateExtraTurnRuinOpportunities() {
// check if any bowls can reach a extra turn bowl
}
private void makeDecision() {
for (int i = 0; i < 13; i++) {
if (ExtraTurnSetupAvailable[i])
DecisionPriority[i]++;
if (LargestBowl[i])
DecisionPriority[i]++;
}
// prioritize extra turns
int counter1 = 0, counter2 = 0;
for (int i = 0; i < 13; i++) {
if (i < 6) {
if (ExtraTurnAvailable[i])
counter1++;
}
if(i > 6){
if(ExtraTurnAvailable[i])
counter2++;
}
}
if(counter1 < 4) counter1 = 4;
if(counter2 < 4) counter2 = 4;
for (int i = 5; i >= 0; i--){
if(ExtraTurnAvailable[i]){
DecisionPriority[i] = counter1;
counter1--;
}
}
for(int i = 12; i > 6; i--){
if(ExtraTurnAvailable[i]){
17. DecisionPriority[i] = counter2;
counter2--;
}
}
// prioritize Steals
counter1 = 0;
counter2 = 0;
for (int i = 0; i < 13; i++) {
if (i < 6) {
if (StealReachable[i])
counter1++;
}
if(i > 6){
if(StealReachable[i])
counter2++;
}
}
if(counter1 < 4) counter1 = 4;
if(counter2 < 4) counter2 = 4;
for (int i = 5; i >= 0; i--){
if(StealReachable[i]){
DecisionPriority[i] = counter1;
counter1--;
}
}
for(int i = 12; i > 6; i--){
if(StealReachable[i]){
DecisionPriority[i] = counter2;
counter2--;
}
}
// add one kudos if the steal reachable is greater than one
for (int i = 0; i < 13; i++) {
if (i < 6) {
if (StealReachable[i]) {
for (int c = i + 1; c < 6; c++) {
18. if (GameBoard[c] == i - c && StealAvailable[c]
&& GameBoard[c] > 1) {
DecisionPriority[i]++;
}
}
}
}
if (i > 6) {
for (int c = i + 1; c < 13; c++) {
if (StealReachable[i]) {
if (GameBoard[c] == i - c && StealAvailable[c]
&& GameBoard[c] > 1) {
DecisionPriority[i]++;
}
}
}
}
}
// remove kudos if they interfere with each other
for (int i = 0; i < 13; i++) {
if (i < 6) {
// remove kudos if steals interfere with extra turns
for (int c = i + 1; c < 6; c++) {
if (StealReachable[i]) {
if (GameBoard[c] >= i - c && ExtraTurnAvailable[c]) {
DecisionPriority[i]--;
}
}
}
// remove kudos if extra turns interfere with steals
for (int c = i + 1; c < 6; c++) {
if (ExtraTurnAvailable[i]) {
if (GameBoard[c] >= i - c && StealReachable[c]) {
DecisionPriority[i]--;
}
}
19. }
}
if (i > 6) {
// remove kudos if steals interfere with extra turns
for (int c = i + 1; c < 13; c++) {
if (StealReachable[i]) {
if (GameBoard[c] >= i - c && ExtraTurnAvailable[c]) {
DecisionPriority[i]--;
}
}
}
// remove kudos if extra turns interfere with steals
for (int c = i + 1; c < 13; c++) {
if (ExtraTurnAvailable[i]) {
if (GameBoard[c] >= i - c && StealReachable[c]) {
DecisionPriority[i]--;
}
}
}
}
}
if (ExtraTurnAvailable[5])
P1Decision = 5;
else {
for (int i = 0; i < 6; i++) {
if (DecisionPriority[i] > DecisionPriority[P1Decision])
P1Decision = i;
}
}
if (ExtraTurnAvailable[12])
P2Decision = 12;
else {
for (int i = 7; i < 13; i++) {
if (DecisionPriority[i] > DecisionPriority[P2Decision])
P2Decision = i;
}