[virtualcommons-svn] commit/foraging: alllee: updated trust game window
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-08-17 02:41:07
|
1 new changeset in foraging: http://bitbucket.org/virtualcommons/foraging/changeset/27b190134ee8/ changeset: 27b190134ee8 user: alllee date: 2011-08-17 04:41:02 summary: updated trust game window affected #: 13 files (28.3 KB) --- a/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java Tue Aug 16 19:41:02 2011 -0700 @@ -32,6 +32,7 @@ import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; +import edu.asu.commons.foraging.event.ShowTrustGameRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.net.SocketIdentifier; import edu.asu.commons.util.Duration; @@ -73,7 +74,7 @@ private JPanel clientPanel = new JPanel(); public ForagingClient(ServerConfiguration configuration) { - this(configuration, new Dimension(800, 600)); + this(configuration, new Dimension(900, 800)); } public ForagingClient(ServerConfiguration configuration, Dimension screenSize) { @@ -159,7 +160,11 @@ getGameWindow().showInstructions(); } }); - + addEventProcessor(new EventTypeProcessor<ShowTrustGameRequest>(ShowTrustGameRequest.class) { + public void handle(ShowTrustGameRequest request) { + getGameWindow().showTrustGame(); + } + }); addEventProcessor(new EventTypeProcessor<RoundStartedEvent>(RoundStartedEvent.class) { public void handle(RoundStartedEvent event) { System.err.println("client starting round: " + dataModel.is2dExperiment()); --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow.java Tue Aug 16 19:41:02 2011 -0700 @@ -18,4 +18,6 @@ public void update(long millisecondsLeft); public void showInstructions(); + public void showTrustGame(); + } --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Tue Aug 16 19:41:02 2011 -0700 @@ -100,6 +100,8 @@ private JPanel subjectWindow; + private TrustGamePanel trustGamePanel; + private ForagingClient client; private SubjectView subjectView; @@ -428,12 +430,10 @@ instructionsScrollPane = new JScrollPane(instructionsEditorPane); add(instructionsScrollPane, BorderLayout.CENTER); currentCenterComponent = instructionsScrollPane; - // setup the Subject Window, add the experiment view - subjectWindow = new JPanel(new BorderLayout(4, 4)); + subjectWindow = new JPanel(new BorderLayout()); subjectWindow.setBackground(Color.WHITE); subjectWindow.setForeground(Color.BLACK); subjectWindow.add(subjectView, BorderLayout.CENTER); - // setBackground(SubjectView.FIELD_OF_VISION_COLOR); setBackground(Color.WHITE); // replace with progress bar. timeLeftLabel = new JLabel("Connecting ..."); @@ -630,13 +630,7 @@ if (configuration.isInRoundChatEnabled()) { ChatPanel chatPanel = getChatPanel(); chatPanel.initialize(); -// Dimension subjectWindowSize = subjectView.getSize(); -// Dimension totalSize = getParent().getSize(); -// System.err.println("subject window size: " + subjectWindowSize); -// System.err.println("total size: " + totalSize); -// Dimension chatPanelSize = new Dimension((totalSize.width - subjectWindowSize.width) / 2, (totalSize.height - subjectWindowSize.height) / 2); -// System.err.println("chat panel size: " + chatPanelSize); - Dimension chatPanelSize = new Dimension(100, getSize().height); + Dimension chatPanelSize = new Dimension(200, getSize().height); chatPanel.setPreferredSize(chatPanelSize); add(chatPanel, BorderLayout.EAST); } @@ -751,6 +745,21 @@ return chatPanel; } + public void showTrustGame() { + RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); + if (roundConfiguration.isTrustGameEnabled()) { + addCenterComponent(new TrustGameWindow(roundConfiguration)); + } + } + + public TrustGamePanel getTrustGamePanel() { + if (trustGamePanel == null) { + // initialize + trustGamePanel = new TrustGamePanel(); + } + return trustGamePanel; + } + public void showInstructions() { RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); instructionsBuilder.delete(0, instructionsBuilder.length()); --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow3D.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow3D.java Tue Aug 16 19:41:02 2011 -0700 @@ -45,6 +45,11 @@ private JPanel gameInformationPanel; private EmbeddedChatPanel chatPanel; + + @Override + public void showTrustGame() { + throw new UnsupportedOperationException("Not supported yet."); + } public static enum VideoCardSupport{SHADER_SUPPORT, VBO_SUPPORT, VERTEX_ARRAY_SUPPORT}; public static VideoCardSupport featureSupported; --- a/src/main/java/edu/asu/commons/foraging/client/GridView.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GridView.java Tue Aug 16 19:41:02 2011 -0700 @@ -165,9 +165,6 @@ } protected void paintComponent(Graphics graphics) { - // XXX: if this guy didn't fill the entire component we'd have to do - // this super call to let the UI delegate some paintage as well. - // super.paintComponent(graphics); Graphics2D graphics2D = (Graphics2D) graphics; // graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // FIXME: can be made more efficient. --- a/src/main/java/edu/asu/commons/foraging/client/SubjectView.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/SubjectView.java Tue Aug 16 19:41:02 2011 -0700 @@ -39,12 +39,27 @@ private final ClientDataModel dataModel; + private boolean tokenFieldOfVision; + private boolean subjectFieldOfVision; + public final static Color FIELD_OF_VISION_COLOR = new Color(255, 255, 255, 150); // associates a Duration with a piece of token consumed at the given Point - // the duration is used to render the token as shrinking. private Map<Point, Duration> collectedTokens = new HashMap<Point, Duration>(); + private int viewSubjectsRadius; + + private double viewTokensRadius; + + private Circle viewTokensField; + + private Circle viewSubjectsField; + + private double fieldOfVisionYOffset; + + private double fieldOfVisionXOffset; + public SubjectView(Dimension screenSize, ClientDataModel dataModel) { super(screenSize); this.dataModel = dataModel; @@ -57,24 +72,35 @@ public void setup(RoundConfiguration configuration) { synchronized (collectedTokens) { collectedTokens.clear(); + tokenFieldOfVision = configuration.isTokensFieldOfVisionEnabled(); + if (tokenFieldOfVision) { + viewTokensRadius = configuration.getViewTokensRadius(); + Point location = dataModel.getCurrentPosition(); + viewTokensField = new Circle(location, viewTokensRadius); + } + subjectFieldOfVision = configuration.isSubjectsFieldOfVisionEnabled(); + if (subjectFieldOfVision) { + viewSubjectsRadius = configuration.getViewSubjectsRadius(); + viewSubjectsField = new Circle(dataModel.getCurrentPosition(), viewSubjectsRadius); + fieldOfVisionXOffset = (dw / 3.0); + fieldOfVisionYOffset = (dh / 3.0); + } } super.setup(configuration); } public void collectToken(Point p) { synchronized (collectedTokens) { - collectedTokens.put(p, Duration.create(1000L)); + collectedTokens.put(p, Duration.create(3000L)); } } protected void paintTokens(Graphics2D graphics2D) { // three cases - show all food on the game board, show all food within // visible radius of the current player, or don't show any food. - if (dataModel.getRoundConfiguration().isTokensFieldOfVisionEnabled()) { - Point location = dataModel.getCurrentPosition(); - Circle viewTokensField = new Circle(location, dataModel.getRoundConfiguration().getViewTokensRadius()); + if (tokenFieldOfVision) { + viewTokensField.setCenter(dataModel.getCurrentPosition()); paintCollection(dataModel.getResourcePositions(), graphics2D, scaledTokenImage, this, viewTokensField); - } else { paintCollection(dataModel.getResourcePositions(), graphics2D, scaledTokenImage); @@ -122,20 +148,17 @@ FontMetrics fontMetrics = graphics2D.getFontMetrics(font); int characterHeight = fontMetrics.getAscent(); int verticalCharacterSpacing = (int) ( (dh - characterHeight) / 2); - Circle fieldOfVision = null; Point currentPosition = dataModel.getCurrentPosition(); - RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); - if (roundConfiguration.isSubjectsFieldOfVisionEnabled()) { + if (subjectFieldOfVision) { // paint a transparent circle centered on the current position of the subject. - int radius = roundConfiguration.getViewSubjectsRadius(); - fieldOfVision = new Circle(currentPosition, radius); + int radius = viewSubjectsRadius; + viewSubjectsField.setCenter(currentPosition); Point topLeftCorner = new Point(currentPosition.x - radius, currentPosition.y - radius); - double x = scaleXDouble(topLeftCorner.x) + (dw / 3); - double y = scaleYDouble(topLeftCorner.y) + (dh / 3); + double x = scaleXDouble(topLeftCorner.x) + fieldOfVisionXOffset; + double y = scaleYDouble(topLeftCorner.y) + fieldOfVisionYOffset; double diameter = radius * 2.0d; diameter = Math.min(scaleXDouble(diameter), scaleYDouble(diameter)) + (dw / 2); Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter); - //graphics2D.fillOval(x, y, diameter, diameter); // clip the rendered part of the Field of vision circle that crosses the playing boundary graphics2D.setClip(circle); Paint originalPaint = graphics2D.getPaint(); @@ -147,7 +170,7 @@ Identifier id = entry.getKey(); Point subjectLocation = entry.getValue().getPosition(); // optimized conditional - if (fieldOfVision == null || id.equals(dataModel.getId()) || fieldOfVision.contains(subjectLocation)) { + if (viewSubjectsField == null || id.equals(dataModel.getId()) || viewSubjectsField.contains(subjectLocation)) { // only draw if: // 1. field of vision is not enabled for subjects // 2. subject being drawn is this participant (i.e., id == dataModel.id) --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Tue Aug 16 19:41:02 2011 -0700 @@ -42,6 +42,10 @@ private static final double DEFAULT_TOKEN_MOVEMENT_PROBABILITY = 0.2d; private static final double DEFAULT_TOKEN_BIRTH_PROBABILITY = 0.01d; + + public double getTrustGamePayoffIncrement() { + return getDoubleProperty("trust-game-payoff", 0.25d); + } public enum SanctionType { REAL_TIME, POST_ROUND, NONE; @@ -505,7 +509,7 @@ } public boolean isTrustGameEnabled() { - return getBooleanProperty("trust-game", false); + return getBooleanProperty("trust-game", true); } public boolean isInRoundChatEnabled() { @@ -572,4 +576,8 @@ return instructionsBuilder; } + public String getTrustGameInstructions() { + return getProperty("trust-game-instructions", "Instructions: You will be randomly matched with another person in your group."); + } + } --- a/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java Tue Aug 16 19:41:02 2011 -0700 @@ -22,27 +22,22 @@ import edu.asu.commons.foraging.event.FacilitatorUpdateEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; +import edu.asu.commons.foraging.event.ShowTrustGameRequest; import edu.asu.commons.foraging.model.ServerDataModel; - - /** * $Id: Facilitator.java 529 2010-08-17 00:08:01Z alllee $ * * @author <a href='ano...@gm...'>Allen Lee</a>, Deepali Bhagvat * @version $Revision: 529 $ */ - public class Facilitator extends BaseFacilitator<ServerConfiguration> { private final static Facilitator INSTANCE = new Facilitator(); + private ServerDataModel serverDataModel; + private FacilitatorWindow facilitatorWindow; + private boolean experimentRunning = false; - private ServerDataModel serverDataModel; - - private FacilitatorWindow facilitatorWindow; - - private boolean experimentRunning = false; - private Facilitator() { this(new ServerConfiguration()); } @@ -51,35 +46,39 @@ public Facilitator(ServerConfiguration configuration) { super(configuration); addEventProcessor(new EventTypeProcessor<SetConfigurationEvent>(SetConfigurationEvent.class) { + public void handle(SetConfigurationEvent event) { RoundConfiguration configuration = (RoundConfiguration) event.getParameters(); setServerConfiguration(configuration.getParentConfiguration()); } }); addEventProcessor(new EventTypeProcessor<FacilitatorUpdateEvent>(FacilitatorUpdateEvent.class) { + public void handle(FacilitatorUpdateEvent event) { if (serverDataModel == null) { experimentRunning = true; serverDataModel = event.getServerDataModel(); facilitatorWindow.displayGame(); - } - else { + } else { serverDataModel = event.getServerDataModel(); } } }); addEventProcessor(new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) { + public void handle(FacilitatorEndRoundEvent event) { serverDataModel = null; facilitatorWindow.endRound(event); } }); addEventProcessor(new EventTypeProcessor<FacilitatorSanctionUpdateEvent>(FacilitatorSanctionUpdateEvent.class) { + public void handle(FacilitatorSanctionUpdateEvent event) { facilitatorWindow.updateDebriefing(event); } }); addEventProcessor(new EventTypeProcessor<QuizCompletedEvent>(QuizCompletedEvent.class) { + public void handle(QuizCompletedEvent event) { facilitatorWindow.quizCompleted(); } @@ -90,12 +89,12 @@ public static Facilitator getInstance() { return INSTANCE; } - + void createFacilitatorWindow(Dimension dimension) { facilitatorWindow = new FacilitatorWindow(dimension, this); if (getId() == null) { // configure for unconnected functionality - facilitatorWindow.configureForReplay(); + facilitatorWindow.configureForReplay(); } } @@ -148,21 +147,25 @@ /** * Sends a request to show round instructions */ - public void sendShowInstructionsRequest() - { - transmit(new ShowInstructionsRequest(getId())); + public void sendShowInstructionsRequest() { + transmit(new ShowInstructionsRequest(getId())); + } + + void sendShowTrustGameRequest() { + transmit(new ShowTrustGameRequest(getId())); } /* * Send a request to start a round */ + public void sendBeginRoundRequest() { transmit(new BeginRoundRequest(getId())); } - - public void sendBeginChatRoundRequest() { - transmit(new BeginChatRoundRequest(getId())); - } - + + public void sendBeginChatRoundRequest() { + transmit(new BeginChatRoundRequest(getId())); + } + public void endExperiment() { // configuration.resetRoundConfiguration(); // serverGameState = null; @@ -189,8 +192,6 @@ return facilitatorWindow; } - - public ServerDataModel getServerGameState() { return serverDataModel; } @@ -203,13 +204,14 @@ public boolean isExperimentRunning() { return experimentRunning; } - + public boolean isReplaying() { return getId() == null; } public static void main(String[] args) { Runnable createGuiRunnable = new Runnable() { + public void run() { Dimension dimension = new Dimension(700, 700); Facilitator facilitator = Facilitator.getInstance(); @@ -231,10 +233,8 @@ public RoundConfiguration getCurrentRoundConfiguration() { return getServerConfiguration().getCurrentParameters(); } - + public void setServerGameState(ServerDataModel serverGameState) { this.serverDataModel = serverGameState; } - - } --- a/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java Tue Aug 16 19:41:02 2011 -0700 @@ -76,6 +76,7 @@ private int completedQuizzes; private JMenuItem startChatMenuItem; + private JMenuItem showTrustGameMenuItem; public FacilitatorWindow(Dimension dimension, Facilitator facilitator) { this.facilitator = facilitator; @@ -170,6 +171,14 @@ }); menu.add(showInstructionsMenuItem); + showTrustGameMenuItem = new JMenuItem("Show Trust Game"); + showTrustGameMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + facilitator.sendShowTrustGameRequest(); + } + }); + menu.add(showTrustGameMenuItem); + startRoundMenuItem = new JMenuItem("Start"); startRoundMenuItem.setMnemonic(KeyEvent.VK_T); startRoundMenuItem.setEnabled(false); --- a/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Wed Aug 03 17:13:58 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Tue Aug 16 19:41:02 2011 -0700 @@ -54,6 +54,7 @@ import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.SanctionAppliedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; +import edu.asu.commons.foraging.event.ShowTrustGameRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.event.UnlockResourceRequest; import edu.asu.commons.foraging.model.ClientData; @@ -616,6 +617,19 @@ } } }); + addEventProcessor(new EventTypeProcessor<ShowTrustGameRequest>(ShowTrustGameRequest.class) { + public void handle(ShowTrustGameRequest event) { + if (event.getId().equals(facilitatorId)) { + logger.info("Showing trust game."); + for (Identifier id: clients.keySet()) { + transmit(new ShowTrustGameRequest(id)); + } + } + else { + logger.warning("Ignoring show instructions request from id: " + event.getId()); + } + } + }); addEventProcessor(new EventTypeProcessor<BeginRoundRequest>(BeginRoundRequest.class) { public void handle(BeginRoundRequest event) { if (event.getId().equals(facilitatorId)) { Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |