
public class Token extends Process {

	private int acc;
	
	public Token(int pid, int t, CommMatrix cm, int p) {
		super(pid, t, cm, p);
		this.setAcc(1);
	}
	
	public void handleMessage() {
		for (int i = 0; i < cm.getSize(); i++) {
			Message m = cm.getM(pid, i);
			if (m != null) {
				if (m.getM().equals(Message.Token)) {
					System.out.println();
					if (pid == 1) for (int j = (cm.getSize() / 2) + 1; j < cm.getSize(); j++) m.sendMessage(j, pid, cm, new Message(Message.Start, t));
					if (pid == 0) for (int j = 2; j < (cm.getSize() / 2) + 1; j++) m.sendMessage(j, pid, cm, new Message(Message.Start, t));
				} 
				else if (m.getM().equals(Message.Finish)) {
					if (acc == 3) {
						acc = 1;
						if (pid == 1) cm.setM(1, pid, new Message(Message.Token, t));
						else if (pid == 0) cm.setM(0, pid, new Message(Message.Token, t));
					} else acc++;
				}
			}
		}
	}

	public int getAcc() {
		return acc;
	}

	public void setAcc(int acc) {
		this.acc = acc;
	}
	
}

@@ -32,16 +32,62 @@
 cess %7B%0A%0A
+%09private static final boolean DEBUG = true;%0A%09%0A
 %09private
@@ -363,24 +363,152 @@
 e.Token)) %7B%0A
+%09%09%09%09%09if (DEBUG) System.out.printf(%22%5B%25d%5D (%25d,%25d) %25s from (%25d,%25d)%5Cn%22, System.currentTimeMillis(), pid, t, m.getM(), i, m.getT());%0A
 %09%09%09%09%09System.
@@ -853,34 +853,147 @@
 if (
-acc == 3) %7B
+DEBUG) System.out.printf(%22%5B%25d%5D (%25d,%25d) %25s from (%25d,%25d)%5Cn%22, System.currentTimeMillis(), pid, t, m.getM(), i, m.getT());
 %0A%09%09%09%09%09
-%09
+if (
 acc =
- 1;
+= 3) %7B
 %0A%09%09%09
@@ -1021,14 +1021,14 @@
 etM(
-1, 
 pid
+, 0
 , ne
@@ -1094,14 +1094,14 @@
 etM(
-0, 
 pid
+, 1
 , ne
@@ -1126,24 +1126,39 @@
 Token, t));%0A
+%09%09%09%09%09%09acc = 1;%0A
 %09%09%09%09%09%7D else 

Fix a problem with writing in the correct communication matrix index