root/ggpa/ActQNetwork.cpp

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

GGPA code from the good old days of SIGART

Line 
1 /*
2  *  ActQNetwork.cpp
3  */
4
5 #include "ActQNetwork.h"
6
7 /*
8  * ActQNetwork
9  * Parameters:   actionLength - max length on action.toInputs()
10  *               stateLength - max length on state.toInputs()
11  *               legalMoves - all possible moves
12  *
13  * Constructor. Creates a mapping of actions to neural networks.
14  */
15 ActQNetwork::ActQNetwork(int actionLength, int stateLength, vector<Action*> legalMoves)
16 {
17     vector<Action*>::iterator moveItr = legalMoves.begin();
18     pair<Action, QNeuralNetwork> mapPair;
19     for(; moveItr != legalMoves.end(); moveItr++){
20         mapPair.first = *(*moveItr);
21         mapPair.second = QNeuralNetwork(actionLength, stateLength);
22         theMap.insert(mapPair);
23     }
24 }
25
26 ActQNetwork::~ActQNetwork()
27 {
28   /*    map<Action, QNeuralNetwork>::iterator mapItr;
29     mapItr = theMap.begin();
30     while(mapItr != theMap.end())
31     {
32         pair<Action, QNeuralNetwork> *rmPair = mapItr;
33         mapItr++;
34         delete rmPair;
35     }
36   */
37
38 }
39
40 /*
41  * update
42  * Parameters:   state - a State object that represents a state in the game
43  *               action - an Action object that represents an action in the
44  *                        game
45  *               utility - a double that represents the utility to insert
46  *                         for this State/Action pair
47  * No return value
48  *
49  * Updates the entry for the given State/Action pair.
50  */
51 void ActQNetwork::update(State &state, Action &action, double utility)
52 {
53     map<Action, QNeuralNetwork>::iterator mapItr =  theMap.find(action);
54     mapItr->second.update(state, action, utility);
55 }
56
57 /*
58  * getValue
59  * Parameters:   state - a State object that represents a state in the game
60  *               action - an Action object that represents an action in the
61  *                        game
62  * Return value: a double representing the utility of the given State/
63  *   Action pair.
64  * This function will return the current utility of the given State/Action
65  *   pair.  In other words, it will return a value representing how good
66  *   the action is from the state.
67  */
68 double ActQNetwork::getValue(State &state, Action &action)
69 {
70     map<Action, QNeuralNetwork>::iterator mapItr =  theMap.find(action);
71     return mapItr->second.getValue(state, action);
72 }
73
74 /*
75  * writeToFile
76  *
77  * Parameters:   file - String containing the name of the file to write to.
78  * Return value: none
79  *
80  * Writes the QNeuralNetwork to the given file.  If the file does not exist, it
81  *   will be created.  If it does exist, then it will be written to the
82  *   end of the file
83  */
84 void ActQNetwork::writeToFile(string filename)
85 {
86   map<Action, QNeuralNetwork>::iterator mapItr;
87   for(mapItr = theMap.begin(); mapItr != theMap.end(); mapItr++)
88       mapItr->second.writeToFile(filename);   
89 }
90
91 /*
92  * readFromFile
93  *
94  * Parameters:   file - string containing the name of the file to read from
95  * Return value: none
96  *
97  * Reads in a QNeuralNetwork from a file.  The current QNeuralNetwork will be set to
98  *    be this saved QNeuralNetwork
99  */
100 void ActQNetwork::readFromFile(string filename)
101 {
102   map<Action, QNeuralNetwork>::iterator mapItr;
103   for(mapItr = theMap.begin(); mapItr != theMap.end(); mapItr++)
104       mapItr->second.readFromFile(filename);
105 }
106
Note: See TracBrowser for help on using the browser.