/************************************************************************\ |* 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.*; public class RealizationVisitor implements Visitor { String p1real = "p1", p2real = "p2", p1know = "p1", p2know = "p2"; Rational prob = Rational.ONE; public void visitExtensiveForm(ExtensiveForm ef) { GameTree tree = ef.getGameTree(); p1know += tree.getP1Learn(); p2know += tree.getP2Learn(); ef.getGameTree().visitBy(this); p1know = "p1"; p2know = "p2"; } public void visitImpPlayerNode(ImpPlayerNode node) { String oldp1know = p1know, oldp2know = p2know; if (node.getPlayer() == 1) { String oldp1real = p1real; for (GameTree child : node) { p1real = p1know = oldp1know + child.getP1Learn(); p2know = oldp2know + child.getP2Learn(); child.visitBy(this); } p1real = oldp1real; } else { String oldp2real = p2real; for (GameTree child : node) { p2real = p2know = oldp2know + child.getP2Learn(); p1know = oldp1know + child.getP1Learn(); child.visitBy(this); } p2real = oldp2real; } p1know = oldp1know; p2know = oldp2know; } public void visitImpRandomNode(ImpRandomNode node) { String oldp1know = p1know, oldp2know = p2know; Rational oldprob = prob; Rational probbase = prob.divide(node.getProbSum()); for (GameTree child : node) { p1know = oldp1know + child.getP1Learn(); p2know = oldp2know + child.getP2Learn(); prob = probbase.multiply(child.getProbMult()); child.visitBy(this); } p1know = oldp1know; p2know = oldp2know; prob = oldprob; } public void visitGameLeaf(GameLeaf leaf) {} }