/************************************************************************\ |* gtf is a framework for analyzing two-player zero-sum games *| |* Copyright (C) 2005 Troels Bjerre Sorensen *| |* *| |* This program is free software; you can redistribute it and/or modify *| |* it under the terms of the GNU General Public License as published by *| |* the Free Software Foundation; either version 2 of the License, or *| |* (at your option) any later version. *| |* *| |* This program is distributed in the hope that it will be useful, but *| |* WITHOUT ANY WARRANTY; without even the implied warranty of *| |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *| |* General Public License for more details. *| |* *| |* You should have received a copy of the GNU General Public License *| |* along with this program; if not, write to the *| |* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *| |* Boston, MA 02111-1307, USA. *| \************************************************************************/ package gtf; import gtf.game.*; import gtf.util.*; import java.io.*; import java.util.*; public class GambitVisitor extends RealizationVisitor implements Processor { PrintStream out; Map p1infosets = new HashMap(), p2infosets = new HashMap(); Map outcomes = new HashMap(); public void process(ExtensiveForm ef, PrintStream err) { String name = ef.getName(); try {out = new PrintStream(new FileOutputStream(new File(name + ".efg")));} catch (Exception e) {err.println(e);} out.println("EFG 2 R \"" + name + "\" { \"Player 1\" \"Player 2\" }\n\"\"\n"); ef.visitBy(this); out.flush(); out.close(); } public void visitImpPlayerNode(ImpPlayerNode node) { int player = node.getPlayer(); Integer infoset; switch (node.getPlayer()) { case 1: out.print("p \"\" 1 "); infoset = p1infosets.get(p1know); if (infoset == null) { infoset = p1infosets.size() + 1; p1infosets.put(p1know, infoset); } out.print(infoset + " \"" + p1know + "\" { "); break; case 2: out.print("p \"\" 2 "); infoset = p2infosets.get(p2know); if (infoset == null) { infoset = p2infosets.size() + 1; p2infosets.put(p2know, infoset); } out.print(infoset + " \"" + p2know + "\" { "); break; } for (GameTree child : node) out.print("\"" + child.getPlayerLearn(player) + "\" "); out.println("} 0"); super.visitImpPlayerNode(node); } public void visitImpRandomNode(ImpRandomNode node) { out.print("c \"\" 1 \"(0,1)\" { "); Rational sum = node.getProbSum(); for (GameTree child : node) { out.print("\"(" + child.getPlayerLearn(1) + "," + child.getPlayerLearn(2) + ")\" " + child.getProbMult() + "/" + sum + " "); } out.println("} 0"); super.visitImpRandomNode(node); } public void visitGameLeaf(GameLeaf leaf) { out.print("t \"\" "); Rational value = leaf.getValue(); Integer outcome = outcomes.get(value); if (outcome == null) { outcome = outcomes.size() + 1; outcomes.put(value, outcome); } out.println(outcome + " \"Outcome " + outcome + "\" { " + value + ", " + value.negate() + " }"); } }