import java.math.*; import java.util.ArrayList; import java.lang.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.awt.Image; import java.io.*; /*The idea is to play Prisoner's Dilemma with n people Payoffs will be dependent on percentage of people playing*/ /*Thoughts: November 9, 2007 "Strategies" will need to be utilized by the prisoners, but how will it play through is the question... Strategies used will be the ones from the site http://www.brembs.net/ipd/ipd.html November 12, 2007 I've completed tit for tat for the most part, but I'm still wondering how exactly I'll implement it. This is only a temporary solution at this point, but I'm still trying to think whether I will actually make a class for strategies or if I will hard code it into the main program. Either method is going to take some time... AND PERHAPS I SHOULD FOCUS ON A GRAPHIC REPRESENTATION AT HOME... November 13, 2007 As luck would have it, I still have my old files of 'Brawler', my APCS project. All I've got to do is derive it to make my JPanel. Until then, I've got to figure out how to implement the other stuff. November 14, 2007 Check out java.sun.com...NOW...Download jdk 6 update 3 November 15, 2007 So, the program works now. We've got a JGrasp window coming up fine and now I'm attempting to make a table From here, I'm looking to do something simplistic, show what the results are. As of now, I'm able to get a table to begin to appear. That's a step forward for graphics...for now anyway. November 20, 2007 The program is working fine now to determine the counting. It turns out that the counting method was fine, but the 'schizophrenic' wasn't necessarily. Now I need to code in other strategies and attempt them in the game. November 28, 2007 Well today's done some researching on code...and played some Megaman: ZXA December 14, 2007 Man, haven't been keeping trac of this 'journal' for a while. So, let's see what happens. December 19, 2007 Okay, let's see what we got. Time to do some more work with the coding, making sure that the strategies are working correctly for one. Hmm, the TFT strategy has presented an interesting predicament. I might be looking at this wrong, but it seems that the player is able to 'predetermine' the opponent's move. I understand that this is due to looking at the ArrayList first, which must be fixed within due time. January 4, 2008 So I've determined something to try for fixing my TFT strategy. I remember now that I implemented a 'previousDecision' function. It will store an old decision BEFORE replacing it with a new one, so this means that I can keep track of the decision for the program to act on later. I'll attempt to implement this later, like THIS WEEKEND. January 7, 2008 More work, Tit for tat is fixed. January 9, 2008 Now, I'm thinking about the strategies to try out, alongside implementing an 'N-participant' thing. I've taken a lok at it and well, the approach is interesting. The 'turtles' that move around fight only against one opponent, each with their own strategy though. January 16, 2008 Today I finished up suspicious TFT and am working on TF2T. I've been reading up some more on the articles, but other than that, not much else. Some general notes: 1. The idea of TFT iterated in a N-person environment is an interesting endeavor. Instead of pitting them all against each other, you've got two randomly fighting each other on a graphical environment. 2. The representation of cooperation (known) will be graphical, and I might follow the idea of turtles moving about. January 18, 2008 So today, since I'm in school, let's see what I got to work on. I'm going to implement the multiple opponents scheme, but I also want to attempt something...Depnding on the strategy I'm thinking about having large factions in itself fight off against each other */ public class prisonerdilemma extends JPanel { int sizer; //int toppay=4; //To the sole betrayer //int midpay=3; //To the two who remain silent //int lowpay=1; //To the two who betray each other //int nopay=0; //To the two who cooperated //ArrayList prisoners; public static void main(String[] arguments) throws IOException { ArrayList prisoners=new ArrayList(); //To keep track of who is in prison ArrayList decisions=new ArrayList(); //To keep track of their decisions /*JFrame f=new JFrame(); JFrame frame = new JFrame(); frame.setSize(1000, 1000); frame.setLocation(0, 0); prisonerdilemma game=new prisonerdilemma(); frame.setContentPane(game); frame.setDefaultCloseOperation(3); frame.setVisible(true); frame.setFocusable(true); game.requestFocus(); */ prisonerdilemma game=new prisonerdilemma(); } public prisonerdilemma() throws IOException { InputStreamReader checker=new InputStreamReader(System.in); BufferedReader buffy=new BufferedReader(checker); System.out.print("How many prisoners? "); String input=buffy.readLine(); int rosSize=(Integer.parseInt(input)); System.out.print("How many rounds? "); input=buffy.readLine(); int rounds=(Integer.parseInt(input)); //input=buffy.readLine(); ArrayList prisoners=new ArrayList(); ArrayList decisions= new ArrayList(); int rostNumb=0; while(rostNumb!=rosSize) { prisoner slammer=new prisoner(rostNumb); System.out.print("What strategy? 1. R, 2. TFT, 3. STFT, 4. TF2T"); input=buffy.readLine(); if(input=="R"||Integer.parseInt(input)==1) slammer.setStrat("RANDOM"); else if(input=="TFT"||Integer.parseInt(input)==2) slammer.setStrat("TFT"); else if(input=="STFT"||Integer.parseInt(input)==3) slammer.setStrat("STFT"); prisoners.add(slammer); rostNumb++; } rostNumb=0; while(rostNumb!=rosSize) { prisoner guard=(prisoner) prisoners.get(rostNumb); System.out.println("Prisoner #" + guard.getID() + " strategy is "+ guard.getStrat()); rostNumb++; } int chart=prisoners.size(); if(chart>2) { System.out.println("We got more prisoners."); } sizer=chart; System.out.println(chart); int k=0; // int rounds=6; int round=0; int number=prisoners.size(); int pri=0; int reader=0; int truthcount=0; int falsecount=0; while(round!=rounds) { pri=0; System.out.println("Round " + round + ":"); System.out.println("FIGHT!"); while(pri0) { player.setPreviousDecision(what); } String which=player.getStrat(); if(which.equals("RANDOM")) random(player); else if(which.equals("TFT")) titForTat(prisoners, player, round); else if(which.equals("STFT")) suspiciousTitForTat(prisoners, player, round); else if(which.equals("TF2T")) break; //boolean what=player.getDecision(); what=player.getDecision(); /****FROM HERE A VARIETY OF STRATEGIES SHALL BE SET FOR PLAY FOR NOW, IT CAN SWITCH BETWEEN TFT AND RANDOM******/ if(what==true) { truthcount++; System.out.println("Prisoner # " + name + " has decided to cooperate"); System.out.println("Truth: " + truthcount); } else { falsecount++; System.out.println("Prisoner # " + name + " has decided to betray."); System.out.println("False: " + falsecount); } decisions.add(new Boolean(what)); pri++; System.out.println("Current Pay of #" + name + ": " + player.getPay()); } if(truthcount==falsecount) { CooperateBetray(prisoners); } else if(truthcount>falsecount) { CooperateCooperate(prisoners); } else if(falsecount>truthcount) { BetrayBetray(prisoners); } round++; truthcount=0; falsecount=0; } } private BufferedImage img, img2; Graphics buffer; ImageIcon icon; /* public void paintComponent(Graphics g) { //g.setColor(Color.white); g.setColor(Color.black); g.fillRect(0, 0, 1000, 1000); g.setColor(Color.green); //for(int k=0; k<250; k++) //g.drawLine(0, 200, 1000, 200); //g.drawLine(0, 0, 1000, 0); for(int k=50; k<1000; k+=(1000/(sizer +1))) { g.drawLine(0, k, 1000, k); } //g.drawLine(0, 0, 0, 250); } */ static boolean roulette() { double rat=Math.random(); if(rat<0.5) return true; else return false; } static void CooperateCooperate(ArrayList list) { System.out.println("Co-op + Co-op"); int midpay=3; int size=list.size(); int counter=0; while(counter=truers) player.setDecision(false); else if(falsers=truers) player.setDecision(false); else if(falsers