In: Computer Science
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