SlideShare a Scribd company logo
1 of 23
Download to read offline
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();
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();
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 {
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) {
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
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++;
}
}
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;
}
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();
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)
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
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();
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
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) {
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;
}
}
}
}
}
}
}
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;
}
}
}
}
}
}
}
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]){
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++) {
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]--;
}
}
}
}
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;
}
}
}
public int getPlayer1Decision() {
return P1Decision;
}
public int getPlayer2Decision() {
return P2Decision;
}
public void displayArrays() {
// Display Extra Turns Available
System.out.print("Extra Turns Available: ");
displayPlayerOptions(ExtraTurnAvailable);
// Display Steals Available
System.out.print("Steals Available: ");
displayPlayerOptions(StealAvailable);
// Display Steal Opportunities Reachable
System.out.print("Steal Opportunities Reachable: ");
displayPlayerOptions(StealReachable);
// Display Extra Turn Setup Opportunities
System.out.print("Extra Turn Setup Opportunities: ");
displayPlayerOptions(ExtraTurnSetupAvailable);
// Display Steal Priorities
System.out.print("Largest Bowls: ");
displayPlayerOptions(LargestBowl);
// Display Steal Priorities
System.out.print("Steal Ruin Opportunities: ");
displayPlayerOptions(StealRuin);
// Display DecisionPriority
System.out.print("Decision Priorities: ");
displayPlayerOptionsInt(DecisionPriority);
// Display P1 Decision
System.out.println("Player 1 Decision: " + P1Decision);
// Display P2 Decision
System.out.println("Player 2 Decision: " + P2Decision);
}
private void displayPlayer1Options(boolean a_array[]) {
for (int i = 0; i < 6; i++) {
int output;
if (a_array[i])
output = 1;
else
output = 0;
System.out.print(output + " ");
}
}
private void displayPlayer2Options(boolean a_array[]) {
for (int i = 12; i > 6; i--) {
int output;
if (a_array[i])
output = 1;
else
output = 0;
System.out.print(output + " ");
}
}
private void displayPlayerOptions(boolean a_array[]) {
displayPlayer1Options(a_array);
System.out.print(" ");
displayPlayer2Options(a_array);
System.out.println();
}
private void displayPlayer1OptionsInt(int a_array[]) {
for (int i = 0; i < 6; i++) {
System.out.print(a_array[i] + " ");
}
}
private void displayPlayer2OptionsInt(int a_array[]) {
for (int i = 12; i > 6; i--) {
System.out.print(a_array[i] + " ");
}
}
private void displayPlayerOptionsInt(int a_array[]) {
displayPlayer1OptionsInt(a_array);
System.out.print(" ");
displayPlayer2OptionsInt(a_array);
System.out.println();
}
}
File save as XY.java (for marquee and all)
package main;
public class XY {
public int x, y;
public XY(int a_x, int a_y)
{
setX(a_x);
setY(a_y);
}
public XY()
{
setX(0);
setY(0);
}
public void set(int a_x, int a_y)
{
setX(a_x);
setY(a_y);
}
public void setX(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return y;
}
}

More Related Content

Similar to PLEASE can do this in NETBEAN I need that way thank very muchManca.pdf

public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
kavithaarp
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
ezzi97
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
trishulinoverseas1
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
trishulinoverseas1
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
info430661
 
this is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdfthis is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdf
arjunstores123
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
manjan6
 

Similar to PLEASE can do this in NETBEAN I need that way thank very muchManca.pdf (9)

public interface Game Note interface in place of class { .pdf
public interface Game  Note interface in place of class { .pdfpublic interface Game  Note interface in place of class { .pdf
public interface Game Note interface in place of class { .pdf
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
this is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdfthis is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdf
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Python find ajacent symbols recursively
Python find ajacent symbols recursivelyPython find ajacent symbols recursively
Python find ajacent symbols recursively
 

More from kennithdase

which of the following approaches to science would not be appropr.pdf
which of the following approaches to science would not be appropr.pdfwhich of the following approaches to science would not be appropr.pdf
which of the following approaches to science would not be appropr.pdf
kennithdase
 
When you look at different stages of mitosis, why are the chromosome.pdf
When you look at different stages of mitosis, why are the chromosome.pdfWhen you look at different stages of mitosis, why are the chromosome.pdf
When you look at different stages of mitosis, why are the chromosome.pdf
kennithdase
 
What is a representation letter What are its parts and what is it .pdf
What is a representation letter What are its parts and what is it .pdfWhat is a representation letter What are its parts and what is it .pdf
What is a representation letter What are its parts and what is it .pdf
kennithdase
 
The problem with our democratic institutions is that they dont cor.pdf
The problem with our democratic institutions is that they dont cor.pdfThe problem with our democratic institutions is that they dont cor.pdf
The problem with our democratic institutions is that they dont cor.pdf
kennithdase
 
PRIVACY Does informations availability justify its useGovernme.pdf
PRIVACY Does informations availability justify its useGovernme.pdfPRIVACY Does informations availability justify its useGovernme.pdf
PRIVACY Does informations availability justify its useGovernme.pdf
kennithdase
 
Select one country and list 5 elements of its cultural environment. .pdf
Select one country and list 5 elements of its cultural environment. .pdfSelect one country and list 5 elements of its cultural environment. .pdf
Select one country and list 5 elements of its cultural environment. .pdf
kennithdase
 

More from kennithdase (20)

Cryptography has been around for hundreds of years. The measure of h.pdf
Cryptography has been around for hundreds of years. The measure of h.pdfCryptography has been around for hundreds of years. The measure of h.pdf
Cryptography has been around for hundreds of years. The measure of h.pdf
 
Chemical germicidesmay react irreversibly with proteinsenzymes..pdf
Chemical germicidesmay react irreversibly with proteinsenzymes..pdfChemical germicidesmay react irreversibly with proteinsenzymes..pdf
Chemical germicidesmay react irreversibly with proteinsenzymes..pdf
 
With the Diffie-Hellman Key Exchange approach, could one participant.pdf
With the Diffie-Hellman Key Exchange approach, could one participant.pdfWith the Diffie-Hellman Key Exchange approach, could one participant.pdf
With the Diffie-Hellman Key Exchange approach, could one participant.pdf
 
which vessel carries blood to the glomerulusSolutionAnswerA.pdf
which vessel carries blood to the glomerulusSolutionAnswerA.pdfwhich vessel carries blood to the glomerulusSolutionAnswerA.pdf
which vessel carries blood to the glomerulusSolutionAnswerA.pdf
 
which of the following approaches to science would not be appropr.pdf
which of the following approaches to science would not be appropr.pdfwhich of the following approaches to science would not be appropr.pdf
which of the following approaches to science would not be appropr.pdf
 
When you look at different stages of mitosis, why are the chromosome.pdf
When you look at different stages of mitosis, why are the chromosome.pdfWhen you look at different stages of mitosis, why are the chromosome.pdf
When you look at different stages of mitosis, why are the chromosome.pdf
 
What is the intent and what is the importance of Article 48 of the W.pdf
What is the intent and what is the importance of Article 48 of the W.pdfWhat is the intent and what is the importance of Article 48 of the W.pdf
What is the intent and what is the importance of Article 48 of the W.pdf
 
What is Computer System Validation and Why is it ImportantSolut.pdf
What is Computer System Validation and Why is it ImportantSolut.pdfWhat is Computer System Validation and Why is it ImportantSolut.pdf
What is Computer System Validation and Why is it ImportantSolut.pdf
 
What feature can you enable in Windows Server 2012 R2 to reduce the .pdf
What feature can you enable in Windows Server 2012 R2 to reduce the .pdfWhat feature can you enable in Windows Server 2012 R2 to reduce the .pdf
What feature can you enable in Windows Server 2012 R2 to reduce the .pdf
 
What is a representation letter What are its parts and what is it .pdf
What is a representation letter What are its parts and what is it .pdfWhat is a representation letter What are its parts and what is it .pdf
What is a representation letter What are its parts and what is it .pdf
 
The problem with our democratic institutions is that they dont cor.pdf
The problem with our democratic institutions is that they dont cor.pdfThe problem with our democratic institutions is that they dont cor.pdf
The problem with our democratic institutions is that they dont cor.pdf
 
The picture below is of two oak leaves taken from the same tree. Leaf.pdf
The picture below is of two oak leaves taken from the same tree. Leaf.pdfThe picture below is of two oak leaves taken from the same tree. Leaf.pdf
The picture below is of two oak leaves taken from the same tree. Leaf.pdf
 
The acoustic intensity I is defined as the average acoustic pressure .pdf
The acoustic intensity I is defined as the average acoustic pressure .pdfThe acoustic intensity I is defined as the average acoustic pressure .pdf
The acoustic intensity I is defined as the average acoustic pressure .pdf
 
PRIVACY Does informations availability justify its useGovernme.pdf
PRIVACY Does informations availability justify its useGovernme.pdfPRIVACY Does informations availability justify its useGovernme.pdf
PRIVACY Does informations availability justify its useGovernme.pdf
 
Small canals that connect osteocytes in their lacunae to the central .pdf
Small canals that connect osteocytes in their lacunae to the central .pdfSmall canals that connect osteocytes in their lacunae to the central .pdf
Small canals that connect osteocytes in their lacunae to the central .pdf
 
Select one country and list 5 elements of its cultural environment. .pdf
Select one country and list 5 elements of its cultural environment. .pdfSelect one country and list 5 elements of its cultural environment. .pdf
Select one country and list 5 elements of its cultural environment. .pdf
 
Sampling distribution of x is theA. mean of the sampleB. Mean of.pdf
Sampling distribution of x is theA. mean of the sampleB. Mean of.pdfSampling distribution of x is theA. mean of the sampleB. Mean of.pdf
Sampling distribution of x is theA. mean of the sampleB. Mean of.pdf
 
polyalkenes aggregate fruit, polydrupes aggregate fruit, multiple fr.pdf
polyalkenes aggregate fruit, polydrupes aggregate fruit, multiple fr.pdfpolyalkenes aggregate fruit, polydrupes aggregate fruit, multiple fr.pdf
polyalkenes aggregate fruit, polydrupes aggregate fruit, multiple fr.pdf
 
Path QUESTION 12 The theory that adolescents pick fri.pdf
Path QUESTION 12 The theory that adolescents pick fri.pdfPath QUESTION 12 The theory that adolescents pick fri.pdf
Path QUESTION 12 The theory that adolescents pick fri.pdf
 
Please look up the following terms and define each, also give some or.pdf
Please look up the following terms and define each, also give some or.pdfPlease look up the following terms and define each, also give some or.pdf
Please look up the following terms and define each, also give some or.pdf
 

Recently uploaded

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 

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; }
  • 20. } } public int getPlayer1Decision() { return P1Decision; } public int getPlayer2Decision() { return P2Decision; } public void displayArrays() { // Display Extra Turns Available System.out.print("Extra Turns Available: "); displayPlayerOptions(ExtraTurnAvailable); // Display Steals Available System.out.print("Steals Available: "); displayPlayerOptions(StealAvailable); // Display Steal Opportunities Reachable System.out.print("Steal Opportunities Reachable: "); displayPlayerOptions(StealReachable); // Display Extra Turn Setup Opportunities System.out.print("Extra Turn Setup Opportunities: "); displayPlayerOptions(ExtraTurnSetupAvailable); // Display Steal Priorities System.out.print("Largest Bowls: "); displayPlayerOptions(LargestBowl); // Display Steal Priorities System.out.print("Steal Ruin Opportunities: "); displayPlayerOptions(StealRuin); // Display DecisionPriority System.out.print("Decision Priorities: "); displayPlayerOptionsInt(DecisionPriority); // Display P1 Decision System.out.println("Player 1 Decision: " + P1Decision); // Display P2 Decision System.out.println("Player 2 Decision: " + P2Decision); } private void displayPlayer1Options(boolean a_array[]) {
  • 21. for (int i = 0; i < 6; i++) { int output; if (a_array[i]) output = 1; else output = 0; System.out.print(output + " "); } } private void displayPlayer2Options(boolean a_array[]) { for (int i = 12; i > 6; i--) { int output; if (a_array[i]) output = 1; else output = 0; System.out.print(output + " "); } } private void displayPlayerOptions(boolean a_array[]) { displayPlayer1Options(a_array); System.out.print(" "); displayPlayer2Options(a_array); System.out.println(); } private void displayPlayer1OptionsInt(int a_array[]) { for (int i = 0; i < 6; i++) { System.out.print(a_array[i] + " "); } } private void displayPlayer2OptionsInt(int a_array[]) { for (int i = 12; i > 6; i--) { System.out.print(a_array[i] + " "); } } private void displayPlayerOptionsInt(int a_array[]) {
  • 22. displayPlayer1OptionsInt(a_array); System.out.print(" "); displayPlayer2OptionsInt(a_array); System.out.println(); } } File save as XY.java (for marquee and all) package main; public class XY { public int x, y; public XY(int a_x, int a_y) { setX(a_x); setY(a_y); } public XY() { setX(0); setY(0); } public void set(int a_x, int a_y) { setX(a_x); setY(a_y); } public void setX(int x) { this.x = x; } public int getX() { return x; } public void setY(int y) { this.y = y; } public int getY() { return y;
  • 23. } }