/************************************************************************\ |* 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 SizeVisitor extends RealizationVisitor implements Processor { HashSet p1infosets = new HashSet(), p2infosets = new HashSet(), p1weights = new HashSet(), p2weights = new HashSet(); public int p1infoSize() { return p1infosets.size() + 1; } public int p2infoSize() { return p2infosets.size() + 1; } public int p1realSize() { return p1weights.size() + 1; } public int p2realSize() { return p2weights.size() + 1; } Rational minpayoff, maxpayoff; public Rational getMinPayoff() { return minpayoff; } public Rational getMaxPayoff() { return maxpayoff; } public void visitImpPlayerNode(ImpPlayerNode node) { if (node.getPlayer() == 1) { p1infosets.add(p1know); for (GameTree child : node) p1weights.add(p1know + child.getP1Learn()); } else { p2infosets.add(p2know); for (GameTree child : node) p2weights.add(p2know + child.getP2Learn()); } super.visitImpPlayerNode(node); } public void visitGameLeaf(GameLeaf leaf) { Rational value = leaf.getValue(); if (minpayoff == null || minpayoff.greater(value)) minpayoff = value; if (maxpayoff == null || maxpayoff.less(value)) maxpayoff = value; } public void process(ExtensiveForm ef, PrintStream out) { ef.visitBy(this); out.println("Player 1:"); out.println("Information sets: " + p1infoSize()); out.println("Realization weights: " + p1realSize()); out.println("Best payoff: " + maxpayoff); out.println("\nPlayer 2:"); out.println("Information sets: " + p2infoSize()); out.println("Realization weights: " + p2realSize()); out.println("Best payoff: " + minpayoff); } }