GameMaster.java.wp: Difference between revisions
From Santa Fe Institute Events Wiki
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
* | * | ||
* Created on June 13 2006 | * Created on June 13 2006 | ||
* Last Modified June | * Last Modified June 16 2006 by Jack | ||
* | * | ||
* This class oversees games played between agents | * This class oversees games played between agents | ||
Line 20: | Line 20: | ||
import uchicago.src.sim.engine.CustomProbeable; | import uchicago.src.sim.engine.CustomProbeable; | ||
import java.util.ArrayList; | import java.util.ArrayList; | ||
import java.util.Collections; | |||
/** | /** | ||
* | * | ||
Line 38: | Line 39: | ||
// agentList: Stores a pointer to the agents list | // agentList: Stores a pointer to the agents list | ||
public ArrayList<CustomNode> agentList; | public ArrayList<CustomNode> agentList; | ||
// compare: the comparator for node reputation | |||
public CompNodeRep compare = new CompNodeRep(); | |||
// | // | ||
Line 73: | Line 77: | ||
focus.updateReputation(rSum); | focus.updateReputation(rSum); | ||
} | } | ||
//double blah = calcTopRepSuccesses(); | |||
} | } | ||
Line 78: | Line 83: | ||
// calcTopRepSuccesses | // calcTopRepSuccesses | ||
public double 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; | |||
} | } | ||
Latest revision as of 21:45, 16 June 2006
/* * 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;} }