/************************************************************************\ |* 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.Rational; import java.util.Iterator; public class PrintVisitor extends EmptyProcessor { String indent = ""; public void visitExtensiveForm(ExtensiveForm ef) { out.println("Name of the game: " + ef.getName()); super.visitExtensiveForm(ef); } public void visitImpPlayerNode(ImpPlayerNode node) { out.println(indent + "Player " + node.getPlayer()); String oldindent = indent; indent += "| "; Iterator ci = node.iterator(); while(ci.hasNext()) { GameTree child = ci.next(); if (! ci.hasNext()) indent = oldindent + " "; out.println(oldindent + "+-" + child.getPlayerLearn(node.getPlayer()) + ":"); child.visitBy(this); } /*for (GameTree child : node) { out.println(oldindent + "+-" + child.getPlayerLearn(node.getPlayer()) + ":"); child.visitBy(this); }*/ indent = oldindent; } public void visitImpRandomNode(ImpRandomNode node) { out.println(indent + "Nature"); String oldindent = indent; indent += "| "; Rational sum = node.getProbSum(); Iterator ci = node.iterator(); while(ci.hasNext()) { GameTree child = ci.next(); if (! ci.hasNext()) indent = oldindent + " "; out.println(oldindent + "+-P" + child.getPlayerLearn() + " = " + child.getProbMult().divide(sum)); child.visitBy(this); } /*for (GameTree child : node) { out.println(oldindent + "+-P" + child.getPlayerLearn() + " = " + child.getProbMult().divide(sum)); child.visitBy(this); }*/ indent = oldindent; } public void visitGameLeaf(GameLeaf leaf) { out.println(indent + "Payoff " + leaf.getValue()); } }