/************************************************************************\ |* 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.game; import gtf.util.*; import java.util.*; import java.io.*; public class Strategy> { Map vals; public final T ZERO, ONE; public Strategy(Map vals) { this.vals = vals; T val = vals.entrySet().iterator().next().getValue(); ZERO = val.zero(); ONE = val.one(); } public static Strategy makeDouble() { try { Map vals = new HashMap(); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); for (String line = input.readLine() ; line != null ; line = input.readLine()) { if (line.startsWith("p1") || line.startsWith("p2")) { StringTokenizer st = new StringTokenizer(line, "\t"); String real = st.nextToken(); vals.put(real.substring(0, real.length() - 1), new DoubleReal(Double.parseDouble(st.nextToken()))); } } return new Strategy(vals); } catch (Exception e) { throw new RuntimeException("Strategy.makeDouble", e); } } public static Strategy makeRational() { try { Map vals = new HashMap(); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); for (String line = input.readLine() ; line != null ; line = input.readLine()) { if (line.startsWith("p1") || line.startsWith("p2")) { StringTokenizer st = new StringTokenizer(line, "\t"); String real = st.nextToken(); vals.put(real.substring(0, real.length() - 1), new Rational(st.nextToken())); } } return new Strategy(vals); } catch (Exception e) { throw new RuntimeException("Strategy.makeRational", e); } } public void print(PrintStream out) { String[] keys = vals.keySet().toArray(new String[0]); Arrays.sort(keys);//, new StringLengthComparator()); out.println("\nPlayer 1:"); for (String key : keys) { if (key.startsWith("p1")) out.println(key + ":\t" + vals.get(key)); } out.println("\nPlayer 2:"); for (String key : keys) { if (key.startsWith("p2")) out.println(key + ":\t" + vals.get(key)); } } public T probOf(String seq) { T temp = vals.get(seq); if(temp == null) return ZERO; return temp; } public Map getMap() { Map temp = new HashMap(); temp.putAll(vals); return temp; } }