private void sendWinner() { Candidate winner = model.getWinner(); writeMessage(13, winner.getCandidateNumber()); // Writes out the winner boolean isClosest = model.winnerIsClosest(player.getIdealPt(), winner); try { out.writeBoolean(isClosest); } catch (IOException e) { removePlayer(); } }
private void startSecondBuy() { try { ArrayList<Candidate> candidates = model.getSortedCandidates(); writeMessage(10, candidates.size()); out.writeByte(1); int numPlayers = model.getNumPlayers(); for (Candidate candidate : candidates) { // This writes the top candidates out.writeByte(candidate.getCandidateNumber()); int numVotes = candidate.getFirstVotes(); int percentVotes = ((numVotes * 100) / numPlayers); out.writeInt(percentVotes); } } catch (IOException e) { removePlayer(); } }
private void startFirstVote() { try { ArrayList<Candidate> candidates = model.getCandidates(); player.setRound("first"); writeMessage(10, candidates.size()); out.writeByte(0); int numPlayers = model.getNumPlayers(); for (Candidate candidate : candidates) { out.writeByte(candidate.getCandidateNumber()); int numVotes = candidate.getStrawVotes(); int percentVotes = ((numVotes * 100) / numPlayers); out.writeInt(percentVotes); } } catch (IOException e) { removePlayer(); } }
private void returnInfo() { try { int candidateToBuyFrom = in.readInt(); Candidate candidate = model.getCandidate(candidateToBuyFrom); int ideal = candidate.getIdealPt(); int random = (int) (Math.random() * 100); int signal = (random > ideal) ? 0 : 1; player.addInfo(candidateToBuyFrom, signal); int[] info = player.getInfo(candidateToBuyFrom); int tokens = info[0] + info[1]; int signals = info[1]; writeMessage(6, candidateToBuyFrom); out.writeInt(tokens); out.writeInt(signals); } catch (IOException e) { removePlayer(); } }