Question

In: Computer Science

**NEED ACTUAL JAVA CODE** Basically this code is defining the board for the game tigers and...

**NEED ACTUAL JAVA CODE**

Basically this code is defining the board for the game tigers and goats or 'Bagh chan'.

Ive posted the other 3 classes that I need help with, didnt want to put all 4 in one question.

/**
* Maintains and updates the status of the board
* i.e. the locations of goats and tigers
*
* @Student 1 Name:
* @Student 1 Number:
*
* @Student 2 Name:
* @Student 2 Number:
*/
public class Board
{
// An enumated type for the three possibilities
private enum Piece {GOAT, TIGER, VACANT};
// 1-D Array representation of the board. Top left is 0,
// then goes anti-clockwise spiraling inward until 23
Piece[] board;

/**
* Constructor for objects of class Board.
* Initializes the board VACANT.
*/
public Board()
{
// TODO 3
  
}

  
/**
* Checks if the location a is VACANT on the board
*/
public boolean isVacant(int a)
{
//TODO 4
return false;
}
  
/**
* Sets the location a on the board to VACANT
*/
public void setVacant(int a)
{
//TODO 5
  
}
  
/**
* Checks if the location a on the board is a GOAT
*/
public boolean isGoat(int a)
{
//TODO 6
return false;
}
  
/**
* Sets the location a on the board to GOAT
*/
public void setGoat(int a)
{
//TODO 7
  
}
  
/**
* Sets the location a on the board to TIGER
*/
public void setTiger(int a)
{
a.tigerPos = []
for idx, p in enumerate(a.points):
if p.get_state() == Point.State.T:
a.tigerPos.append(idx)
assert len(self.tigerPos) == 4
  
}
  
/**
* Moves a piece by swaping the contents of a and b
*/
public void swap(int a, int b)
{
//TODO 9
  
}
}

Solutions

Expert Solution

package com.company;

public class Board
{
// An enumated type for the three possibilities
private enum Piece {GOAT, TIGER, VACANT};
// 1-D Array representation of the board. Top left is 0,
// then goes anti-clockwise spiraling inward until 23
Piece[] board;

/**
* Constructor for objects of class Board.
* Initializes the board VACANT.
*/
public Board()
{
// TODO 3
board = new Piece[24];
for (int i =0;i < 24; i ++)
board[i] = Piece.VACANT;
}


/**
* Checks if the location a is VACANT on the board
*/
public boolean isVacant(int a)
{
//TODO 4
return board[a] == Piece.VACANT;
}

/**
* Sets the location a on the board to VACANT
*/
public void setVacant(int a)
{
//TODO 5
board[a] = Piece.VACANT;
}

/**
* Checks if the location a on the board is a GOAT
*/
public boolean isGoat(int a)
{
//TODO 6
return board[a] == Piece.GOAT;
}

/**
* Sets the location a on the board to GOAT
*/
public void setGoat(int a)
{
//TODO 7
board[a] = Piece.GOAT;
}

/**
* Sets the location a on the board to TIGER
*/
public void setTiger(int a)
{
// This is original Python code
a.tigerPos = []
for idx, p in enumerate(a.points):
if( p.get_state() == Point.State.T)
a.tigerPos.append(idx)
assert(len(self.tigerPos) == 4);

// This is newly written Java code
board[a] = Piece.TIGER;
}

/**
* Moves a piece by swaping the contents of a and b
*/
public void swap(int a, int b)
{
//TODO 9
Piece temp = board[a];
board[a] = board[b];
board[b] = temp;
}
}

I have written my code where there is TODO and also in setTiger but is well commented


Related Solutions

**NEED ACTUAL JAVA CODE** Basically this code is defining the board for the game tigers and...
**NEED ACTUAL JAVA CODE** Basically this code is defining the board for the game tigers and goats or 'Bagh chan'. Ive posted the other 3 classes that I need help with, didnt want to put all 4 in one question. public class GameViewer implements MouseListener { // instance variables private int bkSize; // block size - all other measurements to be derived from bkSize private int brdSize; // board size private SimpleCanvas sc; // an object of SimpleCanvas to draw...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Need to fix this code for tc -tac-toe game .. see the code below and fix...
Need to fix this code for tc -tac-toe game .. see the code below and fix it #include <iostream> using namespace std; void display_board(); void player_turn(); bool gameover (); char turn ; bool draw = false; char board [3][3] = { {'1', '2', '3'}, { '4', '5', '6'}, { '7', '8', '9'}}; int main() { cout << " Lets play Tc- Tac- toe game " <<endl ; cout << " Player 1 [X] ----- player 2 [0] " <<endl <<endl;...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
Could we turn this java code into a GUI game? Add a orange and a green...
Could we turn this java code into a GUI game? Add a orange and a green trophy object. Orange trophy costs 15 clicks and every time we buy a orange trophy price increases by * 1.09. Green trophy costs 100 clicks and every time we buy a green trophy price increases by * 1.09. Example: you would click the button 15 times in order to be allowed to buy the orange trophy then it resets but then the cost becomes...
Could we turn this java code into a GUI game? Add a orange and a green...
Could we turn this java code into a GUI game? Add a orange and a green trophy object. Orange trophy costs 15 clicks and every time we buy a orange trophy price increases by * 1.09. Green trophy costs 100 clicks and every time we buy a green trophy price increases by * 1.09. Example: you would click the button 15 times in order to be allowed to buy the orange trophy then it resets but then the cost becomes...
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
I need a Verilog code that makes the LEDs on the FPGA board works like this....
I need a Verilog code that makes the LEDs on the FPGA board works like this. https://image.ibb.co/mu5tnS/6.gif There are 16 LEDs in the FPGA board
Hi! I need it in android studio and in java Design a game app “BouncingBall ”...
Hi! I need it in android studio and in java Design a game app “BouncingBall ” in which the user’s goal is to prevent a bouncing ball from falling off the bottom of the screen. When the user presses the start button, a ball bounces off the top, left and right sides (the “walls”) of the screen. A horizontal bar on the bottom of the screen serves as a paddle to prevent the ball from hitting the bottom of the...
Hi! I need it in android studio and in java Design a game app “BouncingBall ”...
Hi! I need it in android studio and in java Design a game app “BouncingBall ” in which the user’s goal is to prevent a bouncing ball from falling off the bottom of the screen. When the user presses the start button, a ball bounces off the top, left and right sides (the “walls”) of the screen. A horizontal bar on the bottom of the screen serves as a paddle to prevent the ball from hitting the bottom of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT