Post by Lars Ericson on Jul 19, 2015 19:00:10 GMT -8
GGP Base has the parts necessary to picture the propnet of a game. Consider for example onestep:
(role white)
(role black)
(init o1)
(legal white a)
(legal white b)
(legal black a)
(<= (next o2)
(does white a)
(true o1))
(<= (next o3)
(does white b)
(true o1))
(<= (goal white 0) (true o1))
(<= (goal white 10) (true o2))
(<= (goal white 90) (true o3))
(<= (goal black 0) (true o1))
(<= (goal black 90) (true o2))
(<= (goal black 10) (true o3))
(<= terminal (true o2))
(<= terminal (true o3))
The propnet for this is:
This notation doesn't conform precisely to that used in the GGP course text, but for free it's still something. To get this, we define PropNetDiagram.java:
package org.ggp.base.player.gamer.statemachine.sample;
import org.ggp.base.util.game.CloudGameRepository;
import org.ggp.base.util.game.Game;
import org.ggp.base.util.game.GameRepository;
import org.ggp.base.util.propnet.architecture.PropNet;
import org.ggp.base.util.propnet.factory.OptimizingPropNetFactory;
public class PropnetDiagram{
public static void main(String[] args) throws Exception {
GameRepository repo = new CloudGameRepository("games.ggp.org/base");
String gameKey = "onestep";
Game theGame = repo.getGame(gameKey);
PropNet propnet = OptimizingPropNetFactory.create(theGame.getRules());
String gv_file="c:/Users/Lars/Desktop/moves/aha.gv";
String svg_file="c:/Users/Lars/Desktop/moves/aha.gv.jpg";
propnet.renderToFile(gv_file);
RunCmd dot = new RunCmd();
dot.runCmd("dot", "-Tjpg", gv_file, "-O");
dot.runCmd("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", svg_file, "", "");
}
}
This calls pre-existing stuff in GGP and also this function RunCmd (class? everything in Java is a class) I defined:
package org.ggp.base.player.gamer.statemachine.sample;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public final class RunCmd {
public static void runCmd(String cmd, String arg1, String arg2, String arg3) throws IOException {
Process process = new ProcessBuilder(cmd, arg1, arg2, arg3).start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:", cmd);
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
I was hoping to experience some epiphany about propnets when I looked at the picture for onestep, which is the simplest game in the base repository. I think I need another donut though, because it isn't calling to me yet.
(role white)
(role black)
(init o1)
(legal white a)
(legal white b)
(legal black a)
(<= (next o2)
(does white a)
(true o1))
(<= (next o3)
(does white b)
(true o1))
(<= (goal white 0) (true o1))
(<= (goal white 10) (true o2))
(<= (goal white 90) (true o3))
(<= (goal black 0) (true o1))
(<= (goal black 90) (true o2))
(<= (goal black 10) (true o3))
(<= terminal (true o2))
(<= terminal (true o3))
The propnet for this is:
This notation doesn't conform precisely to that used in the GGP course text, but for free it's still something. To get this, we define PropNetDiagram.java:
package org.ggp.base.player.gamer.statemachine.sample;
import org.ggp.base.util.game.CloudGameRepository;
import org.ggp.base.util.game.Game;
import org.ggp.base.util.game.GameRepository;
import org.ggp.base.util.propnet.architecture.PropNet;
import org.ggp.base.util.propnet.factory.OptimizingPropNetFactory;
public class PropnetDiagram{
public static void main(String[] args) throws Exception {
GameRepository repo = new CloudGameRepository("games.ggp.org/base");
String gameKey = "onestep";
Game theGame = repo.getGame(gameKey);
PropNet propnet = OptimizingPropNetFactory.create(theGame.getRules());
String gv_file="c:/Users/Lars/Desktop/moves/aha.gv";
String svg_file="c:/Users/Lars/Desktop/moves/aha.gv.jpg";
propnet.renderToFile(gv_file);
RunCmd dot = new RunCmd();
dot.runCmd("dot", "-Tjpg", gv_file, "-O");
dot.runCmd("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", svg_file, "", "");
}
}
This calls pre-existing stuff in GGP and also this function RunCmd (class? everything in Java is a class) I defined:
package org.ggp.base.player.gamer.statemachine.sample;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public final class RunCmd {
public static void runCmd(String cmd, String arg1, String arg2, String arg3) throws IOException {
Process process = new ProcessBuilder(cmd, arg1, arg2, arg3).start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:", cmd);
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
I was hoping to experience some epiphany about propnets when I looked at the picture for onestep, which is the simplest game in the base repository. I think I need another donut though, because it isn't calling to me yet.