Note that there are some explanatory texts on larger screens.

plurals
  1. POI need a fresh pair of eyes for debugging
    text
    copied!<p>The purpose of this assignment was to create a Field and Robot class and objects of those classes. </p> <p>The single field object is limited to a square of points from (0, 0) to (50, 50), and contains 3 pieces of gold and 3 bombs. </p> <p>Three robot objects search the field (one after another) for gold from left to right (0, 0) to (0, 50) and descend through the field (1, 0) to 1, 50) and so on. </p> <p>The robots are destroyed by bombs that are places by input from the user. Once the gold is collected it cannot be picked up by another robot, and one a bomb explodes it does not do so again.</p> <p>This is my attempt at solving the problem so far, I am continuing to work on it, but would appreciate a second pair of eyes on it to catch something im missing. The program compiles, but the bombs and gold arent being "found" correctly and the output states that the following robots die on the same bomb as the one before it. Also, there are several pieces of code removed by comments, I did this to test different parts of the program. I think this section is where I'm having trouble. The methods field.alreadyFound() and field.alreadyBombed() return a boolean with the value true. My if statements should be saying if the gold/bomb has already been found, ignore it.</p> <pre><code>while(x &lt;= 50 &amp;&amp; y &lt;= 50 &amp;&amp; alive2 == true) { foundGold1 = robot2.look(field.locateGold1()); foundGold2 = robot2.look(field.locateGold2()); foundGold3 = robot2.look(field.locateGold3()); foundBomb1 = robot2.look(field.locateBomb1()); foundBomb2 = robot2.look(field.locateBomb2()); foundBomb3 = robot2.look(field.locateBomb3()); if (foundGold1 == true) { if (field.alreadyFound1() == true) { } else { robot2.addGold(); field.foundGold1(); } } if (foundGold2 == true) { if (field.alreadyFound2() == true) { } else { robot2.addGold(); field.foundGold2(); } } if (foundGold3 == true) { if (field.alreadyFound3() == true) { } else { robot2.addGold(); field.foundGold3(); } } if (foundBomb1 == true) { if (field.alreadyBombed1() == true) { } else { alive2 = false; } } if (foundBomb2 == true) { if (field.alreadyBombed2() == true) { } else { alive2 = false; } } if (foundBomb3 == true) { if (field.alreadyBombed3() == true) { } else { alive2 = false; } } y = y + 1; robot2.setLocation(x, y); //System.out.println(y); if (y == 50) { x = x + 1; y = 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload