/** * Runs the server. The server will wait for some match info (which specifies the teams and set of * maps to run) and then begin running matches. */ public void run() { int aWins = 0, bWins = 0; while (!matches.isEmpty()) { Match match = matches.peek(); if (!finished.isEmpty()) match.setInitialTeamMemory(finished.getLast().getComputedTeamMemory()); try { debug("running match " + match); match.initialize(); runMatch(match, proxyWriter); finished.add(match); matches.remove(match); if (match.getWinner() == Team.A) aWins++; else if (match.getWinner() == Team.B) bWins++; match.finish(); // Allow best of three scrimmages -- single game scrims should still work fine // TODO:This "win mode" should probably be something from the database if (mode == Mode.TOURNAMENT || mode == Mode.SCRIMMAGE) { if (aWins == 2 || bWins == 2) break; } } catch (Exception e) { ErrorReporter.report(e); error("couldn't run match: "); this.state = State.ERROR; } } proxyWriter.terminate(); }
@Override public void visitInjectNotification(InjectNotification n) { InjectDelta result = matches.peek().inject(n.getInternalSignal()); proxyWriter.enqueue(result); }