WikiPeerCode
/*
* GameMaster.java
*
* Created on June 13 2006
* Last Modified June 16 2006 by Jack
*
* This class oversees games played between agents
*/
package RepMod;
import uchicago.src.sim.gui.NetworkDrawable;
import uchicago.src.sim.network.DefaultDrawableNode;
import uchicago.src.sim.gui.DrawableNonGridNode;
import uchicago.src.sim.util.Random;
import uchicago.src.sim.gui.OvalNetworkItem;
import java.awt.Color;
import uchicago.src.sim.gui.ColorMap;
import uchicago.src.sim.engine.CustomProbeable;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author Jack Waddell
*
*
*/
// GameMaster Constructor
public class GameMaster {
// GUIModel: Stores the model class that runs the graphics
public static GUIModel guiModel = null;
// model: stores the base model
public static RepMod model;
// agentList: Stores a pointer to the agents list
public ArrayList<CustomNode> agentList;
// compare: the comparator for node reputation
public CompNodeRep compare = new CompNodeRep();
//
public double topRepSuccess;
public GameMaster (ArrayList agentList) {
// If the agent list pointer is sent from RepMod
// then changing the list here changes it there as well.
this.agentList = agentList;
}
/////////////////////////////////////////////////////////////
// voteAll
// Inputs: none
// Output: none
// Traverses the agent list, playing a game once between
// all pairs of neighbors on the network.
public void voteAll(){
//for (CustomNode nodej : agentList){
CustomNode voter, focus;
double rSum = 0;
// Traverse the agent list
for (int i = 0; i < agentList.size(); i++){
focus = agentList.get(i);
// Get current node's neighbors: symmetric network
// means that out neighbors are just neighbors.
ArrayList<CustomNode> neighbors = focus.getOutNodes();
for (int j = 0; j < neighbors.size(); j++){
voter = neighbors.get(j);
rSum += voter.vote(focus.getSuccess());
}
focus.updateReputation(rSum);
}
//double blah = calcTopRepSuccesses();
}
/////////////////////////////////////////////////////////////
// calcTopRepSuccesses
public double calcTopRepSuccesses(){
ArrayList<CustomNode> tempList = new ArrayList<CustomNode>();
tempList.addAll(agentList);
Collections.sort(tempList, compare);
for(CustomNode agent : tempList){
//System.out.printf("Agent %d has rep %f\n", agent.getID(), agent.getReputation());
}
return 0;
}
/////////////////////////////////////////////////////////////
// challengeAll
// Inputs: none
// Outputs: none
public void challengeAll(){
//for (CustomNode nodej : agentList){
CustomNode node;
double difficulty = model.getUniformDoubleFromTo(0,1);
// Traverse the agent list
for (int i = 0; i < agentList.size(); i++){
node = agentList.get(i);
node.challenge(difficulty);
}
}
//***********************************************************
// Getters and Setters
public static void setModel(RepMod m) {model = m;}
public static void setGUIModel(GUIModel m) {guiModel = m;}
}