Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AIKBSplayTree.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2007 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef AIKBSPLAYTREE_H
22 #define AIKBSPLAYTREE_H
23 
24 #include "AIKB.h"
25 
26 namespace OpenSkyNet {
27  namespace AI {
35  class KBSplayTree : public KB {
36  class BinaryNode {
37  std::list<Record> _records;
38  BinaryNode *_left, *_right;
39 
40  BinaryNode() : _left(0), _right(0) {}
41  BinaryNode(const std::list<Record>& records_, BinaryNode* left_, BinaryNode* right_)
42  : _records(records_), _left(left_), _right(right_) {}
43 
44  friend class KBSplayTree;
45  };
46 
47  BinaryNode* _root;
48  int _size;
49 
54  void reclaimMemory(BinaryNode* t) const;
55 
60  BinaryNode* clone(BinaryNode* t) const;
61 
62  float calcStateScore(int stateId, BinaryNode* t, bool first) const;
63 
65 
66  void rotateWithLeftChild(BinaryNode*& k2) const;
67  void rotateWithRightChild(BinaryNode*& k1) const;
68 
78  void splay(const Record& x, BinaryNode*& t) const;
80  public:
81  KBSplayTree() : _root(0), _size(0) {}
82  KBSplayTree(int maxRecords_, unsigned int reservedRecords_,
83  unsigned int initParamsSizeOfReservedRecords_) : KB(maxRecords_,
84  reservedRecords_,initParamsSizeOfReservedRecords_), _root(0), _size(0) {}
85  KBSplayTree(const KBSplayTree& rhs_) { *this = rhs_; }
86  const KBSplayTree& operator=(const KBSplayTree& rhs_);
87  virtual ~KBSplayTree() { clear(); }
88 
91  virtual bool add(const Record& record_, bool disallowIfPremNameExists_=false);
92  virtual void remove(const Record& record_, bool all_, int numOfParamsToCheck_=-1);
93  virtual const std::list<Record>& find(const Record& record_);
94  virtual bool isEmpty() const;
95  virtual void clear();
96  virtual int size() const;
97  virtual float calcStateScore(int stateId_) const;
99  };
100  }
101 }
102 
103 #endif //AIKBSPLAYTREE_H
KBSplayTree()
Definition: AIKBSplayTree.h:81
Definition: AIBase.h:148
KBSplayTree(const KBSplayTree &rhs_)
Definition: AIKBSplayTree.h:85
virtual bool add(const Record &record_, bool disallowIfPremNameExists_=false)
Definition: AIKBSplayTree.cpp:19
virtual void clear()
Definition: AIKBSplayTree.cpp:127
Definition: AIKB.h:33
virtual int size() const
Definition: AIKBSplayTree.cpp:133
Definition: AIKBSplayTree.h:35
const KBSplayTree & operator=(const KBSplayTree &rhs_)
Definition: AIKBSplayTree.cpp:9
virtual bool isEmpty() const
Definition: AIKBSplayTree.cpp:123
virtual const std::list< Record > & find(const Record &record_)
Definition: AIKBSplayTree.cpp:113
KBSplayTree(int maxRecords_, unsigned int reservedRecords_, unsigned int initParamsSizeOfReservedRecords_)
Definition: AIKBSplayTree.h:82
virtual ~KBSplayTree()
Definition: AIKBSplayTree.h:87