Package stanfordlogic.game

Examples of stanfordlogic.game.Gamer


   
    private Gamer makeGamer(String gameId, Parser parser)
    {
        try {
            Constructor<? extends Gamer> c = gamerType_.getConstructor(new Class [] {String.class, Parser.class});
            Gamer g = c.newInstance(new Object[] {gameId, parser});
            return g;
        }
        catch (Exception e) {
            // this is really, really bad.
            e.printStackTrace();
View Full Code Here


    public Gamer makeGamer(String gameId, GdlAtom role, GdlList description,
                           int startClock, int playClock)
    {
        Parser parser = GameManager.getParser();
       
        Gamer gamer = makeGamer(gameId, parser);
       
        GameInformation gameInfo = new MetaGdl(parser).examineGdl(description);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts(gameInfo.getAllGrounds());
       
        AbstractReasoner reasoner = new BasicReasoner(staticKb, gameInfo.getIndexedRules(), parser);
       
        TermObject myRole = (TermObject) TermObject.buildFromGdl(role);
       
        gamer.initializeGame(myRole, playClock, gameInfo, reasoner);
       
        return gamer;
    }
View Full Code Here

    public Gamer makeGamer(String gameId, GdlAtom role, GdlList description,
                           int startClock, int playClock)
    {
        Parser parser = GameManager.getParser();
       
        Gamer gamer = new RandomGamer(gameId, parser);
       
        GameInformation gameInfo = new MetaGdl(parser).examineGdl(description);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts(gameInfo.getAllGrounds());
       
        AbstractReasoner reasoner = new BasicReasoner(staticKb, gameInfo.getIndexedRules(), parser);
       
        TermObject myRole = (TermObject) TermObject.buildFromGdl(role);
       
        gamer.initializeGame(myRole, playClock, gameInfo, reasoner);
       
        return gamer;
    }
View Full Code Here

            logger_.severe(gameId_ + ": Previous move list in STOP message was not a GDL list!");
            finish();
            return;
        }
       
        Gamer game = GameManager.getGame(gameId_);
        if(game == null)
        {
            logger_.severe("No game found for play request ID: " + gameId_);
            finish();
            return;
View Full Code Here

    public Gamer makeGamer(String gameId, GdlAtom role, GdlList description,
                           int startClock, int playClock)
    {
        Parser parser = GameManager.getParser();
       
        Gamer gamer = new LegalGamer(gameId, parser);
       
        GameInformation gameInfo = new MetaGdl(parser).examineGdl(description);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts(gameInfo.getAllGrounds());
       
        AbstractReasoner reasoner = new BasicReasoner(staticKb, gameInfo.getIndexedRules(), parser);
       
        TermObject myRole = (TermObject) TermObject.buildFromGdl(role);
       
        gamer.initializeGame(myRole, playClock, gameInfo, reasoner);
       
        return gamer;
    }
View Full Code Here

            if ( prevExp instanceof GdlAtom == false || prevExp.equals( GameManager.getParser().TOK_NIL ) == false )
                throw new IllegalArgumentException("PLAY request doesn't have LIST and doesn't have NIL atom as prev-moves!");
            prevMoves = null; // empty prev moves
        }
       
        Gamer game = GameManager.getGame(gameId_);
        if(game == null)
        {
            logger_.severe("No game found for play request ID: " + gameId_);
            finish();
            return;
        }
       
        logger_.info(gameId_ + ": Beginning move think." + prevMovesStr);
       
        Triple<GdlExpression,String,String> next;
       
        try
       
            next = game.play(prevMoves);
        }
        catch (Exception e)
        {
            logger_.severe(gameId_ + ": Exception while processing 'game.play':" + e.toString());
           
View Full Code Here

        GdlList description = (GdlList) content_.getElement(3);
       
        int start = Integer.parseInt( content_.getElement(4).toString() );
        int play = Integer.parseInt( content_.getElement(5).toString() );
        //crea juego
        Gamer gamer = GameManager.newGame(gameId_, role, description, start, play);
       
        if (gamer != null) {
            logger_.info(gameId_ + ": Game successfully created.");
        }
        else {
View Full Code Here

           
            // put in a temporary game:
            games_.put(gameId, null);
        }
       
        Gamer g = gamerFactory_.makeGamer(gameId, role, description, startClock, playClock);
       
        synchronized(GameManager.class)
        {
            games_.put(gameId, g);
        }
View Full Code Here

     * @param gameId Name of the game to terminate.
     * @param prevMoves The last set of moves made in the game.
     */
    public static synchronized void endGame(String gameId, GdlList prevMoves)
    {
        Gamer gamer = games_.get(gameId);
       
        if (gamer == null)
        {
            logger_.severe(gameId + ": WARNING: Attempting to terminate game [" + gameId
                + "], but no such game");
            return;
        }
       
        try
        {
            StringBuilder prevMovesStr = new StringBuilder();
            prevMovesStr.append(" Previous moves: ");
            for ( GdlExpression exp : prevMoves )
            {
                prevMovesStr.append(exp.toString());
                prevMovesStr.append("  ");
            }

            logger_.info(gameId + ": Beginning payoff computation." + prevMovesStr);

            // Get the list of payoffs: <Role, Payoff, IsMe>
            List<Triple<String, Integer, Boolean>> results = gamer.getPayoffs(prevMoves);
           
            // Figure out what the longest role is
            int maxRoleLength = 0;
            for ( Triple<String, Integer, Boolean> res : results )
                maxRoleLength = Math.max(maxRoleLength, res.first.length());

            // Print out the payoffs
            for ( Triple<String, Integer, Boolean> res : results )
            {
                // print the right amount of spaces (so that things line up right)
                StringBuilder spacing = new StringBuilder();
                for ( int i = 0; i < maxRoleLength - res.first.length(); i++ )
                    spacing.append(" ");

                logger_.info("       " + ( res.third ? "->" : "  " ) + " " + res.first
                                + spacing + " " + res.second + " "
                                + ( res.third ? "<-" : "  " ));
            }
        }
        catch (Exception e)
        {
            logger_.severe(gameId + ": Error computing payoff: " + e.getClass().getName() + " - " + e.getMessage());
        }
       
        // tell the game it's time to die.
        gamer.stopIt();
        games_.remove(gameId);
    }
View Full Code Here

TOP

Related Classes of stanfordlogic.game.Gamer

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.