root/ggpa/Action.h

Revision 1, 4.7 kB (checked in by pantley2, 4 years ago)

GGPA code from the good old days of SIGART

Line 
1 /*
2  * Action.h
3  *
4  * Header file for Action class
5  *
6  */
7
8 #ifndef ACTION_H
9 #define ACTION_H
10
11 #include <vector>
12 #include <string>
13 using namespace std;
14
15 #include "Sentence.h"
16
17 /*
18  * This class of objects represents an action in a game. It will contain
19  *    a name and several parameters.  For a given action, there will always
20  *    be the same number of parameters.
21  */
22 class Action : public Sentence {
23
24 private:
25
26     // declare any private variables here
27     string actor;
28    
29     // the possible actors
30     vector<string> possibleActors;
31
32 public:
33
34    /*
35          * Constructor for Action
36          * Parameters:  theValues - a vector of values for the Action
37          *              theStructure - a pointer to a SentenceStructure. Must be an action.
38     *       theActor - the current actor for this Action
39     *       actors - the possible actors for this Action
40          * Return type: none
41          * Sets the values of the sentence equal to a copy of theValues,
42          * checking that the values are all in the SentenceStructure.
43          */
44     Action(vector<string> theValues, SentenceStructure* theStructure,
45            string theActor, const vector<string>& actors);
46
47     Action(const Action &action);
48
49     /*
50      * getActor
51      * No parameters
52      * Return type: string
53      * Returns the name of the player that does this action
54      */
55     string getActor() const;
56
57     /*
58      * setActor
59      * Parameters: theActor - the name of the player that does this action
60      * Return type: none
61      * Sets the actor to be theActor
62      */
63     void setActor(string theActor);
64
65     /**
66      * getAtomicAction
67      * Parameters: variableMap - a mapping of the variables
68      * Return type: a new Sentence
69      * Creates a new sentence with any variables mapped by the parameter map
70      */
71     Action* getAtomicAction(map<string, string> variableMap) const;
72
73     /**
74      * getAtomicSentence
75      * Parameters: variableMap - a mapping of the variables
76      * Return type: a new Sentence
77      * Creates a new sentence with any variables mapped by the parameter map
78      */
79     virtual Sentence* getAtomicSentence(map<string, string> variableMap) const;
80
81    /**
82     * getVariables
83     * No parameters.
84     * Return type: a map from variables to vectors of of their possible values
85     * Searches through the sentence and its dependencies, and returns all
86     * of the variables, along with their posible values
87     */
88    virtual map<string, vector<string> > getVariables() const;
89
90     //int operator=(const Action &action);
91
92     /*
93      * operator==
94      * Parameters: action - an action to compare to
95      * Return type: bool
96      * Returns true if the actions are identical, and false otherwise
97      */
98     bool operator==(const Action &action) const;
99    
100     //bool operator<(const Action &action) const;
101
102     /******************************************************************
103      * These three functions will be required for using the Action with a
104      *    neural network.  Do not change their signatures unless absolutely
105      *    necessary.
106      */
107
108     /*
109      * getName
110      * Parameters: None
111      * Return value: string
112      * Returns the name of the action
113      */
114     // already exists in Sentence.h
115     // string getName() const;
116
117     /*
118      * toInputs
119      *
120      * Parameters:   None
121      * Return value: An array of doubles, each between 0 and 1
122      *
123      * This function converts a state to an array of doubles, each between 0
124      * and 1.  This array will always be the same for a specific Action.
125      */
126     vector<double> toInputs() const;
127
128     /*
129      * inputSize
130      *
131      * Parameters: None
132      * Return value: int
133      * Returns the number of inputs required for a Action.  This is the same
134      * as the length of the array returned by the toInputs function.
135      */
136     int inputSize() const;
137
138    /*
139     * print
140     * Parameters: output: a stream to output to.
141     *             indent: indent on each line
142     * No return type.
143     * Prints the sentence to the given stream
144     */
145    void print(ostream& output = cout, string indent = "") const;
146
147     /*
148      * mergeValues
149      * No parameters or return type.
150      * Merges possible values for variables in this sentence.
151      */
152     virtual void mergeValues();
153
154 private:
155    /*
156     * getVariables
157     * Parameters: variableMap: a map where we should add the new variables
158     * Return type: none
159     * Adds the variables and their set of possible values to the variableMap
160     */
161    void getVariables(map<string, vector<string> >& variableMap) const;
162    
163    /*
164     * mergeValues
165     * Parameters: variableMap:  a multimap from variables to their set of
166     *                           possible values
167     * Return type: none
168     * Merges the sets of values for the variables
169     */
170    virtual void mergeValues(multimap<string, PossibleValues*>& variableMap);
171
172 };
173
174 #endif
175
Note: See TracBrowser for help on using the browser.