// ArgumentGame.java // // main source file for the ArgumentGame (simulation of a rational argument) // -------------------------------------------------------------------------- // game written for/designed by Prof. Ron Lou, loui@ai.cs.wustl.edu // based on the paper "An Argument Game" by Ronald Loui and Wiliam Chen // based on the game "LMNOP" // (see Loui-Norman-Stiefvater-Merrill-Olson-Costello [92] // code by Nina Kang, nkang@husc.harvard.edu, 8/96 import java.applet.Applet; import java.awt.*; import java.lang.*; import java.util.*; // ARGUMENT GAME -- the applet itself public class ArgumentGame extends Applet implements Observer { // DATA STRUCTURES CardDeck deck; // all functions related to the physical cards Case[] cases; // the stacks of cards on the card table Contract contract; // details of the bid, and facts (evidence) GameFlow flow; // coordinates the playing of cards ObservableBool contractDone; // game status ObservableBool cardsGone; // same // GRAPHICS STRUCTURES Panel top; // top half of board Panel bottom; // bottom... Panel buttons; // buttons at bottom of board PanelCollection panels; // basic graphics routines, etc. CardLayout cl1; // controls top panel CardLayout cl2; // controls bottom panel public static void main (String args[]) { Frame f = new Frame ("An ArgumentGame"); ArgumentGame agame = new ArgumentGame(); agame.init(); f.setLayout (new FlowLayout()); f.add (agame); f.resize (500, 580); } public void update (Observable obs, Object arg) { if (obs == contractDone) { top.remove (contract); flow.getContract (contract); cl1.show (top, "Flow"); layout(); Case.formulateSupport(); } else if (obs == cardsGone) { outOfCards(); } } public void init() { initialize_components(); initialize_graphics(); // order is important. } void initialize_components () { deck = new CardDeck(this); contract = new Contract (this); cases = Case.init(true, this); // true-- excludings are on contract.suggestFirstBid(); panels = new PanelCollection (this); flow = new GameFlow (this); contractDone = new ObservableBool (false); contractDone.addObserver (this); cardsGone = new ObservableBool (false); cardsGone.addObserver (this); } void initialize_graphics() { // handle layouts setLayout (new BorderLayout()); add ("North", top = new Panel()); add ("Center", bottom = new Panel()); add ("South", buttons = new Panel()); top.setLayout (cl1 = new CardLayout()); top.add ("Contract", contract); top.add ("Flow", flow); bottom.setLayout (cl2 = new CardLayout ()); bottom.add ("Cases", panels.cases); bottom.add ("Argument", panels.argument); // bottom.add ("Help", panels.help); // no longer implemented // bottom.add ("Choice", flow.myArgument); // -- occurs in GameFlow::getContract() buttons.setLayout (new FlowLayout (FlowLayout.CENTER)); buttons.add (new Button ("View Cases")); buttons.add (new Button ("View Full Tree")); buttons.add (new Button ("View Argument")); // buttons.add (new Button ("Help")); // no longer implemented cl1.show (top, "Contract"); cl2.show (bottom, "Cases"); } public boolean action (Event evt, Object arg) { if (contractDone.getValue() == true) { if ("View Cases".equals(arg)) { cl2.show (bottom, "Cases"); } else if ("View Full Tree".equals (arg)) { cl2.show (bottom, "Argument"); panels.argument.repaint(); } else if ("View Argument".equals (arg)) { cl2.show (bottom, "Choice"); // } else if ("Help".equals (arg)) { // no longer implemented // cl2.show (bottom, "Help"); } } return (true); } public void paint(Graphics g) { } // ------------------ End-of-Game functions --------------------------- // ArgumentGame section 2.5 // // "Play terminates if it is a player's turn to play and that player // cannot make a *sufficient response*; thus, the other player wins." void noRebuttal (String winner) { String msg[] = new String[3]; msg[0] = "Congratulations, " + winner + ":"; msg[1] = "Your opponent was unable to cite"; msg[2] = "a valid counterargument. You win."; top.add ("No Rebuttal", panels.makeMessagePanel (msg)); cl1.show(top, "No Rebuttal"); cl2.show (bottom, "Choice"); layout(); } void badChallenge (String loser) { String msg[] = new String[3]; msg[0] = "Sorry, "+ loser; msg[1] = "You couldn't come up with a valid challenge."; msg[2] = "You lose."; top.add ("Bad Challenge", panels.makeMessagePanel (msg)); cl1.show(top, "Bad Challenge"); cl2.show (bottom, "Cases"); layout(); } // ArgumentGame section 2.5, cont'd. // // "Play terminates if it is the declarer's turn to play and declarer has // exhausted declarer's resources; thus, declarer wins. void noResources () { String msg[] = new String[3]; msg[0] = "Sorry, " + contract.Vladimir() + ":"; msg[1] = "You are out of resources."; msg[2] = "You lose."; top.add ("No Resources", panels.makeMessagePanel (msg)); cl1.show(top, "No Resources"); cl2.show (bottom, "Choice"); layout(); } void outOfCards () { String msg[] = new String[3]; msg[0] = "Sorry, players A and B,"; msg[1] = "You are out of cards."; msg[2] = "Game over."; top.add ("Out of Cards", panels.makeMessagePanel (msg)); cl1.show(top, "Out of Cards"); // flow.myArgument.judge(); cl2.show (bottom, "Choice"); layout(); } void deadCase () { String msg[] = new String[3]; msg[0] = "Sorry, " + contract.Vladimir() + ":"; msg[1] = "You are out of evidence."; msg[2] = "You lose."; top.add ("Dead Case", panels.makeMessagePanel (msg)); cl1.show(top, "Dead Case"); cl2.show (bottom, "Argument"); layout(); } }