10.1 IntroductionAs we saw in Chapter 4, a game player is typically implemented as a web service that receives messages from a Game Manager and replies appropriately. Building a player means writing event handlers for the different types of messages in the GGP communication protocol using subroutines for processing game descriptions and match data. Our job in building a player is to use the available subroutines to implement event handlers for the various GGP messages. Building a game player using a propnet is essentially the same. In fact, all of the methods we have described so far still apply. The main difference is that we replace the subroutines that work directly on game descriptions with subroutines that operate on propnets. For example, in place of the findlegals subroutine we used earlier, we now use a proplegals subroutine that computes legal actions using the propnet; in place of the findterminalp subroutine we used earlier, we now use a propterminalp subroutine that computes whether or not a state is terminal using the propnet; and so forth. We begin this chapter by presenting a representation of propnets as data structures. We then define the basic subroutines for marking propnets and reading marks on propnets. Then we use these subroutines to build up the General Game Playing subroutines needed by our players (e.g. proplegals, propterminalp, and so forth). 10.2 Propositional Nets as Data StructuresBefore we can define methods for processing propnets, we need a representation of those propnets as data structures. In the simple approach taken here, we represent each propnet component as a structured object with various components depending on the type of the object. The connectivity of the propnet is captured by values of these components. A propnet as a whole is represented by an object of the form shown below. The type is propnet. The roles component is a sequence of the roles in the game. The inputs component is a sequence of sequences of input nodes, one sequence for each role; the bases component is a sequence of the base nodes in the game; and the view component is a sequence of the view nodes in the game. The legals component is a sequence of sequences of legal nodes, one sequence for each role; the rewards component is a sequence of sequences of reward nodes; and the terminal component is the terminal node of the game.
An input node is a structured object of the form shown below. The type component is input; the name is the GDL representation of the input; and the mark is an indication of whether the node is true or false in the current state (as determined by the input marking current at each point in time). A base node is a structured object of the form shown below. The type component is base; the name is the GDL representation of the node; the source is the transition that leads to the base node; and the mark is an indication of whether the node is true or false in the current state (as determined by the base marking current at each point in time). A view node is a structured object of the form shown below. The type component is view; the name is the GDL representation of the node; the source is the connective that leads to the view node. A negation is a structured object of the form shown below. The type component is negation, and the source is the proposition that leads to the connective. A conjunction is a structured object of the form shown below. The type component is conjunction, and the sources component is a sequence of propositions that leads to the connective. A disjunction is a structured object of the form shown below. The type component is disjunction, and the sources component is a sequence of propositions that leads to the connective. A transition is a structured object of the form shown below. The type component is transition, and the source is the proposition that leads to the transition. As an example, consider the propnet presented in the preceding chapter. For convenience, it appears here again as Figure 10.1. In what follows, we see how to assemble this propnet manually. In a general game player, it would be automatically generated from the GDL game description. First of all, we create input, base, and view nodes for the propositions in the propnet. Since we do not yet have data structures for our connectives, we initialize the sources of our propositions with null.
Next, we create connectives and insert the propositions as components.
Now, we go back and insert the connectives into the proposition nodes.
Finally, we insert all of these things into the components of mypropnet.
Once we have created our propnet, either manually or automatically from the GDL for a game, we can access the components by simply naming the propnet and one of its components and extracting the desired component. For example, to get a sequence of the base propositions in mypropnet, we would ask for mypropnet.base; and to get the source of proposition r, we would ask for r.source. 10.3 Marking and Reading Propositional NetsIn our approach to General Game Playing using propnets, we use input markings in place of moves and base markings in place of states. In order to compute the various attributes of a game on a given step, we typically mark the input propositions and base propositions of the propnet and then compute the corresponding view marking. We then read the view marking to compute the desired attributes. In this section, we discuss the details of marking and reading propnets, and in the next section we show how they are used. There are two different approaches to marking and reading propnets. In the forward propagation approach, we mark propositions and then propagate the values to compute the values of view propositions dependent on those marks. To answer questions, we then just read the values of the relevant view propositions. In the backward reasoning approach, we mark our base and input propositions but do not propagate. Instead, when we need a value for a view proposition, we work backward from the desired view proposition to determine that value. The forward method saves redundant computation. The backward methods is a little simpler and not much slower. We show the backward method here. Marking propositions is easy. See the subroutines below. We simply iterate through the base propositions or input propositions marking those nodes with values from the input or base vectors of booleans.
Computing the values of view propositions is accomplished by working backwards from the propositions of interests. If the proposition is an input or base proposition, we simply return the mark on that proposition. In the case of a view proposition, we compute the values of propositions for the inputs to the connective feeding the view proposition and combine those values in accordance with the type of the connective.
10.4 Computing Game Playing BasicsNow that we have some tools for marking and reading propnets, let's see how we can use them to define the basic subroutines used in the game playing methods we defined in previous chapters. In order to compute the legal actions for a role in a given state using a propnet, we first mark the base propositions of the propnet using the information in the given state. We then check each of the legality nodes for the given role in the propnet. If the node is true, we put the corresponding input node on the list. When we are done, we return the list of input nodes that we have accumulated in this process. (Note that, to return one of these actions to a game manager, we would need to extract the name component from the corresponding input node.)
The propnext subroutine shown below computes the next state for a given move and a given state using a given propnet. (Note that the move here is assumed to be an input marking, not just a sequence of actions. To simulate a move supplied by a game manager, we would need to convert to an input marking before using propnext.) In executing the propnext subroutine, we first mark the input propositions using the given move, and we mark the base propositions of the propnet using the information in the given state. We then check each of the base propositions in the propnet, collecting those that are true in the next state.
To compute the reward for a given role in a given state using a propnet, we first mark the base propositions as before. We then check each of the reward propositions for the given role until we find one that is true.
Computing whether or not a state is terminal is particularly easy. We mark the base propositions as before and check the terminal node for the propnet.
