Resistance.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef RESISTANCE_HPP
00007 #define RESISTANCE_HPP
00008
00009 #include "Hex.hpp"
00010 #include "HexEval.hpp"
00011 #include "HexBoard.hpp"
00012 #include "Groups.hpp"
00013
00014 _BEGIN_BENZENE_NAMESPACE_
00015
00016
00017
00018
00019 class AdjacencyGraph
00020 {
00021 public:
00022
00023
00024 AdjacencyGraph();
00025
00026 ~AdjacencyGraph();
00027
00028 std::vector<bool>& operator[](int n);
00029
00030 const std::vector<bool>& operator[](int n) const;
00031
00032 private:
00033 std::vector< std::vector<bool> > m_adj;
00034 };
00035
00036 inline AdjacencyGraph::AdjacencyGraph()
00037 : m_adj(BITSETSIZE, std::vector<bool>(BITSETSIZE, false))
00038 { }
00039
00040 inline AdjacencyGraph::~AdjacencyGraph()
00041 { }
00042
00043 inline std::vector<bool>& AdjacencyGraph::operator[](int n)
00044 {
00045 return m_adj[n];
00046 }
00047
00048 inline const std::vector<bool>& AdjacencyGraph::operator[](int n) const
00049 {
00050 return m_adj[n];
00051 }
00052
00053
00054
00055
00056 struct ConductanceValues
00057 {
00058
00059 double no_connection;
00060
00061
00062 double empty_to_empty;
00063
00064
00065 double color_to_empty;
00066
00067
00068 double color_to_color;
00069
00070
00071 ConductanceValues()
00072 : no_connection(0.0),
00073 empty_to_empty(1.0),
00074 color_to_empty(2.0),
00075 color_to_color(0.0)
00076 { }
00077 };
00078
00079
00080
00081
00082 class Resistance
00083 {
00084 public:
00085
00086
00087 explicit Resistance();
00088
00089
00090 virtual ~Resistance();
00091
00092
00093
00094 bool SimulateAndOverEdge() const;
00095
00096 void SetSimulateAndOverEdge(bool enable);
00097
00098
00099
00100
00101 void Evaluate(const HexBoard& brd);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 void Evaluate(const HexBoard& brd,
00113 AdjacencyGraph graph[BLACK_AND_WHITE]);
00114
00115
00116
00117
00118 void Evaluate(const Groups& groups, AdjacencyGraph graph[BLACK_AND_WHITE]);
00119
00120
00121
00122
00123 double Resist(HexColor color) const;
00124
00125
00126
00127
00128 HexEval Score() const;
00129
00130
00131
00132 HexEval Score(HexPoint cell, HexColor color) const;
00133
00134
00135
00136 HexEval Score(HexPoint cell) const;
00137
00138 private:
00139
00140
00141 void ComputeScores(HexColor color, const Groups& brd,
00142 const AdjacencyGraph& graph,
00143 const ConductanceValues& values,
00144 HexEval* out);
00145
00146
00147 void ComputeScore();
00148
00149 HexEval m_score;
00150 HexEval m_resistance[BLACK_AND_WHITE];
00151 HexEval m_scores[BLACK_AND_WHITE][BITSETSIZE];
00152
00153 bool m_simulate_and_over_edge;
00154 };
00155
00156 inline bool Resistance::SimulateAndOverEdge() const
00157 {
00158 return m_simulate_and_over_edge;
00159 }
00160
00161 inline void Resistance::SetSimulateAndOverEdge(bool enable)
00162 {
00163 m_simulate_and_over_edge = enable;
00164 }
00165
00166 inline HexEval Resistance::Score() const
00167 {
00168 return m_score;
00169 }
00170
00171 inline HexEval Resistance::Score(HexPoint cell) const
00172 {
00173
00174 return m_scores[BLACK][cell] + m_scores[WHITE][cell];
00175 }
00176
00177 inline HexEval Resistance::Score(HexPoint cell, HexColor color) const
00178 {
00179
00180 return m_scores[color][cell];
00181 }
00182
00183
00184
00185
00186 namespace ResistanceUtil
00187 {
00188
00189 void Initialize();
00190
00191
00192
00193 void AddAdjacencies(const HexBoard& brd,
00194 AdjacencyGraph graph[BLACK_AND_WHITE]);
00195
00196
00197
00198 void SimulateAndOverEdge(const HexBoard& brd,
00199 AdjacencyGraph graph[BLACK_AND_WHITE]);
00200
00201 }
00202
00203
00204
00205 _END_BENZENE_NAMESPACE_
00206
00207 #endif // RESISTANCE_HPP