cl-ggp/overview/index.html @ 621ae61499ab

cl-ggp: Update site.
author Steve Losh <steve@stevelosh.com>
date Wed, 23 Mar 2016 16:24:01 +0000
parents (none)
children 641956c66398
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Overview / cl-ggp</title>
        <link rel="stylesheet" href="../_dmedia/bootstrap.css"/>
        <link rel="stylesheet" href="../_dmedia/tango.css"/>
        <link rel="stylesheet/less" type="text/css" href="../_dmedia/style.less"/>
        <script src="../_dmedia/less.js" type="text/javascript">
        </script>
    </head>
    <body class="content">
        <div class="wrap">
            <header><h1><a href="..">cl-ggp</a></h1></header>
                <div class="markdown">
<h1 id="overview"><a href="">Overview</a></h1><p><code>cl-ggp</code> handles the GGP protocol for you.  Players are implemented as CLOS
objects.</p>
<div class="toc">
<ul>
<li><a href="#basics">Basics</a></li>
<li><a href="#functionality">Functionality</a><ul>
<li><a href="#player-start-game">player-start-game</a></li>
<li><a href="#player-update-game">player-update-game</a></li>
<li><a href="#player-select-move">player-select-move</a></li>
<li><a href="#player-stop-game">player-stop-game</a></li>
</ul>
</li>
<li><a href="#example-player">Example Player</a></li>
</ul></div>
<h2 id="basics">Basics</h2>
<p>You can create your own player by extending the <code>ggp-player</code> class, creating an
object, and calling <code>start-player</code> on it to fire it up:</p>
<div class="codehilite"><pre>(defclass simple-player (ggp:ggp-player)
  ())

(defvar *player* (make-instance 'simple-player
                                :name "SimplePlayer"
                                :port 4000))

(ggp:start-player *player*)
</pre></div>


<p><code>ggp-player</code> takes <code>:name</code> and <code>:port</code> initargs.  It has a few other internal
slots you shouldn't mess with.</p>
<p>You can kill a player with <code>kill-player</code>.</p>
<h2 id="functionality">Functionality</h2>
<p><code>cl-ggp</code> defines four generic methods that are called on players at various
points in each game.  You can provide method definitions for some or all of
these to let your player do whatever it needs to do.</p>
<p>At a minimum you <strong>must</strong> implement <code>player-select-move</code>.  The others are
optional and will default to doing nothing.</p>
<h3 id="player-start-game">player-start-game</h3>
<div class="codehilite"><pre>(defmethod player-start-game ((player YOUR-PLAYER) rules role start-clock play-clock)
  ...)
</pre></div>


<p>This is called when a new game starts.</p>
<p><code>rules</code> is the GDL rules of the game, parsed into Lisp lists/symbols.  You'll
probably want to feed this into a logic library.</p>
<p><code>role</code> is a symbol representing which role you've been assigned.</p>
<p><code>start-clock</code> is </p>
<p><code>play-clock</code> is </p>
<h3 id="player-update-game">player-update-game</h3>
<div class="codehilite"><pre>(defmethod player-update-game ((player YOUR-PLAYER) moves)
  ...)
</pre></div>


<p>This is called once per turn, to update the game state with the moves each
player selected.</p>
<p><code>moves</code> is a list of the moves made by all players.</p>
<h3 id="player-select-move">player-select-move</h3>
<div class="codehilite"><pre>(defmethod player-select-move ((player YOUR-PLAYER))
  ...)
</pre></div>


<p>This is called once per turn.  It should return the move your player wants to
do.  All players <strong>must</strong> implement this function.</p>
<h3 id="player-stop-game">player-stop-game</h3>
<div class="codehilite"><pre>(defmethod player-stop-game ((player YOUR-PLAYER))
  ...)
</pre></div>


<p>This is called when the game is stopped.  You can use it for things like tearing
down any extra data structures you've made, suggesting a GC to your Lisp, etc.</p>
<h2 id="example-player">Example Player</h2>
                </div>
            <footer><p><i>Made with Lisp and love by <a href="http://stevelosh.com/">Steve Losh</a> in Reykjavík, Iceland.</i></p>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-15328874-3', 'auto');
  ga('send', 'pageview');

</script></footer>
        </div>
    </body>
</html>