Changeset 25 for exampleparties/randomparty/src/main/java
- Timestamp:
- 10/08/20 10:17:25 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
exampleparties/randomparty/src/main/java/geniusweb/exampleparties/randomparty/RandomParty.java
r24 r25 63 63 private Settings settings; 64 64 private Votes lastvotes; 65 private String protocol; 65 66 66 67 public RandomParty() { … … 81 82 this.progress = settings.getProgress(); 82 83 this.settings = settings; 84 this.protocol = settings.getProtocol().getURI().getPath(); 85 83 86 } else if (info instanceof ActionDone) { 84 87 Action otheract = ((ActionDone) info).getAction(); … … 88 91 } else if (info instanceof YourTurn) { 89 92 makeOffer(); 90 nextRound();91 93 } else if (info instanceof Finished) { 92 94 getReporter().log(Level.INFO, "Final ourcome:" + info); … … 94 96 lastvotes = vote((Voting) info); 95 97 getConnection().send(lastvotes); 96 nextRound();97 98 } else if (info instanceof OptIn) { 98 99 // just repeat our last vote. 99 100 getConnection().send(lastvotes); 100 nextRound();101 101 } 102 102 } catch (Exception e) { 103 103 throw new RuntimeException("Failed to handle info", e); 104 104 } 105 } 106 107 private void nextRound() { 108 if (progress instanceof ProgressRounds) { 109 progress = ((ProgressRounds) progress).advance(); 110 } 111 105 updateRound(info); 112 106 } 113 107 … … 125 119 126 120 /** 121 * Update {@link #progress} 122 * 123 * @param info the received info. Used to determine if this is the last info 124 * of the round 125 */ 126 private void updateRound(Inform info) { 127 if (protocol == null) 128 return; 129 switch (protocol) { 130 case "SAOP": 131 case "SHAOP": 132 if (!(info instanceof YourTurn)) 133 return; 134 break; 135 case "MOPAC": 136 if (!(info instanceof OptIn)) 137 return; 138 break; 139 default: 140 return; 141 } 142 // if we get here, round must be increased. 143 if (progress instanceof ProgressRounds) { 144 progress = ((ProgressRounds) progress).advance(); 145 } 146 147 } 148 149 /** 127 150 * send our next offer 128 151 */ 129 152 private void makeOffer() throws IOException { 130 153 Action action; 131 String protocol = settings.getProtocol().getURI().getPath();132 154 if ((protocol.equals("SAOP") || protocol.equals("SHAOP")) 133 155 && isGood(lastReceivedBid)) {
Note:
See TracChangeset
for help on using the changeset viewer.