def main(_): game = pyspiel.load_game(FLAGS.game) nfg_text = pyspiel.game_to_nfg_string(game) if FLAGS.outfile is None: print(nfg_text) else: print("Exporting to {}".format(FLAGS.outfile)) outfile = open(FLAGS.outfile, "w") outfile.write(nfg_text) outfile.close()
def test_pd(self): expected_pd_nfg = ("""NFG 1 R "OpenSpiel export of matrix_pd()" { "Player 0" "Player 1" } { 2 2 } 5 5 10 0 0 10 1 1 """) game = pyspiel.load_game("matrix_pd") nfg_text = pyspiel.game_to_nfg_string(game) self.assertEqual(nfg_text, expected_pd_nfg)
def test_mp3p(self): expected_mp3p_nfg = ( """NFG 1 R "OpenSpiel export of matching_pennies_3p()" { "Player 0" "Player 1" "Player 2" } { 2 2 2 } 1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 1 -1 1 -1 -1 -1 -1 1 1 1 1 -1 """) game = pyspiel.load_game("matching_pennies_3p") nfg_text = pyspiel.game_to_nfg_string(game) self.assertEqual(nfg_text, expected_mp3p_nfg)
def test_rps(self): expected_rps_nfg = ("""NFG 1 R "OpenSpiel export of matrix_rps()" { "Player 0" "Player 1" } { 3 3 } 0 0 1 -1 -1 1 -1 1 0 0 1 -1 1 -1 -1 1 0 0 """) game = pyspiel.load_game("matrix_rps") nfg_text = pyspiel.game_to_nfg_string(game) self.assertEqual(nfg_text, expected_rps_nfg)
def test_native_export_import(self): """Check that we can import games that we've exported. We do not do any additional checking here, as these methods are already being extensively tested in nfg_test.cc. The purpose of this test is only to check that the python wrapping works. """ game_strings = [ "matrix_rps", "matrix_shapleys_game", "matrix_pd", "matrix_sh", "blotto(players=2,coins=5,fields=3)", "blotto(players=3,coins=5,fields=3)" ] for game_string in game_strings: game = pyspiel.load_game(game_string) nfg_text = pyspiel.game_to_nfg_string(game) nfg_game = pyspiel.load_nfg_game(nfg_text) self.assertIsNotNone(nfg_game)