<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FProjects%2FOcean%2FOcean.java</id>
	<title>Computer Science/61b/Projects/Ocean/Ocean.java - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FProjects%2FOcean%2FOcean.java"/>
	<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;action=history"/>
	<updated>2026-05-03T02:23:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=24423&amp;oldid=prev</id>
		<title>Lensovet: Lensovet moved page CS/61b/Projects/Ocean/Ocean.java to Computer Science/61b/Projects/Ocean/Ocean.java</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=24423&amp;oldid=prev"/>
		<updated>2023-02-20T03:51:36Z</updated>

		<summary type="html">&lt;p&gt;Lensovet moved page &lt;a href=&quot;/~sysadmin/w/CS/61b/Projects/Ocean/Ocean.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Projects/Ocean/Ocean.java&quot;&gt;CS/61b/Projects/Ocean/Ocean.java&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/Computer_Science/61b/Projects/Ocean/Ocean.java&quot; title=&quot;Computer Science/61b/Projects/Ocean/Ocean.java&quot;&gt;Computer Science/61b/Projects/Ocean/Ocean.java&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:51, 20 February 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=3961&amp;oldid=prev</id>
		<title>Lensovet: moved CS 61b/Projects/Ocean/Ocean.java to CS/61b/Projects/Ocean/Ocean.java:&amp;#32;fix CS 61b hierarchy</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=3961&amp;oldid=prev"/>
		<updated>2010-11-14T05:59:46Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/~sysadmin/w/CS_61b/Projects/Ocean/Ocean.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS 61b/Projects/Ocean/Ocean.java&quot;&gt;CS 61b/Projects/Ocean/Ocean.java&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/CS/61b/Projects/Ocean/Ocean.java&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Projects/Ocean/Ocean.java&quot;&gt;CS/61b/Projects/Ocean/Ocean.java&lt;/a&gt;: fix CS 61b hierarchy&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 05:59, 14 November 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=2243&amp;oldid=prev</id>
		<title>Lensovet at 03:21, 14 November 2006</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Projects/Ocean/Ocean.java&amp;diff=2243&amp;oldid=prev"/>
		<updated>2006-11-14T03:21:19Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{code}}&lt;br /&gt;
 /* Ocean.java */&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *  The Ocean class defines an object that models an ocean full of sharks and&lt;br /&gt;
  *  fish.  Descriptions of the methods you must implement appear below.  They&lt;br /&gt;
  *  include a constructor of the form&lt;br /&gt;
  *&lt;br /&gt;
  *      public Ocean(int i, int j, int starveTime);&lt;br /&gt;
  *&lt;br /&gt;
  *  that creates an empty ocean having width i and height j, in which sharks&lt;br /&gt;
  *  starve after starveTime timesteps.&lt;br /&gt;
  *&lt;br /&gt;
  *  See the README file accompanying this project for additional details.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 public class Ocean {&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	*  Do not rename these constants.  WARNING:  if you change the numbers, you&lt;br /&gt;
 	*  will need to recompile Test4.java.  Failure to do so will give you a very&lt;br /&gt;
 	*  hard-to-find bug.&lt;br /&gt;
 	*/&lt;br /&gt;
 	&lt;br /&gt;
 	public final static int EMPTY = 0;&lt;br /&gt;
 	public final static int SHARK = 1;&lt;br /&gt;
 	public final static int FISH = 2;&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	*  Define any variables associated with an Ocean object here.  These&lt;br /&gt;
 	*  variables MUST be private.&lt;br /&gt;
 	*/&lt;br /&gt;
 	&lt;br /&gt;
 	private int x;&lt;br /&gt;
 	private int y;&lt;br /&gt;
 	private int starvetime;&lt;br /&gt;
 	private int[] cells;&lt;br /&gt;
 	private int[] hunger;&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  The following methods are required for Part I.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	/** &lt;br /&gt;
 		* Given an x &amp;amp; y coordinate, returns the cell's index in an ocean array&lt;br /&gt;
 		* if either coordinate is out of bounds due to the ocean's size, convert it accordingly&lt;br /&gt;
 		* @param x is the x-coord; @param y is the y-coord of the cell&lt;br /&gt;
 		* @return the index in the array&lt;br /&gt;
 		**/&lt;br /&gt;
 	public int cellind(int x, int y) {&lt;br /&gt;
 		x = x%this.x; //  Math.abs(x)%this.x; gives incorrect values&lt;br /&gt;
 		y = y%this.y;&lt;br /&gt;
 		if (x &amp;lt; 0) { x = x+this.x; }&lt;br /&gt;
 		if (y &amp;lt; 0) { y = y+this.y; }&lt;br /&gt;
 		int ind = this.x*y+x;&lt;br /&gt;
 		return ind;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/** @param pos is the index in the ocean array&lt;br /&gt;
 		the methods below convert an array index into an x and y coordinate, respectively **/&lt;br /&gt;
 	&lt;br /&gt;
 	public int coordx(int pos) {&lt;br /&gt;
 		int i = pos%x;&lt;br /&gt;
 		return i; }&lt;br /&gt;
   	&lt;br /&gt;
 	public int coordy(int pos) {&lt;br /&gt;
 		int j = pos/x;&lt;br /&gt;
 		return j; }&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  Ocean() is a constructor that creates an empty ocean having width i and&lt;br /&gt;
 	 *  height j, in which sharks starve after starveTime timesteps.&lt;br /&gt;
 	 *  @param i is the width of the ocean.&lt;br /&gt;
 	 *  @param j is the height of the ocean.&lt;br /&gt;
 	 *  @param starveTime is the number of timesteps sharks survive without food.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public Ocean(int i, int j, int starveTime) {&lt;br /&gt;
 		x = i;&lt;br /&gt;
 		y = j;&lt;br /&gt;
 		starvetime = starveTime;&lt;br /&gt;
 		cells = new int[i*j];&lt;br /&gt;
 		for (int ic=0; ic&amp;lt;cells.length; ic++) { cells[ic] = EMPTY; } // all cells EMPTY by default&lt;br /&gt;
 		hunger = new int[i*j];&lt;br /&gt;
 		for (int ih=0; ih&amp;lt;hunger.length; ih++) { hunger[ih] = 0; } // hunger of all cells 0 by default&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  width() returns the width of an Ocean object.&lt;br /&gt;
 	 *  @return the width of the ocean.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public int width() {&lt;br /&gt;
 		return x;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  height() returns the height of an Ocean object.&lt;br /&gt;
 	 *  @return the height of the ocean.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public int height() {&lt;br /&gt;
 		return y;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  starveTime() returns the number of timesteps sharks survive without food.&lt;br /&gt;
 	 *  @return the number of timesteps sharks survive without food.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public int starveTime() {&lt;br /&gt;
 		return starvetime;&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  addFish() places a fish in cell (x, y) if the cell is empty.  If the&lt;br /&gt;
 	 *  cell is already occupied, leave the cell as it is.&lt;br /&gt;
 	 *  @param x is the x-coordinate of the cell to place a fish in.&lt;br /&gt;
 	 *  @param y is the y-coordinate of the cell to place a fish in.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public void addFish(int x, int y) {&lt;br /&gt;
 		if (cells[this.cellind(x,y)] == EMPTY) {&lt;br /&gt;
 			cells[this.cellind(x,y)] = FISH;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  addShark() (with two parameters) places a newborn shark in cell (x, y) if&lt;br /&gt;
 	 *  the cell is empty.  A &amp;quot;newborn&amp;quot; shark is equivalent to a shark that has&lt;br /&gt;
 	 *  just eaten.  If the cell is already occupied, leave the cell as it is.&lt;br /&gt;
 	 *  @param x is the x-coordinate of the cell to place a shark in.&lt;br /&gt;
 	 *  @param y is the y-coordinate of the cell to place a shark in.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public void addShark(int x, int y) {&lt;br /&gt;
 		int curpos = this.cellind(x,y);&lt;br /&gt;
 		if (cells[curpos] == EMPTY) {&lt;br /&gt;
 			cells[curpos] = SHARK;&lt;br /&gt;
 			hunger[curpos] = starvetime;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  cellContents() returns EMPTY if cell (x, y) is empty, FISH if it contains&lt;br /&gt;
 	 *  a fish, and SHARK if it contains a shark.&lt;br /&gt;
 	 *  @param x is the x-coordinate of the cell whose contents are queried.&lt;br /&gt;
 	 *  @param y is the y-coordinate of the cell whose contents are queried.&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	public int cellContents(int x, int y) {&lt;br /&gt;
 		return cells[this.cellind(x,y)]; // simply return the contents at the given index&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/**&lt;br /&gt;
 	 *  timeStep() performs a simulation timestep as described in README.&lt;br /&gt;
 	 *  @return an ocean representing the elapse of one timestep.&lt;br /&gt;
 	 * required actions:&lt;br /&gt;
 	 *  1) If a cell contains a shark, and any of its neighbors is a fish, then the&lt;br /&gt;
 	 *  shark eats during the timestep, and it remains in the cell at the end of the&lt;br /&gt;
 	 *  timestep.  (We may have multiple sharks sharing the same fish.  This is fine;&lt;br /&gt;
 	 *  they all get enough to eat.)   &lt;br /&gt;
 	 *  &lt;br /&gt;
 	 *  2) If a cell contains a shark, and none of its neighbors is a fish, it gets&lt;br /&gt;
 	 *  hungrier during the timestep.  If this timestep is the (starveTime + 1)th&lt;br /&gt;
 	 *  timestep the shark has gone through without eating, then the shark dies&lt;br /&gt;
 	 *  (disappears).  Otherwise, it remains in the cell.  An example demonstrating&lt;br /&gt;
 	 *  this rule appears below.   &lt;br /&gt;
 	 *  &lt;br /&gt;
 	 *  3) If a cell contains a fish, and all of its neighbors are either empty or are&lt;br /&gt;
 	 *  other fish, then the fish stays where it is.   &lt;br /&gt;
 	 *&lt;br /&gt;
 	 *  4) If a cell contains a fish, and one of its neighbors is a shark, then the&lt;br /&gt;
 	 *  fish is eaten by a shark, and therefore disappears.   &lt;br /&gt;
 	 *  &lt;br /&gt;
 	 *  5) If a cell contains a fish, and two or more of its neighbors are sharks, then&lt;br /&gt;
 	 *  a new shark is born in that cell.  Sharks are well-fed at birth; _after_ they&lt;br /&gt;
 	 *  are born, they can survive an additional starveTime timesteps without eating.&lt;br /&gt;
 	 *  (But they will die at the end of starveTime + 1 consecutive timesteps without&lt;br /&gt;
 	 *  eating.)  &lt;br /&gt;
 	 *  &lt;br /&gt;
 	 *  6) If a cell is empty, and fewer than two of its neighbors are fish, then the&lt;br /&gt;
 	 *  cell remains empty.&lt;br /&gt;
 	 *  &lt;br /&gt;
 	 *  7) If a cell is empty, at least two of its neighbors are fish, and at most one&lt;br /&gt;
 	 *  of its neighbors is a shark, then a new fish is born in that cell.&lt;br /&gt;
 	 *    &lt;br /&gt;
 	 *  8) If a cell is empty, at least two of its neighbors are fish, and at least two&lt;br /&gt;
 	 *  of its neighbors are sharks, then a new shark is born in that cell.  (The new&lt;br /&gt;
 	 *  shark is well-fed at birth, even though it hasn't eaten a fish yet.)&lt;br /&gt;
 	 */&lt;br /&gt;
 	&lt;br /&gt;
 	/** @return an array of neighbors around a given position **/&lt;br /&gt;
 	public int[] neighborarray(int pos) {&lt;br /&gt;
 		int[] array = new int[8];&lt;br /&gt;
 		int x = coordx(pos);&lt;br /&gt;
 		int y = coordy(pos);&lt;br /&gt;
 		array[0] = cellContents(x-1, y-1); // nw&lt;br /&gt;
 		array[1] = cellContents(x, y-1); // n&lt;br /&gt;
 		array[2] = cellContents(x+1, y-1); // ne&lt;br /&gt;
 		array[3] = cellContents(x+1, y); // e&lt;br /&gt;
 		array[4] = cellContents(x+1, y+1); // se&lt;br /&gt;
 		array[5] = cellContents(x, y+1); // s&lt;br /&gt;
 		array[6] = cellContents(x-1, y+1); // sw&lt;br /&gt;
 		array[7] = cellContents(x-1, y); // w&lt;br /&gt;
 		return array; }&lt;br /&gt;
 	&lt;br /&gt;
 	/** @return the number of neighbors of a given type around a given position **/&lt;br /&gt;
 	public int neighbor(int type, int pos) {&lt;br /&gt;
 		int[] array = neighborarray(pos);&lt;br /&gt;
 		int number = 0;&lt;br /&gt;
 		for (int i=0; i&amp;lt;array.length; i++) {&lt;br /&gt;
 			if (array[i] == type) { number++; } }&lt;br /&gt;
 		return number; }&lt;br /&gt;
 	&lt;br /&gt;
 	/** @return true if the method name's condition is satisfied around for a given position **/&lt;br /&gt;
 	public boolean caneat(int pos) { // 1 - If a cell contains a shark, and any of its neighbors is a fish&lt;br /&gt;
 		if (cells[pos] == SHARK &amp;amp;&amp;amp; neighbor(FISH, pos)&amp;gt;0) {&lt;br /&gt;
 			return true;&lt;br /&gt;
 		} else { return false; } }&lt;br /&gt;
 	&lt;br /&gt;
 	public boolean dangerous(int pos) { // 4 - If a cell contains a fish, and one of its neighbors is a shark&lt;br /&gt;
 		if (cells[pos] == FISH &amp;amp;&amp;amp; neighbor(SHARK, pos)==1) {&lt;br /&gt;
 			return true;&lt;br /&gt;
 		} else { return false; } }&lt;br /&gt;
    	&lt;br /&gt;
 	public boolean givesbirth(int pos) { /* 5 - If a cell contains a fish, and two or more of its neighbors are sharks&lt;br /&gt;
    		8 - If a cell is empty, at least two of its neighbors are fish, and at least two of its neighbors are sharks */&lt;br /&gt;
 		if (cells[pos] == FISH &amp;amp;&amp;amp; neighbor(SHARK, pos)&amp;gt;1) {&lt;br /&gt;
 			return true;&lt;br /&gt;
 		} else if (cells[pos] == EMPTY &amp;amp;&amp;amp; neighbor(FISH, pos)&amp;gt;1 &amp;amp;&amp;amp; neighbor(SHARK, pos)&amp;gt;1) {&lt;br /&gt;
 			return true;&lt;br /&gt;
 		} else { return false; } }&lt;br /&gt;
    	&lt;br /&gt;
 	public boolean spawnsfish(int pos) { // 7 - If a cell is empty, at least two of its neighbors are fish, and at most one of its neighbors is a shark&lt;br /&gt;
 		if (cells[pos] == EMPTY &amp;amp;&amp;amp; neighbor(FISH, pos)&amp;gt;1 &amp;amp;&amp;amp; neighbor(SHARK, pos)&amp;lt;2) {&lt;br /&gt;
 			return true;&lt;br /&gt;
 		} else { return false; } }&lt;br /&gt;
 	&lt;br /&gt;
 	public Ocean timeStep() {&lt;br /&gt;
 		Ocean newocean = new Ocean(x, y, starvetime); // create new Ocean to hold the state after timeStep&lt;br /&gt;
 		/** Important notes: this new ocean is initially &amp;quot;blank&amp;quot;. What this means here:&lt;br /&gt;
 		  * If someone &amp;quot;dies&amp;quot; below, we don't need to do anything, because the cell in the new ocean is already EMPTY&lt;br /&gt;
 		  * If any other values (i.e. hunger) change, they need to be written to the new ocean&lt;br /&gt;
 		  * If the value of a given cell does not change, it MUST be copied to the new ocean&lt;br /&gt;
 		**/&lt;br /&gt;
 		for (int pos=0; pos&amp;lt;cells.length; pos++) {&lt;br /&gt;
 			if (caneat(pos)) {  // the shark eats during the timestep, and it remains in the cell at the end of the timestep&lt;br /&gt;
 				newocean.cells[pos] = SHARK;&lt;br /&gt;
 				newocean.hunger[pos] = starvetime; }&lt;br /&gt;
 			else if (caneat(pos) != true &amp;amp;&amp;amp; cells[pos]==SHARK) {&lt;br /&gt;
 				if (hunger[pos] == 0) { /* If this timestep is the (starveTime + 1)th timestep&lt;br /&gt;
 					the shark has gone through without eating&lt;br /&gt;
 					then the shark dies (disappears), so we do nothing since value is EMPTY by default */&lt;br /&gt;
 				} else { // otherwise decrease its turns to die by 1&lt;br /&gt;
 					newocean.cells[pos] = SHARK;&lt;br /&gt;
 					newocean.hunger[pos] = hunger[pos] - 1;&lt;br /&gt;
 				}&lt;br /&gt;
 			} else if (dangerous(pos)) { /* the fish is eaten by a shark and disappears, so do nothing */&lt;br /&gt;
 			} else if (givesbirth(pos)) {  // a new shark is born in that cell; (sharks are well-fed at birth)&lt;br /&gt;
 				newocean.cells[pos] = SHARK;&lt;br /&gt;
 				newocean.hunger[pos] = starvetime;&lt;br /&gt;
 			} else if (spawnsfish(pos)) { newocean.cells[pos] = FISH;  // a new fish is born in that cell&lt;br /&gt;
 			} else { newocean.cells[pos] = cells[pos]; } // in all other cases, just copy the existing value - CRUCIAL!&lt;br /&gt;
 			/** 3 - If a cell contains a fish, and all of its neighbors are either empty or are other fish, then the fish stays where it is.&lt;br /&gt;
 			if (pos.boring) {  }&lt;br /&gt;
 			6 - If a cell is empty, and fewer than two of its neighbors are fish, then the cell remains empty.&lt;br /&gt;
 			if (pos.fishy) {  }&lt;br /&gt;
 			**/&lt;br /&gt;
 		}&lt;br /&gt;
 		return newocean; // return the newly-created and modified ocean&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 /**&lt;br /&gt;
  *  The following method is required for Part II.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *  addShark() (with three parameters) places a shark in cell (x, y) if the&lt;br /&gt;
  *  cell is empty.  The shark's hunger is represented by the third parameter.&lt;br /&gt;
  *  If the cell is already occupied, leave the cell as it is.  You will need&lt;br /&gt;
  *  this method to help convert run-length encodings to Oceans.&lt;br /&gt;
  *  @param x is the x-coordinate of the cell to place a shark in.&lt;br /&gt;
  *  @param y is the y-coordinate of the cell to place a shark in.&lt;br /&gt;
  *  @param feeding is an integer that indicates the shark's hunger.  You may&lt;br /&gt;
  *  encode it any way you want; for instance, &amp;quot;feeding&amp;quot; may be the&lt;br /&gt;
  *  last timestep the shark was fed, or the amount of time that has&lt;br /&gt;
  *  passed since the shark was last fed, or the amount of time left&lt;br /&gt;
  *  before the shark will starve.  It's up to you, but be consistent.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 	public void addShark(int x, int y, int feeding) {&lt;br /&gt;
 		int curpos = this.cellind(x,y);&lt;br /&gt;
 		if	(cells[curpos] == EMPTY) {&lt;br /&gt;
 			cells[curpos] = SHARK;&lt;br /&gt;
 			hunger[curpos] = feeding;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 					 &lt;br /&gt;
 /**&lt;br /&gt;
  *  The following method is required for Part III.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  *  sharkFeeding() returns an integer that indicates the hunger of the shark&lt;br /&gt;
  *  in cell (x, y), using the same &amp;quot;feeding&amp;quot; representation as the parameter&lt;br /&gt;
  *  to addShark() described above.  If cell (x, y) does not contain a shark,&lt;br /&gt;
  *  then its return value is undefined--that is, anything you want.&lt;br /&gt;
  *  Normally, this method should not be called if cell (x, y) does not&lt;br /&gt;
  *  contain a shark.  You will need this method to help convert Oceans to&lt;br /&gt;
  *  run-length encodings.&lt;br /&gt;
  *  @param x is the x-coordinate of the cell whose contents are queried.&lt;br /&gt;
  *  @param y is the y-coordinate of the cell whose contents are queried.&lt;br /&gt;
  */&lt;br /&gt;
 &lt;br /&gt;
 	public int sharkFeeding(int x, int y) {&lt;br /&gt;
 		return hunger[this.cellind(x,y)];&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	/* The method below does the same thing as above, but takes an array position instead of (x,y) coords */&lt;br /&gt;
 	&lt;br /&gt;
 	public int sharkFeeding(int pos) {&lt;br /&gt;
 		return sharkFeeding(coordx(pos), coordy(pos));&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
</feed>