[virtualcommons-svn] SF.net SVN: virtualcommons:[391] foraging/branches/deepak-branch-fall-09/ src
Status: Beta
Brought to you by:
alllee
From: <db...@us...> - 2009-12-03 00:48:44
|
Revision: 391 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=391&view=rev Author: dbarge Date: 2009-12-03 00:48:31 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Added some code for getting parameters for the timers on the client side Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-03 00:48:31 UTC (rev 391) @@ -41,6 +41,8 @@ private int currentTokens; private int role; + + private Identifier moniterId; private static final int MONITOR = 0; private static final int HARVEST = 1; @@ -77,6 +79,14 @@ return this.role; } + public void setMoniterId (Identifier moniterId) { + this.moniterId = moniterId; + } + + public Identifier getMoniterId() { + return this.moniterId; + } + public boolean isSanctioningAllowed(){ System.out.println("My Role : "+getMyRole()); /* Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-03 00:48:31 UTC (rev 391) @@ -188,11 +188,13 @@ addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { public void handle(NewClientRole event) { Identifier receivedClientId = event.getRoleObj().getClientId(); - System.out.println("Broadcast ID : "+receivedClientId); + //System.out.println("Broadcast ID : "+receivedClientId); if(dataModel.getId().equals(receivedClientId)) { int roles [] = event.getRoleObj().getClientRoles(); + //System.out.println("Setting my role"); dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); - System.out.println("New role for the client : "+dataModel.getMyRole()); + dataModel.setMoniterId(event.getRoleObj().getMoniterId()); + //System.out.println("New role for the client : "+dataModel.getMyRole()); gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); // Utils.notify(GameWindow2D.clientRoleSignal); @@ -265,6 +267,7 @@ } public boolean canPerformRealTimeSanction(EnforcementData votedEnforcement) { + //System.out.println("Result index"+votedEnforcement.getResultIndex()); if(votedEnforcement.getResultIndex() == 2 || votedEnforcement.getResultIndex() == 3) return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() >= 0; else @@ -281,7 +284,7 @@ public void transmit(PostRoundSanctionRequest request) { if (state == ClientState.WAITING) { - System.out.println("Sending post round sanction request"); + //System.out.println("Sending post round sanction request"); gameWindow2D.switchInstructionsPane(); super.transmit(request); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 00:48:31 UTC (rev 391) @@ -78,7 +78,7 @@ // the data model private final ClientDataModel dataModel; - // instructions components. + // instructions components. private Component currentCenterComponent; @@ -247,9 +247,11 @@ } private void startEnforcementDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(10); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementDisplayDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -275,9 +277,10 @@ } private void startRegulationDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -302,9 +305,11 @@ } private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -347,9 +352,11 @@ private void startRegulationVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -382,10 +389,12 @@ } } - private void startRegulationSubmissionTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + + private void startSanctioningTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -413,8 +422,10 @@ } } private void startChatTimer() { - if (timer == null) { - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + if (timer == null) { + // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -629,10 +640,16 @@ case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - // System.out.println("Key pressed : "+(keyChar-48)); - if(dataModel.getRoundConfiguration().isChatEnabled() == false) { - return; - } + + // System.out.println("Key pressed : "+(keyChar-48)); + //if(dataModel.getRoundConfiguration().isChatEnabled() == false) { + //return; + //} + if(dataModel.getRoundConfiguration().isSanctioningEnabled() == false) { + return; + } + + if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; @@ -733,8 +750,11 @@ // by the server no new clients can connect because the round // has begun. update(configuration.getRoundDuration().getTimeLeft()); - if(configuration.isChatEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + + //if(configuration.isChatEnabled()){ + if(configuration.isSanctioningEnabled()){ + displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + } add(messagePanel, BorderLayout.SOUTH); @@ -1030,7 +1050,7 @@ // System.out.println("Initialization done"); //remove( messagePanel ); addCenterComponent( sanctioningPanel ); - startRegulationSubmissionTimer(); + startSanctioningTimer(); } }); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-03 00:48:31 UTC (rev 391) @@ -34,7 +34,7 @@ protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage, monitorImage; protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, - scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMonitorImage; + scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMoniterImage; /** * Use these for the dimensions when drawing. @@ -93,7 +93,7 @@ scaledSelfExplicitCollectionModeImage = selfExplicitCollectionModeImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledBeingSanctionedImage = beingSanctionedImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledSanctioningImage = sanctioningImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); - scaledMonitorImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); + scaledMoniterImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); } /** Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-03 00:48:31 UTC (rev 391) @@ -169,7 +169,7 @@ graphics2D.drawImage(scaledBeingSanctionedImage, x, y, this); } else if (dataModel.isMonitor()) { - graphics2D.drawImage(scaledMonitorImage, x, y, this); + graphics2D.drawImage(scaledMoniterImage, x, y, this); } else if (dataModel.isSanctioning(id)) { graphics2D.setColor(Color.WHITE); @@ -182,11 +182,19 @@ graphics2D.drawImage(scaledSelfExplicitCollectionModeImage, x, y, this); } else { + //System.out.println("Is a self image"); graphics2D.drawImage(scaledSelfImage, x, y, this); } } else { - graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); + if (id.equals(dataModel.getMoniterId()) && dataModel.isSanctioningEnabled()) { + //System.out.println("Is a moniter image"); + graphics2D.drawImage(scaledMoniterImage, x, y, this); + } + else { + //System.out.println("Is a other image"); + graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); + } } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-03 00:48:31 UTC (rev 391) @@ -274,9 +274,29 @@ } public int getChatDuration() { - return getIntProperty("chat-duration", 5); + return getIntProperty("chat-duration", 30); } - + + public int getRegulationSubmissionDuration() { + return getIntProperty("regulation-duration", 60); + } + + public int getRegulationDisplayDuration() { + return getIntProperty("regulation-display-duration", 15); + } + + public int getEnforcementVotingDuration() { + return getIntProperty("enforcement-voting-duration", 30); + } + + public int getEnforcementDisplayDuration() { + return getIntProperty("enforcement-display-duration", 15); + } + + public int getRegulationVotingtDuration() { + return getIntProperty("regulation-voting-duration", 30); + } + public String getSanctionInstructions() { return getProperty("sanction-instructions"); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-03 00:48:31 UTC (rev 391) @@ -21,6 +21,8 @@ private Identifier id; + private Identifier moniterId; + private int roleNo; public ClientRole() {} @@ -41,6 +43,15 @@ this.id = id; } + public Identifier getMoniterId(){ + return moniterId; + } + + public void setMoniterId(Identifier moniterId){ + this.moniterId = moniterId; + } + + public int getRoleNo(){ return roleNo; } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-03 00:48:31 UTC (rev 391) @@ -101,6 +101,11 @@ public static final int SANCTION = 2; public static final int HARVESTANDSANCTION = 3; + public static final int NO_SANCTIONS = 0; + public static final int HARVEST_WITH_SANCTION = 1; + public static final int RANDOM_SANCTIONER = 2; + public static final int CIRCULAR_MONITERING = 3; + public final static int SYNCHRONIZATION_FREQUENCY = 60; public final static int SERVER_SLEEP_INTERVAL = 100; @@ -264,7 +269,7 @@ Identifier newClientIdentifier = event.getId(); // Identifier newClientIdentifier = (Identifier)t1.toString(); - System.out.println("Client ID : "+newClientIdentifier); + System.out.println("New Client ID : "+newClientIdentifier); synchronized (clients) { clients.put(newClientIdentifier, new ClientData(newClientIdentifier)); @@ -439,7 +444,7 @@ switch(srcEnforcementType) { /* * No sanctioning just harvest - */ case 0: + */ case NO_SANCTIONS: System.out.println("This code should never be reached"); break; @@ -447,7 +452,7 @@ /* * Harvest and sanction * Reduce other by 2 but also own by 1 - */ case 1: + */ case HARVEST_WITH_SANCTION: sourceClient.sanctionCost(); targetClient.sanctionPenalty(1); // add sanction request to the target client so they can figure out who just sanctioned them @@ -466,7 +471,7 @@ * One participant is a moniter who sanctions but cannot harvest * Moniter can give penalty by subtract 1 from sanctionee * Nothing taken from Moniter but receives 25% tokens from each - */ case 2: + */ case RANDOM_SANCTIONER: //sourceClient.sanctionCost(); targetClient.sanctionPenalty(0); // add sanction request to the target client so they can figure out who just sanctioned them @@ -485,7 +490,7 @@ * One participant is a moniter who sanctions but cannot harvest * Moniter can give penalty by subtract 1 from sanctionee * Nothing taken from Moniter but receives 25% tokens from each - */ case 3: + */ case CIRCULAR_MONITERING: //sourceClient.sanctionCost(); targetClient.sanctionPenalty(0); // add sanction request to the target client so they can figure out who just sanctioned them @@ -660,6 +665,7 @@ NewClientRole newClientRole = new NewClientRole(targetId); clientRole.setClientId(targetId); clientRole.setRoleNo(i); + if(roles[i] == MONITER)clientRole.setMoniterId(targetId); clients.get(targetId).setClientRole(clientRole); newClientRole.setRoleObj(clientRole); transmit(newClientRole); @@ -706,6 +712,7 @@ // update all clients with the roles roles = findClientRoles(group, 3); + roles = findClientRoles(group, 3); for(Identifier targetId: group.getClientIdentifiers()) { sendNewRolesToClients(targetId, roles); } @@ -724,26 +731,26 @@ int i; System.out.println("Finding roles for mechanism : "+index); switch(index){ - case 0: + case NO_SANCTIONS: for(i=0; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVEST; } break; - case 1: + case HARVEST_WITH_SANCTION: for(i=0; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVESTANDSANCTION; } break; - case 2: + case RANDOM_SANCTIONER: roles[0] = MONITER; for(i=1; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVEST; } break; - case 3: + case CIRCULAR_MONITERING: // first client is given the chance to sanction int moniter = group.getRandomMoniterCount(); group.incrRandomMoniterCount(); @@ -811,6 +818,7 @@ NewClientRole newClientRole = new NewClientRole(targetId); clientRole.setClientId(targetId); clientRole.setRoleNo(i); + if(roles[i] == MONITER)clientRole.setMoniterId(targetId); clients.get(targetId).setClientRole(clientRole); newClientRole.setRoleObj(clientRole); transmit(newClientRole); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |