Transcript Corrections

Corrections
26-Jul-16
Pausing I



On my HTML page, I said to pause like this:
private void interpret(Tree node) {
if (stopped) return;
if (paused) {
try {
currentThread().wait();
}
catch (InterruptedException e) { }
}
...
}
The code for pausing is completely wrong, but it’s in the right
place
Pausing II



In my threads.ppt lecture, which I posted but forgot to link to, I
said to pause like this:
public void run( ) {
while (okToRun) {
while (paused) {
try { Thread.sleep(100); }
catch (InterruptedException e) { }
}
...main loop...
}
}
This is more nearly correct, but it shouldn’t be in the run method
Pausing III

The run method takes no parameters and just calls the interpret
method (with a predefined parse tree):


public void run() {
interpret(program);
}
The highly recursive interpret method is where you need to
check for pausing and stopping:

private void interpret(Tree node) {
if (stopped) return;
while (paused) {
// while, not if
try {
Thread.sleep(100);
// not currentThread().wait()
}
catch (InterruptedException e) { }
}
...
}
The revised BoardGame.zip


The second version of BoardGame.zip does have the
necessary corrections; the most important of these is
that piece.remove() no longer calls removeHelper()
Although it has corrections, there is some cruft that I
failed to clean out


Most important, Piece.toString() calls a special-purpose
method, getColorName, which I did not provide
Piece.toString() should look like this:

public String toString() {
return getClass().getName() + "[" + row + "][" + column + "]";
}