Package org.ggp.base.server

Examples of org.ggp.base.server.GameServer


    return true;
  }

  public synchronized void abortOngoingMatch(String matchID) {
    if (gameServers.containsKey(matchID)) {
      GameServer server = gameServers.get(matchID).get();
      if (server != null) {
        server.abort();
      }
    }
  }
View Full Code Here


      match.setPlayerNamesFromHost(playerNames);
      if (spec.shouldScramble) {
        match.enableScrambling();
      }

      GameServer gameServer = new GameServer(match, hosts, ports);
      if (spec.shouldDetail) {
        gameServer.addObserver(errorPanel);
        gameServer.addObserver(historyPanel);
        gameServer.addObserver(visualizationPanel);
        gameServer.addObserver(statesPanel);
      }
      gameServer.addObserver(schedulingPanel);
      gameServer.addObserver(leaderboardPanel);
      gameServer.addObserver(this);
      gameServer.start();

      activePlayers.addAll(playerNames);

      if (spec.shouldSave) {
        File matchesDir = new File(System.getProperty("user.home"), "ggp-saved-matches");
        if (!matchesDir.exists()) {
          matchesDir.mkdir();
        }
        File matchFile = new File(matchesDir, match.getMatchId() + ".json");
        gameServer.startSavingToFilename(matchFile.getAbsolutePath());
      }
      if (spec.shouldPublish) {
        if (!match.getGame().getRepositoryURL().contains("127.0.0.1")) {
          gameServer.startPublishingToSpectatorServer("http://matches.ggp.org/");
          gameServer.setForceUsingEntireClock();
        }
      }

      gameServers.put(spec.matchID, new WeakReference<GameServer>(gameServer));
      schedulingQueue.remove(spec);
View Full Code Here

          fakeHosts.add("SamplePlayer" + i);
          fakePorts.add(9147+i);
        }

        // Set up a game server to play through the game, with all players playing randomly.
        final GameServer theServer = new GameServer(theMatch, fakeHosts, fakePorts);
        for (int i = 0; i < fakeHosts.size(); i++) {
          theServer.makePlayerPlayRandomly(i);
        }

        // TODO: Allow a custom state machine to be plugged into the GameServer so that we can
        // simulate games using this tool with custom state machines, to verify they're sane.

        final Set<GdlSentence> oldContents = new HashSet<GdlSentence>();
        final int[] nState = new int[1];
        theServer.addObserver(new Observer() {
      @Override
      public void observe(Event event) {
        if (event instanceof ServerNewGameStateEvent) {
          MachineState theCurrentState = ((ServerNewGameStateEvent)event).getState();
                  if(nState[0] > 0) System.out.print("State[" + nState[0] + "]: ");
                  Set<GdlSentence> newContents = theCurrentState.getContents();
                  for(GdlSentence newSentence : newContents) {
                      if(hideStepCounter && newSentence.toString().contains("step")) continue;
                      if(hideControlProposition && newSentence.toString().contains("control")) continue;
                      if(!oldContents.contains(newSentence)) {
                          System.out.print("+" + newSentence + ", ");
                      }
                  }
                  for(GdlSentence oldSentence : oldContents) {
                      if(hideStepCounter && oldSentence.toString().contains("step")) continue;
                      if(hideControlProposition && oldSentence.toString().contains("control")) continue;
                      if(!newContents.contains(oldSentence)) {
                          System.out.print("-" + oldSentence + ", ");
                      }
                  }
                  System.out.println();
                  oldContents.clear();
                  oldContents.addAll(newContents);

                  if(showCurrentState) System.out.println("State[" + nState[0] + "] Full: " + theCurrentState);
                  nState[0]++;
        } else if (event instanceof ServerNewMovesEvent) {
          System.out.println("Move taken: " + ((ServerNewMovesEvent)event).getMoves());
        } else if (event instanceof ServerCompletedMatchEvent) {
              System.out.println("State[" + nState[0] + "] Full (Terminal): " + oldContents);
              System.out.println("Match information: " + theMatch);
              System.out.println("Goals: " + ((ServerCompletedMatchEvent)event).getGoals());
              try {
                System.out.println("Match information cryptographically signed? " + SignableJSON.isSignedJSON(new JSONObject(theMatch.toJSON())));
                System.out.println("Match information cryptographic signature valid? " + SignableJSON.verifySignedJSON(new JSONObject(theMatch.toJSON())));
              } catch (JSONException je) {
                je.printStackTrace();
              }
              System.out.println("Game over.");
        }
      }
    });

        theServer.start();
        theServer.join();
    }
View Full Code Here

    }
    Match match = new Match(matchName, -1, startClock, playClock, game);
    match.setPlayerNamesFromHost(playerNames);

    // Actually run the match, using the desired configuration.
    GameServer server = new GameServer(match, hostNames, portNumbers);
    server.start();
    server.join();

    // Open up the directory for this tournament.
    // Create a "scores" file if none exists.
    File f = new File(tourneyName);
    if (!f.exists()) {
      f.mkdir();
      f = new File(tourneyName + "/scores");
      f.createNewFile();
    }

    // Open up the XML file for this match, and save the match there.
    f = new File(tourneyName + "/" + matchName + ".xml");
    if (f.exists()) f.delete();
    BufferedWriter bw = new BufferedWriter(new FileWriter(f));
    bw.write(match.toXML());
    bw.flush();
    bw.close();

    // Open up the JSON file for this match, and save the match there.
    f = new File(tourneyName + "/" + matchName + ".json");
    if (f.exists()) f.delete();
    bw = new BufferedWriter(new FileWriter(f));
    bw.write(match.toJSON());
    bw.flush();
    bw.close();

    // Save the goals in the "/scores" file for the tournament.
    bw = new BufferedWriter(new FileWriter(tourneyName + "/scores", true));
    List<Integer> goals = server.getGoals();
    String goalStr = "";
    String playerStr = "";
    for (int i = 0; i < goals.size(); i++)
    {
      Integer goal = server.getGoals().get(i);
      goalStr += Integer.toString(goal);
      playerStr += playerNames.get(i);
      if (i != goals.size() - 1)
      {
        playerStr += ",";
View Full Code Here

                }

                match.setPlayerNamesFromHost(playerNames);

                GamerLogger.startFileLogging(match, "kiosk");
                kioskServer = new GameServer(match, hosts, ports);
                kioskServer.givePlayerUnlimitedTime((flipRoles.isSelected()? 1 : 0));
                kioskServer.addObserver(theHumanGamer);
                kioskServer.addObserver(this);
                kioskServer.start();
View Full Code Here

TOP

Related Classes of org.ggp.base.server.GameServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.