2-APL UPC project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

scoreboard added

fdesan d1461475 37b0476d

+52 -8
+26 -7
code/2apl_platform/environments/cardtable/Env.java
··· 24 24 private int numberOfPlayers, numberOfNotaries, numberOfGatekeepers, numberOfDealers; 25 25 26 26 private Deck deck; 27 + 28 + private Scoreboard sb; 27 29 28 30 // The default constructor 29 31 public Env() ··· 37 39 numberOfGatekeepers=0; 38 40 39 41 deck = new Deck(); 42 + sb = new Scoreboard(); 40 43 } 41 44 42 45 public Term enterAsNotary(String sAgent) throws ExternalActionFailedException { ··· 111 114 // Increase number of players 112 115 increaseNumberOfPlayers(); 113 116 114 - // Redraw so we can see the agent 115 - //validatewindow(); 116 - //m_window.repaint(); 117 - 118 - // We came so far, this means success! 119 - //agent.signalMoveSucces.emit(); 117 + sb.addPlayer(agent.getName()); 120 118 121 119 writeToLog("Player sit: " +agent.getName()); 122 120 ··· 160 158 return wrapBoolean(true); 161 159 } 162 160 161 + public Term updateScore(String sAgent, APLIdent player_name, APLNum score) { 162 + sb.updateScore(player_name.toString(), score.toInt()); 163 + notifyEvent("scoreUpdated", player_name, score); 164 + return wrapBoolean(true); 165 + } 166 + 163 167 /* Standard functions --------------------------------------*/ 164 168 165 169 private void notifyAgents(APLFunction event, String... receivers) { ··· 199 203 ArrayList<String> targetAgents = new ArrayList<String>(); 200 204 for (Agent a : agentmap.values()) 201 205 { 202 - if ((a.isSit() && a.getType()==0) || (a.isSit() && a.getType()==2)) 206 + if ((a.isSit() && a.getType()==0) || (a.isSit() && a.getType()==2)) // player or notary 203 207 targetAgents.add(a.getName()); 204 208 } 205 209 ··· 207 211 { 208 212 notifyAgents(new APLFunction(parm1,suit,rank),targetAgents.toArray(new String[0])); 209 213 writeToLog("EVENT: "+parm1+"("+suit.toString()+","+rank.toString()+")"+" to "+targetAgents); 214 + } 215 + } 216 + 217 + private void notifyEvent(String parm1, APLIdent name, APLNum score) { 218 + ArrayList<String> targetAgents = new ArrayList<String>(); 219 + for (Agent a : agentmap.values()) 220 + { 221 + if ((a.isSit() && a.getType()==0)) // player 222 + targetAgents.add(a.getName()); 223 + } 224 + 225 + if (!targetAgents.isEmpty()) 226 + { 227 + notifyAgents(new APLFunction(parm1,name,score),targetAgents.toArray(new String[0])); 228 + writeToLog("EVENT: "+parm1+"("+name.toString()+","+score.toString()+")"+" to "+targetAgents); 210 229 } 211 230 } 212 231
-1
code/2apl_platform/environments/cardtable/Hand.java
··· 1 - 2 1 package cardtable; 3 2 4 3 import java.util.*;
+26
code/2apl_platform/environments/cardtable/Scoreboard.java
··· 1 + package cardtable; 2 + 3 + import java.util.*; 4 + 5 + public class Scoreboard 6 + { 7 + private HashMap<String,Integer> scoreboard; 8 + 9 + public Scoreboard() { 10 + scoreboard = new HashMap<String,Integer>(); 11 + } 12 + 13 + public void addPlayer(String name) { 14 + scoreboard.put(name, new Integer(0)); 15 + } 16 + 17 + public void updateScore(String name, int score) { 18 + Integer cur = (Integer) scoreboard.get(name); 19 + scoreboard.remove(name); 20 + scoreboard.put(name, new Integer(score*cur.intValue())); 21 + } 22 + 23 + public Integer getScore(String name) { 24 + return (Integer) scoreboard.get(name); 25 + } 26 + }