[Housebot-developers] SF.net SVN: housebot: [468] trunk/housebot/src
Status: Alpha
Brought to you by:
j_house
|
From: <tg...@us...> - 2007-02-08 09:26:19
|
Revision: 468
http://svn.sourceforge.net/housebot/?rev=468&view=rev
Author: tgiphil
Date: 2007-02-08 01:25:20 -0800 (Thu, 08 Feb 2007)
Log Message:
-----------
* added some of Point functionality to position
* converted Point to position
* converted Vector to std::vector
* converted Dictionary to std::map
* removed GameTreeSavedSGFAdapter (merged into GameTree)
* moved Coordinate.* to pattern directory
* removed Point.h, Vector.h, Dictionary.h, and GameTreeSavedSGFAdapter.h
[Passes basic regression test]
Modified Paths:
--------------
trunk/housebot/src/brains/blunder.cpp
trunk/housebot/src/brains/fundamental.cpp
trunk/housebot/src/brains/fuseki9.cpp
trunk/housebot/src/brains/regions.cpp
trunk/housebot/src/brains/static_ld.cpp
trunk/housebot/src/go_board.cpp
trunk/housebot/src/go_board.hpp
trunk/housebot/src/gtp/GTPBoard.cpp
trunk/housebot/src/gtp/GTPBoard.h
trunk/housebot/src/gtp/GTPCommand.cpp
trunk/housebot/src/gtp/GTPCommand.h
trunk/housebot/src/gtp/GTPFunctionObject.h
trunk/housebot/src/gtp/GTPGoBoard.h
trunk/housebot/src/housebot.cpp
trunk/housebot/src/pattern/DFAMatrix.cpp
trunk/housebot/src/pattern/DFAMatrix.h
trunk/housebot/src/pattern/DFAMatrixBuilder.cpp
trunk/housebot/src/pattern/DFAMatrixBuilder.h
trunk/housebot/src/pattern/DFAMatrixCache.h
trunk/housebot/src/pattern/DFAMatrixCache3.h
trunk/housebot/src/pattern/DFANode.h
trunk/housebot/src/pattern/DFAPattern.cpp
trunk/housebot/src/pattern/Makefile.am
trunk/housebot/src/pattern/Pattern.cpp
trunk/housebot/src/pattern/Pattern.h
trunk/housebot/src/pattern/PatternCode.h
trunk/housebot/src/pattern/PatternCollection.h
trunk/housebot/src/pattern/PatternDetector.cpp
trunk/housebot/src/pattern/PatternDetector.h
trunk/housebot/src/pattern/PatternHit.h
trunk/housebot/src/pattern/PatternInterpreter.cpp
trunk/housebot/src/pattern/PatternTest.cpp
trunk/housebot/src/pattern/SpiralIterator.h
trunk/housebot/src/phil/GoBoardInterface.h
trunk/housebot/src/phil/GoBoardIterator.h
trunk/housebot/src/phil/Makefile.am
trunk/housebot/src/phil/MemFile.cpp
trunk/housebot/src/phil/SmartString.h
trunk/housebot/src/sgf/GameTree.cpp
trunk/housebot/src/sgf/GameTree.h
trunk/housebot/src/sgf/Makefile.am
trunk/housebot/src/sgf/SGFCollection.cpp
trunk/housebot/src/sgf/SGFCollection.h
trunk/housebot/src/sgf/SGFNode.cpp
trunk/housebot/src/sgf/SGFNode.h
trunk/housebot/src/sgf/SGFProperty.cpp
trunk/housebot/src/sgf/SGFSequence.cpp
trunk/housebot/src/sgf/SGFSequence.h
Added Paths:
-----------
trunk/housebot/src/pattern/Coordinate.cpp
trunk/housebot/src/pattern/Coordinate.h
Removed Paths:
-------------
trunk/housebot/src/phil/Coordinate.cpp
trunk/housebot/src/phil/Coordinate.h
trunk/housebot/src/phil/Dictionary.h
trunk/housebot/src/phil/Point.cpp
trunk/housebot/src/phil/Point.h
trunk/housebot/src/phil/Vector.h
trunk/housebot/src/sgf/GameTreeSaveSGFAdapter.cpp
trunk/housebot/src/sgf/GameTreeSaveSGFAdapter.h
Modified: trunk/housebot/src/brains/blunder.cpp
===================================================================
--- trunk/housebot/src/brains/blunder.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/brains/blunder.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -24,7 +24,7 @@
#include "brains.hpp"
#include "blunder.hpp"
#include "pattern/PatternDetector.h"
-#include "phil/Vector.h"
+#include <vector>
namespace brain{
blunder::blunder(collective &c, st_list &rw, const_st_list &ro)
@@ -76,10 +76,8 @@
mLazy = false;
}
- Point lPoint = mGoBoardInterface.ToPoint(p);
-
- for(unsigned int i=0;i<mPatternDetector->mPatternHits.Size();i++)
- if (mPatternDetector->mPatternHits[i].mHitLocation == lPoint)
+ for(unsigned int i=0;i<mPatternDetector->mPatternHits.size();i++)
+ if (mPatternDetector->mPatternHits[i].mHitLocation == p)
return 1;
return 0;
Modified: trunk/housebot/src/brains/fundamental.cpp
===================================================================
--- trunk/housebot/src/brains/fundamental.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/brains/fundamental.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -48,8 +48,8 @@
colors->reinitialize(boardsize, empty);
/// \bug Old chains are not deleted...
chains->reinitialize(boardsize, NULL);
- position p(0,0);
- while(p.onboard(boardsize)){
+ position p(0,0);
+ while(p.onboard(boardsize)){ // future change to !p.is_pass()
colors->new_object(p, empty);
chains->new_object(p, NULL);
p.next(boardsize);
Modified: trunk/housebot/src/brains/fuseki9.cpp
===================================================================
--- trunk/housebot/src/brains/fuseki9.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/brains/fuseki9.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -24,7 +24,7 @@
#include "brains.hpp"
#include "fuseki9.hpp"
#include "pattern/PatternDetector.h"
-#include "phil/Vector.h"
+#include <vector>
namespace brain{
fuseki9::fuseki9(collective &c, st_list &rw, const_st_list &ro)
@@ -83,10 +83,9 @@
for (index_t row=0;row<mGoBoardInterface.GetBoardSize();row++){
for (index_t col=0;col<mGoBoardInterface.GetBoardSize();col++){
position p(row,col);
- Point lPoint = mGoBoardInterface.ToPoint(p);
- for(unsigned int i=0;i<mPatternDetector->mPatternHits.Size();i++)
- if (mPatternDetector->mPatternHits[i].mHitLocation == lPoint)
+ for(unsigned int i=0;i<mPatternDetector->mPatternHits.size();i++)
+ if (mPatternDetector->mPatternHits[i].mHitLocation == p)
return true;
}
}
@@ -104,10 +103,8 @@
mLazy = false;
}
- Point lPoint = mGoBoardInterface.ToPoint(p);
-
- for(unsigned int i=0;i<mPatternDetector->mPatternHits.Size();i++)
- if (mPatternDetector->mPatternHits[i].mHitLocation == lPoint)
+ for(unsigned int i=0;i<mPatternDetector->mPatternHits.size();i++)
+ if (mPatternDetector->mPatternHits[i].mHitLocation == p)
return 1;
return 0;
Modified: trunk/housebot/src/brains/regions.cpp
===================================================================
--- trunk/housebot/src/brains/regions.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/brains/regions.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -94,7 +94,7 @@
// it into the status trackers.
chainPtr ch(new chain(size));
position p(0,0);
- while(p.onboard(size)) {
+ while(p.onboard(size)) { // change to !p.is_pass()
ch->add_member(p);
p.next(size);
}
Modified: trunk/housebot/src/brains/static_ld.cpp
===================================================================
--- trunk/housebot/src/brains/static_ld.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/brains/static_ld.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -197,7 +197,7 @@
clear_data();
static_ld_position_type->reinitialize(size, UNSURROUNDABLE);
position p(0,0);
- while(p.onboard(size)) {
+ while(p.onboard(size)) { // change to !p.is_pass()
static_ld_position_type->new_object(p, UNSURROUNDABLE);
p.next(size);
}
Modified: trunk/housebot/src/go_board.cpp
===================================================================
--- trunk/housebot/src/go_board.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/go_board.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -99,3 +99,58 @@
};
return out;
}
+
+position::position(const SmartString& pString)
+{
+ if ((pString.Length() == 2) || (pString.Length() == 3))
+ {
+ const char a2 = toupper(pString[0]);
+ col = pString[1]-'0';
+
+ if (pString.Length() == 3)
+ {
+ int y2 = toupper(pString[2])-'0';
+ col = (col * 10) + y2;
+ }
+ col--;
+
+ row = ((a2<'I') ? (a2-'A') : (a2-'A')-1);
+ }
+ else
+ col = row = position::pass_value;
+}
+
+const SmartString position::ToSGFString(const unsigned int pBoardSize) const
+{
+ if (is_pass())
+ return "";
+
+ char a = row+'a';
+ char b = (pBoardSize - col - 1)+'a';
+
+ SmartString s;
+
+ s << a << b;
+
+ return s;
+}
+
+const SmartString position::ToString(const bool pShowNull) const
+{
+ if (is_pass())
+ return SmartString(pShowNull ? "(NULL)" : "PASS");
+
+ char c = row+'A';
+
+ if (c >= 'I')
+ c++;
+
+ int d = (col+1);
+
+ SmartString s;
+
+ s << c << d;
+
+ return s;
+}
+
Modified: trunk/housebot/src/go_board.hpp
===================================================================
--- trunk/housebot/src/go_board.hpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/go_board.hpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -30,6 +30,9 @@
#include <list>
#include <set>
+#include "phil/SmartString.h"
+#include "pattern/Coordinate.h"
+
#ifndef bzero
void ___bzero(void *s, size_t n);
#define bzero(_ptr, _len) ___bzero((_ptr),(_len))
@@ -59,19 +62,22 @@
/// \brief Holds board position information
class position{
+private:
+ static const index_t pass_value = (index_t) -1;
public:
index_t row;
index_t col;
public:
- position(index_t row = (index_t)-1, index_t col = (index_t)-1): row(row),col(col){}
- position(const position &x):row(x.row),col(x.col){}
+ inline position(): row(pass_value),col(pass_value){}
+ inline position(index_t row, index_t col): row(row),col(col){}
+ inline position(const position &x):row(x.row),col(x.col){}
/// anything not on the board returns false (even the one-beyond board edge)
- bool onboard (unsigned int pboardsize) const { return (row<pboardsize) && (col<pboardsize); }
- bool is_pass () const {return row==(index_t)-1 && col==(index_t)-1;}
+ inline bool onboard (unsigned int pboardsize) const { return (row<pboardsize) && (col<pboardsize); }
+ inline bool is_pass () const {return (row==position::pass_value) && (col==position::pass_value);}
// used for looping over the entire board (usually)
- void next (unsigned int pboardsize)
+ inline void next (unsigned int pboardsize)
{
assert(row < pboardsize && col < pboardsize);
@@ -91,25 +97,63 @@
}
// We're at the last point on the board...
- row = (index_t) -1;
- col = (index_t) -1;
+ row = position::pass_value;
+ col = position::pass_value;
}
- position shifted_copy(int row_shift, int col_shift) const{
+ inline position shifted_copy(int row_shift, int col_shift) const{
return position(row+row_shift, col+col_shift);
}
- bool operator < (const position &p) const {
+ inline bool operator < (const position &p) const {
if (row != p.row)
return row < p.row;
return col < p.col;
}
- bool operator == (const position &p) const {
+ inline bool operator == (const position &p) const {
return row==p.row && col==p.col;
}
- bool operator != (const position &p) const {
+ inline bool operator != (const position &p) const {
return row!=p.row || col!=p.col;
}
+
+ //inline position(const char a, const int y)
+ //{
+ // row = y-1;
+ // char a2 = toupper(a);
+ // col = ((a2<'I') ? (a2-'A') : (a2-'A')-1);
+ //}
+
+ // from SGF position representation
+ inline position(const char a, const char b, unsigned int boardsize)
+ {
+ char a2 = toupper(a);
+ char b2 = toupper(b);
+
+ if (a2=='T' || b2 =='T') // pass
+ {
+ col = row = position::pass_value;
+ return;
+ }
+
+ col = boardsize - (b2-'A'+1);
+ row = a2-'A';
+ }
+
+ inline position(const Coordinate &c) : row (c.x()) , col(c.y())
+ {
+// row = c.x()
+// col = c.y();
+ }
+
+ position(const SmartString& pString);
+ const SmartString ToString(const bool pShowNull = false) const;
+ const SmartString ToSGFString(const unsigned int pBoardSize) const;
+
+ // hack for now
+ inline int compress() const { return (col << 8) | row; }
+ inline position(int i) : row( i | ((1 << 8) - 1)), col(i >> 8) { }
+
};
std::ostream& operator << (std::ostream &out, const position &x);
Modified: trunk/housebot/src/gtp/GTPBoard.cpp
===================================================================
--- trunk/housebot/src/gtp/GTPBoard.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPBoard.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -19,7 +19,7 @@
* MA 02110-1301, USA. *
*********************************************************************/
-// GTPBoardAbstract.cpp: implementation of the GTPBoardAbstract class.
+// GTPBoard.cpp: implementation of the GTPBoard class.
//
//////////////////////////////////////////////////////////////////////
Modified: trunk/housebot/src/gtp/GTPBoard.h
===================================================================
--- trunk/housebot/src/gtp/GTPBoard.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPBoard.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -27,11 +27,11 @@
#define GTPBoardH
#include "phil/SmartString.h"
-#include "phil/Dictionary.h"
#include "GTPInternalResponse.h"
#include "GTPCommand.h"
#include "GTPFunctionObject.h"
#include <time.h>
+#include <map>
enum ScoringSystem
{
@@ -48,8 +48,8 @@
{
protected:
- Dictionary<const SmartString, GTPFunction> RegisteredCommands;
- Dictionary<const SmartString, GTPFunctionObject*> RegisteredCommandObjects;
+ std::map<const SmartString, GTPFunction> RegisteredCommands;
+ std::map<const SmartString, GTPFunctionObject*> RegisteredCommandObjects;
SmartString Commands;
clock_t Clock;
Modified: trunk/housebot/src/gtp/GTPCommand.cpp
===================================================================
--- trunk/housebot/src/gtp/GTPCommand.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPCommand.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -36,7 +36,7 @@
mComment.Erase();
mRawCommand.Erase();
mArguments.Erase();
- mArgumentParts.Clear();
+ mArgumentParts.clear();
mCommandNbr = 0;
if (lCmd.IsEmpty())
@@ -103,7 +103,7 @@
else
if (at != argstart)
{
- mArgumentParts.Add(SmartString(lCmd,argstart,at-argstart));
+ mArgumentParts.push_back(SmartString(lCmd,argstart,at-argstart));
argstart = at+1;
}
@@ -111,7 +111,7 @@
}
if (at != argstart)
- mArgumentParts.Add(SmartString(lCmd,argstart,at-argstart));
+ mArgumentParts.push_back(SmartString(lCmd,argstart,at-argstart));
if (end != 0)
mArguments = SmartString(lCmd,start,end-start+1);
Modified: trunk/housebot/src/gtp/GTPCommand.h
===================================================================
--- trunk/housebot/src/gtp/GTPCommand.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPCommand.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -27,9 +27,8 @@
#define GTPCommandH
#include "phil/SmartString.h"
-#include "phil/Vector.h"
+#include <vector>
#include "../go_board.hpp"
-#include "phil/Point.h"
class GTPCommand
{
@@ -40,7 +39,7 @@
SmartString mArguments;
SmartString mComment;
SmartString mRawCommand;
- Vector<SmartString> mArgumentParts;
+ std::vector<SmartString> mArgumentParts;
public:
bool Verify(const SmartString& p_Command, const SmartString& p_Arguments, const SmartString& p_Comment, const int p_CommandNbr = 0) const;
@@ -68,18 +67,18 @@
{ return mRawCommand; }
inline const unsigned int GetArgumentCount() const
- { return mArgumentParts.Size(); }
+ { return mArgumentParts.size(); }
inline const SmartString GetArgument(const unsigned int i) const
{
- _ASSERT(i<mArgumentParts.Size());
+ _ASSERT(i<mArgumentParts.size());
return mArgumentParts[i];
}
inline bool GetArgumentAsInteger(const unsigned int i, int& p) const
{
- if (i>=mArgumentParts.Size())
+ if (i>=mArgumentParts.size())
return false;
if (mArgumentParts[i].Length() == 0)
@@ -90,7 +89,7 @@
inline bool GetArgumentAsFloat(const unsigned int i, float& p) const
{
- if (i>=mArgumentParts.Size())
+ if (i>=mArgumentParts.size())
return false;
if (mArgumentParts[i].Length() == 0)
@@ -101,7 +100,7 @@
inline bool GetArgumentAsColor(const unsigned int i, color_t& pColor) const
{
- if (i>=mArgumentParts.Size())
+ if (i>=mArgumentParts.size())
return false;
if (mArgumentParts[i].Length() < 1)
@@ -117,15 +116,15 @@
return true;
}
- inline bool GetArgumentAsPoint(const unsigned int i, Point& pPoint) const
+ inline bool GetArgumentAsPosition(const unsigned int i, position& pPosition) const
{
- if (i>=mArgumentParts.Size())
+ if (i>=mArgumentParts.size())
return false;
if (mArgumentParts[i].Length() < 2)
return false;
- pPoint = Point(mArgumentParts[i]);
+ pPosition = position(mArgumentParts[i]);
return true;
}
Modified: trunk/housebot/src/gtp/GTPFunctionObject.h
===================================================================
--- trunk/housebot/src/gtp/GTPFunctionObject.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPFunctionObject.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -65,6 +65,7 @@
if (x=="white" || x=="White" || x=="WHITE")
return white;
assert(false);
+ return empty;
}
template<typename inputType> inline
Modified: trunk/housebot/src/gtp/GTPGoBoard.h
===================================================================
--- trunk/housebot/src/gtp/GTPGoBoard.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/gtp/GTPGoBoard.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -34,7 +34,6 @@
#include "../go_board.hpp"
#include "sgf/GameTree.h"
-#include "sgf/GameTreeSaveSGFAdapter.h"
#include "sgf/SGFCollection.h"
#include "brains/fuseki9.hpp"
@@ -62,10 +61,9 @@
bool SaveGame(const SmartString& pFileName)
{
- return GameTreeSaveSGFAdapter::CreateSGFFile(mGameTree,pFileName);
+ return mGameTree.CreateSGFFile(pFileName);
}
-
// way to upgrade the the base class members to this derived class
static inline GTPGoBoard& _GTPGoBoard(GTPBoard& pGTPBoard)
{
@@ -127,12 +125,12 @@
if (!pGTPCommand.GetArgumentAsColor(0, lColor))
return InvalidParameterResponse();
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint(1,lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition(1,lPosition))
return InvalidParameterResponse();
- if (Board(pGTPBoard).PlaceStone(lColor, lPoint, true)) // Undo should be supported
+ if (Board(pGTPBoard).PlaceStone(lColor, lPosition, true)) // Undo should be supported
return GTPInternalResponse();
else
return GTPInternalResponse(false, "invalid move");
@@ -194,10 +192,10 @@
if (!pGTPCommand.GetArgumentAsColor(0, lColor))
return InvalidParameterResponse();
- const Point lPoint = Board(pGTPBoard).RandomBestMove(lColor);
+ const position lPosition = Board(pGTPBoard).RandomBestMove(lColor);
- if (Board(pGTPBoard).PlaceStone(lColor, lPoint, true))
- return GTPInternalResponse(true,lPoint.ToString());
+ if (Board(pGTPBoard).PlaceStone(lColor, lPosition, true))
+ return GTPInternalResponse(true,lPosition.ToString());
else
return InvalidMoveResponse();
}
@@ -212,11 +210,11 @@
if (!pGTPCommand.GetArgumentAsColor(0, lColor))
return InvalidParameterResponse();
- const Point lPoint = Board(pGTPBoard).BestMove(lColor);
+ const position lPosition = Board(pGTPBoard).BestMove(lColor);
// note: does not play move like previous version
- return GTPInternalResponse(true,lPoint.ToString());
+ return GTPInternalResponse(true,lPosition.ToString());
}
static GTPInternalResponse GTPLoadSGF(const GTPCommand& pGTPCommand, GTPBoard& pGTPBoard)
@@ -269,12 +267,12 @@
if (pGTPCommand.GetArgumentCount() < 1)
return MissingParametersResponse();
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint(0,lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition(0,lPosition))
return InvalidParameterResponse();
- color_t lColor = Board(pGTPBoard).GetColor(lPoint);
+ color_t lColor = Board(pGTPBoard).GetColor(lPosition);
if (lColor == empty)
return GTPInternalResponse(true,"empty");
@@ -325,15 +323,15 @@
int middle = ((Board(pGTPBoard).GetBoardSize()+1)/2)-1;
int right = Board(pGTPBoard).GetBoardSize()-spacing;
- if (lHandicap >= 1) Board(pGTPBoard).PlaceStone(black,Point(left,left));
- if (lHandicap >= 2) Board(pGTPBoard).PlaceStone(black,Point(right,right));
- if (lHandicap >= 3) Board(pGTPBoard).PlaceStone(black,Point(left,right));
- if (lHandicap >= 4) Board(pGTPBoard).PlaceStone(black,Point(right,left));
- if (lHandicap >= 5) Board(pGTPBoard).PlaceStone(black,Point(left,middle));
- if (lHandicap >= 6) Board(pGTPBoard).PlaceStone(black,Point(right,middle));
- if (lHandicap >= 7) Board(pGTPBoard).PlaceStone(black,Point(middle,left));
- if (lHandicap >= 8) Board(pGTPBoard).PlaceStone(black,Point(middle,right));
- if (lHandicap >= 9) Board(pGTPBoard).PlaceStone(black,Point(middle,middle));
+ if (lHandicap >= 1) Board(pGTPBoard).PlaceStone(black,position(left,left));
+ if (lHandicap >= 2) Board(pGTPBoard).PlaceStone(black,position(right,right));
+ if (lHandicap >= 3) Board(pGTPBoard).PlaceStone(black,position(left,right));
+ if (lHandicap >= 4) Board(pGTPBoard).PlaceStone(black,position(right,left));
+ if (lHandicap >= 5) Board(pGTPBoard).PlaceStone(black,position(left,middle));
+ if (lHandicap >= 6) Board(pGTPBoard).PlaceStone(black,position(right,middle));
+ if (lHandicap >= 7) Board(pGTPBoard).PlaceStone(black,position(middle,left));
+ if (lHandicap >= 8) Board(pGTPBoard).PlaceStone(black,position(middle,right));
+ if (lHandicap >= 9) Board(pGTPBoard).PlaceStone(black,position(middle,middle));
SmartString s;
@@ -358,12 +356,12 @@
for (int i=0;i<lHandicap;i++)
{
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint(i,lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition(i,lPosition))
return InvalidParameterResponse();
- Board(pGTPBoard).PlaceStone(black,lPoint);
+ Board(pGTPBoard).PlaceStone(black,lPosition);
}
return GTPInternalResponse();
@@ -381,16 +379,16 @@
if (!pGTPCommand.GetArgumentAsColor(i * 2, lColor))
return InvalidParameterResponse();
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint((i * 2) + 1, lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition((i * 2) + 1, lPosition))
return InvalidParameterResponse();
- if (!Board(pGTPBoard).PlaceStone(lColor, lPoint, false))
+ if (!Board(pGTPBoard).PlaceStone(lColor, lPosition, false))
{
SmartString lString;
- lString << "invalid move - " << lPoint.ToString();
+ lString << "invalid move - " << lPosition.ToString();
return GTPInternalResponse(false, lString);
}
@@ -412,10 +410,10 @@
SmartString s;
// std::vector<position> best_moves = Board(pGTPBoard).the_collective->best_moves(Board(pGTPBoard).ToColorT(lColor),10);
- Vector<Point> lPoints = Board(pGTPBoard).GetTopMoves(lColor, 10);
+ std::vector<position> lPositions = Board(pGTPBoard).GetTopMoves(lColor, 10);
- for (unsigned int i=0; i< lPoints.Size(); i++)
- s << lPoints[i].ToString() << " " << (i+1) << " ";
+ for (unsigned int i=0; i< lPositions.size(); i++)
+ s << lPositions[i].ToString() << " " << (i+1) << " ";
return GTPInternalResponse(true,s);
}
@@ -425,12 +423,12 @@
if (pGTPCommand.GetArgumentCount() < 1)
return MissingParametersResponse();
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint(0,lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition(0,lPosition))
return InvalidParameterResponse();
- life_status lUnconditionalSafety = Board(pGTPBoard).GetLifeStatus(lPoint);
+ life_status lUnconditionalSafety = Board(pGTPBoard).GetLifeStatus(lPosition);
switch (lUnconditionalSafety)
{
@@ -518,12 +516,12 @@
if (!pGTPCommand.GetArgumentAsColor(0, lColor))
return InvalidParameterResponse();
- Point lPoint;
+ position lPosition;
- if (!pGTPCommand.GetArgumentAsPoint(1,lPoint))
+ if (!pGTPCommand.GetArgumentAsPosition(1,lPosition))
return InvalidParameterResponse();
- return GTPInternalResponse(true, Board(pGTPBoard).IsLegal(lColor, lPoint) ? "1" : "0");
+ return GTPInternalResponse(true, Board(pGTPBoard).IsLegal(lColor, lPosition) ? "1" : "0");
}
static GTPInternalResponse GTPAllMoveValues(const GTPCommand& pGTPCommand, GTPBoard& pGTPBoard)
@@ -565,7 +563,7 @@
lPatternDetector.FindPatterns(Board(pGTPBoard),lColor);
- for(unsigned int i=0;i<lPatternDetector.mPatternHits.Size();i++)
+ for(unsigned int i=0;i<lPatternDetector.mPatternHits.size();i++)
lString << lPatternDetector.mPatternHits[i].mHitLocation.ToString() << " ";
return GTPInternalResponse(true,lString);
@@ -587,7 +585,7 @@
lPatternDetector.FindPatterns(Board(pGTPBoard),lColor);
- for(unsigned int i=0;i<lPatternDetector.mPatternHits.Size();i++)
+ for(unsigned int i=0;i<lPatternDetector.mPatternHits.size();i++)
lString << lPatternDetector.mPatternHits[i].mHitLocation.ToString() << " ";
return GTPInternalResponse(true,lString);
Modified: trunk/housebot/src/housebot.cpp
===================================================================
--- trunk/housebot/src/housebot.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/housebot.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -114,13 +114,14 @@
{
po::options_description desc("Top Level Options");
+
desc.add_options()
("help,h", "produce this help message")
("unit_test,t", "Run unit tests")
("config,c", po::value<std::string>()->default_value("housebot.cfg"),
"Config file")
;
-
+
register_brains(desc);
collective the_collective(desc);
Added: trunk/housebot/src/pattern/Coordinate.cpp
===================================================================
--- trunk/housebot/src/pattern/Coordinate.cpp (rev 0)
+++ trunk/housebot/src/pattern/Coordinate.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -0,0 +1,26 @@
+/*********************************************************************
+ * Copyright (C) 2006 Phil Garcia *
+ * *
+ * This file is part of HouseBot and MyGoBot *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
+ * MA 02110-1301, USA. *
+ *********************************************************************/
+
+// Coordinate.cpp: implementation of the Coordinate class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "Coordinate.h"
Added: trunk/housebot/src/pattern/Coordinate.h
===================================================================
--- trunk/housebot/src/pattern/Coordinate.h (rev 0)
+++ trunk/housebot/src/pattern/Coordinate.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -0,0 +1,219 @@
+/*********************************************************************
+ * Copyright (C) 2006 Phil Garcia *
+ * *
+ * This file is part of HouseBot and MyGoBot *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
+ * MA 02110-1301, USA. *
+ *********************************************************************/
+
+// Coordinate.h: interface for the Coordinate class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#ifndef CoordinateH
+#define CoordinateH
+
+#include "phil/SmartString.h"
+
+class Coordinate
+{
+private:
+
+protected:
+ short mx;
+ short my;
+
+public:
+ inline Coordinate()
+ {
+ mx = 0;
+ my = 0;
+ }
+
+ inline Coordinate(const Coordinate &p)
+ {
+ mx = p.mx;
+ my = p.my;
+ }
+
+ inline Coordinate(const short p_x, const short p_y)
+ {
+ mx = p_x;
+ my = p_y;
+ }
+
+ ~Coordinate() { } // not a virtual method! (if virtual then object size changes doubles)
+
+ inline int x() const
+ {
+ return mx;
+ }
+
+ inline int y() const
+ {
+ return my;
+ }
+
+ friend inline Coordinate operator+(const Coordinate &p1, const Coordinate &p2)
+ {
+ return Coordinate(p1.mx + p2.mx,p1.my + p2.my);
+ }
+
+ friend inline Coordinate operator-(const Coordinate &p1, const Coordinate &p2)
+ {
+ return Coordinate(p1.mx - p2.mx,p1.my - p2.my);
+ }
+
+ friend inline Coordinate operator*(const Coordinate &p1, const int i)
+ {
+ return p1.Transform(i);
+ }
+
+ inline bool operator==(const Coordinate &p) const { return (mx==p.mx) && (my==p.my); }
+ inline bool operator!=(const Coordinate &p) const { return (mx!=p.mx) || (my!=p.my); }
+
+ SmartString ToString() const
+ {
+ SmartString s;
+
+ s << '(' << mx << ',' << my << ") ";
+
+ return s;
+ }
+
+// friend std::ostream& operator<<(std::ostream& s, const Coordinate &p);
+
+ inline void StepNext()
+ {
+ StepNext(mx,my);
+ }
+
+ inline void SpiralNext()
+ {
+ SpiralNext(mx,my);
+ }
+
+// inline void Transformation(const unsigned int i)
+// {
+// Transformation(i, mx, my);
+// }
+
+ inline Coordinate Transform(const int i) const
+ {
+ short lX = mx;
+ short lY = my;
+
+ Transformation(i, lX, lY);
+
+ return Coordinate(lX, lY);
+ }
+
+ inline bool IsOnBoard(unsigned int pBoardSize) const
+ {
+ return ((mx>=0) && (my>=0) && (mx<(int)pBoardSize) && (my<(int)pBoardSize));
+ }
+
+ static inline void StepNext(short &x, short &y)
+ {
+ if (x == 0)
+ {
+ // jump
+ x = y + 1;
+ y = 0;
+ }
+ else
+ if (y < x)
+ {
+ // up
+ y = y + 1;
+ }
+ else
+ {
+ // left
+ x = x - 1;
+ }
+
+ }
+
+ static inline void SpiralNext(short &x, short &y)
+ {
+ if ((x == 0) && (y==0))
+ {
+ // start
+ x = -1;
+ y = 0;
+ }
+ else
+ if ((y == 1) && (x <= 0))
+ {
+ // jump
+ x = x - 2;
+ y = 0;
+ }
+ else
+ if ((x < 0) && (y <= 0))
+ {
+ // down, right
+ x = x + 1;
+ y = y - 1;
+ }
+ else
+ if ((x >= 0) && (y < 0))
+ {
+ // up, right
+ x = x + 1;
+ y = y + 1;
+ }
+ else
+ if ((x > 0) && (y >= 0))
+ {
+ // up, left
+ x = x - 1;
+ y = y + 1;
+ }
+ else
+ {
+ // down, left
+ x = x - 1;
+ y = y - 1;
+ }
+
+ }
+
+ static inline void Transformation(const int i, short &x, short &y)
+ {
+ switch(i)
+ {
+ case 0: { return; }
+ case 1: { x = -x; return; }
+ case 2: { y = -y; return; }
+ case 3: { y = -y; x = -x; return; }
+
+ case 4: {int t = y; y = x; x = t; return; }
+ case 5: {int t = y; y = -x; x = t; return; }
+ case 6: {int t = y; y = x; x = -t; return; }
+ case 7: {int t = y; y = -x; x = -t; return; }
+
+ case -1: { y = -y; x = -x; return; }
+
+ default: return;
+ }
+
+ }
+
+};
+
+#endif
Modified: trunk/housebot/src/pattern/DFAMatrix.cpp
===================================================================
--- trunk/housebot/src/pattern/DFAMatrix.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrix.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -37,7 +37,7 @@
{
// merge attributes (l and r)
- int lState = DFANodes.Size() - 1;
+ int lState = DFANodes.size() - 1;
AttributeUnion(DFANodes[lState], pDFALeft.DFANodes[pLeft], pDFARight.DFANodes[pRight]);
@@ -53,8 +53,8 @@
if (lNewValue == 0)
{
// create it
- int lLastState = DFANodes.Size();
- DFANodes.Add(DFANode(DFANodes[lState].Level + 1));
+ int lLastState = DFANodes.size();
+ DFANodes.push_back(DFANode(DFANodes[lState].Level + 1));
pCache.Add(lNextL, lNextR, lLastState);
@@ -79,7 +79,7 @@
{
// merge attributes (l and r)
- int lState = DFANodes.Size() - 1;
+ int lState = DFANodes.size() - 1;
AttributeUnion(DFANodes[lState], pDFALeft.DFANodes[pLeft], pDFAMiddle.DFANodes[pMiddle], pDFARight.DFANodes[pRight]);
@@ -96,8 +96,8 @@
if (lNewValue == 0)
{
// create it
- int lLastState = DFANodes.Size();
- DFANodes.Add(DFANode(DFANodes[lState].Level + 1));
+ int lLastState = DFANodes.size();
+ DFANodes.push_back(DFANode(DFANodes[lState].Level + 1));
pCache.Add(lNextL, lNextM, lNextR, lLastState);
@@ -120,7 +120,7 @@
const SmartString DFAMatrix::ToString() const
{
- unsigned int n = DFANodes.Size();
+ unsigned int n = DFANodes.size();
SmartString lString;
lString.Add("***DFA MATRIX***\n");
Modified: trunk/housebot/src/pattern/DFAMatrix.h
===================================================================
--- trunk/housebot/src/pattern/DFAMatrix.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrix.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -26,7 +26,7 @@
#ifndef DFAMatrixH
#define DFAMatrixH
-#include "phil/Vector.h"
+#include <vector>
#include "Pattern.h"
#include "PatternCollection.h"
#include "DFAPattern.h"
@@ -39,7 +39,7 @@
protected:
SmartString Buckets[4];
- Vector<DFANode> DFANodes;
+ std::vector<DFANode> DFANodes;
void InitBuckets()
{
@@ -81,8 +81,8 @@
{
InitBuckets();
- DFANodes.Clear();
- DFANodes.Add(DFANode(-1));
+ DFANodes.clear();
+ DFANodes.push_back(DFANode(-1));
for (unsigned int lState = 0; lState < pDFA.Length(); lState++)
{
@@ -94,21 +94,21 @@
if (Buckets[z].Contains(c))
lDFANode[z] = lState + 2;
- DFANodes.Add(lDFANode);
+ DFANodes.push_back(lDFANode);
}
DFANode lDFANodeLast = DFANode(pDFA.Length());
lDFANodeLast.Add(std::pair<Pattern*, int>((Pattern *)pPattern, pTransformation));
- DFANodes.Add(lDFANodeLast);
+ DFANodes.push_back(lDFANodeLast);
}
void Merge(const DFAMatrix& pDFAMatrixA, const DFAMatrix& pDFAMatrixB)
{
- DFANodes.Clear();
+ DFANodes.clear();
DFANodes.reserve(std::max(pDFAMatrixA.DFANodes.size(),pDFAMatrixB.DFANodes.size())+128);
- DFANodes.Add(DFANode(-1));
- DFANodes.Add(DFANode(0));
+ DFANodes.push_back(DFANode(-1));
+ DFANodes.push_back(DFANode(0));
DFAMatrixCache lCache(DFANodes.capacity());
@@ -117,11 +117,11 @@
void Merge(const DFAMatrix& pDFAMatrixA, const DFAMatrix& pDFAMatrixB, const DFAMatrix& pDFAMatrixC)
{
- DFANodes.Clear();
+ DFANodes.clear();
DFANodes.reserve(std::max(std::max(pDFAMatrixA.DFANodes.size(),pDFAMatrixB.DFANodes.size()),pDFAMatrixC.DFANodes.size())+128);
- DFANodes.Add(DFANode(-1));
- DFANodes.Add(DFANode(0));
+ DFANodes.push_back(DFANode(-1));
+ DFANodes.push_back(DFANode(0));
DFAMatrixCache3 lCache(DFANodes.capacity());
@@ -145,15 +145,15 @@
Merge(pDFAMatrixA, pDFAMatrixB, pDFAMatrixC);
}
- int GetPatterns(int pState, char pValue, Vector<std::pair<Pattern*, int> >& pPatternList)
+ int GetPatterns(int pState, char pValue, std::vector<std::pair<Pattern*, int> >& pPatternList)
{
- if (DFANodes.Size()== 0)
+ if (DFANodes.size()== 0)
return 0;
const int lNodes = DFANodes[pState].Size();
for(int i = 0; i < lNodes; i++)
- pPatternList.Add(DFANodes[pState].GetNodeAttribute(i));
+ pPatternList.push_back(DFANodes[pState].GetNodeAttribute(i));
return DFANodes[pState][DFAMatrix::GetDestination(pValue)];
}
Modified: trunk/housebot/src/pattern/DFAMatrixBuilder.cpp
===================================================================
--- trunk/housebot/src/pattern/DFAMatrixBuilder.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrixBuilder.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -57,7 +57,7 @@
}
*/
const DFAPattern lDFAPattern(pPattern, lSmallestTranslation);
- mDFAMatrixes.Push(DEBUG_NEW DFAMatrix(&pPattern, lSmallestTranslation, lDFAPattern));
+ mDFAMatrixes.push_back(new DFAMatrix(&pPattern, lSmallestTranslation, lDFAPattern));
}
void DFAMatrixBuilder::Load(const PatternCollection& pPatternCollection)
@@ -73,10 +73,10 @@
DFAMatrix* DFAMatrixBuilder::GetMatrix()
{
- if (mDFAMatrixes.Size() == 0)
- return DEBUG_NEW DFAMatrix();
+ if (mDFAMatrixes.size() == 0)
+ return new DFAMatrix();
- if (mDFAMatrixes.Size() > 1)
+ if (mDFAMatrixes.size() > 1)
Build2();
return mDFAMatrixes[0];
@@ -84,90 +84,90 @@
bool DFAMatrixBuilder::BuildPass()
{
- unsigned int lNodes = mDFAMatrixes.Size();
+ unsigned int lNodes = mDFAMatrixes.size();
if (lNodes <= 1)
return true;
- Vector<DFAMatrix *> lDFAMatrix;
+ _Vector<DFAMatrix *> lDFAMatrix;
- while (mDFAMatrixes.Size() >= 2)
+ while (mDFAMatrixes.size() >= 2)
{
DFAMatrix* lDFAMatrix1 = mDFAMatrixes.Pop();
DFAMatrix* lDFAMatrix2 = mDFAMatrixes.Pop();
- DFAMatrix* lDFAMatrixCombined = DEBUG_NEW DFAMatrix(*lDFAMatrix1, *lDFAMatrix2);
+ DFAMatrix* lDFAMatrixCombined = new DFAMatrix(*lDFAMatrix1, *lDFAMatrix2);
- lDFAMatrix.Push(lDFAMatrixCombined);
+ lDFAMatrix.push_back(lDFAMatrixCombined);
delete lDFAMatrix1;
delete lDFAMatrix2;
}
- if (mDFAMatrixes.Size() == 1)
- lDFAMatrix.Push(mDFAMatrixes.Pop());
+ if (mDFAMatrixes.size() == 1)
+ lDFAMatrix.push_back(mDFAMatrixes.Pop());
mDFAMatrixes = lDFAMatrix;
- return (mDFAMatrixes.Size() == 1);
+ return (mDFAMatrixes.size() == 1);
}
bool DFAMatrixBuilder::BuildPass3()
{
- unsigned int lNodes = mDFAMatrixes.Size();
+ unsigned int lNodes = mDFAMatrixes.size();
// std::cout << "Nodes = " << lNodes << std::endl << std::flush;
if (lNodes <= 1)
return true;
- Vector<DFAMatrix *> lDFAMatrix;
+ _Vector<DFAMatrix *> lDFAMatrix;
- while (mDFAMatrixes.Size() >= 3)
+ while (mDFAMatrixes.size() >= 3)
{
DFAMatrix* lDFAMatrix1 = mDFAMatrixes.Pop();
DFAMatrix* lDFAMatrix2 = mDFAMatrixes.Pop();
DFAMatrix* lDFAMatrix3 = mDFAMatrixes.Pop();
- DFAMatrix* lDFAMatrixCombined = DEBUG_NEW DFAMatrix(*lDFAMatrix1, *lDFAMatrix2, *lDFAMatrix3);
+ DFAMatrix* lDFAMatrixCombined = new DFAMatrix(*lDFAMatrix1, *lDFAMatrix2, *lDFAMatrix3);
- lDFAMatrix.Push(lDFAMatrixCombined);
+ lDFAMatrix.push_back(lDFAMatrixCombined);
delete lDFAMatrix1;
delete lDFAMatrix2;
delete lDFAMatrix3;
}
- while (mDFAMatrixes.Size() >= 2)
+ while (mDFAMatrixes.size() >= 2)
{
DFAMatrix* lDFAMatrix1 = mDFAMatrixes.Pop();
DFAMatrix* lDFAMatrix2 = mDFAMatrixes.Pop();
- DFAMatrix* lDFAMatrixCombined = DEBUG_NEW DFAMatrix(*lDFAMatrix1, *lDFAMatrix2);
+ DFAMatrix* lDFAMatrixCombined = new DFAMatrix(*lDFAMatrix1, *lDFAMatrix2);
- lDFAMatrix.Push(lDFAMatrixCombined);
+ lDFAMatrix.push_back(lDFAMatrixCombined);
delete lDFAMatrix1;
delete lDFAMatrix2;
}
- if (mDFAMatrixes.Size() == 1)
- lDFAMatrix.Push(mDFAMatrixes.Pop());
+ if (mDFAMatrixes.size() == 1)
+ lDFAMatrix.push_back(mDFAMatrixes.Pop());
mDFAMatrixes = lDFAMatrix;
- return (mDFAMatrixes.Size() == 1);
+ return (mDFAMatrixes.size() == 1);
}
-DFAMatrixBuilder::DFAMatrixBuilder(Vector<DFAMatrix*>& pDFAMatrixes, unsigned int pCount)
+DFAMatrixBuilder::DFAMatrixBuilder(_Vector<DFAMatrix*>& pDFAMatrixes, unsigned int pCount)
{
unsigned int lCount = pCount;
- if (lCount > pDFAMatrixes.Size())
- lCount = pDFAMatrixes.Size();
+ if (lCount > pDFAMatrixes.size())
+ lCount = pDFAMatrixes.size();
for (; lCount > 0; lCount--)
- mDFAMatrixes.Push(pDFAMatrixes.Pop());
+ mDFAMatrixes.push_back(pDFAMatrixes.Pop());
}
void DFAMatrixBuilder::ThreadStart(DFAMatrixBuilder* pDFAMatrixBuilder)
@@ -177,21 +177,21 @@
void DFAMatrixBuilder::Build2()
{
- if (mDFAMatrixes.Size() > 16)
+ if (mDFAMatrixes.size() > 16)
{
- DFAMatrixBuilder lDFAMatrixBuilder1(mDFAMatrixes, mDFAMatrixes.Size() / 3);
+ DFAMatrixBuilder lDFAMatrixBuilder1(mDFAMatrixes, mDFAMatrixes.size() / 3);
boost::thread thrd1(boost::bind(&DFAMatrixBuilder::ThreadStart,&lDFAMatrixBuilder1));
- DFAMatrixBuilder lDFAMatrixBuilder2(mDFAMatrixes, mDFAMatrixes.Size() / 2);
+ DFAMatrixBuilder lDFAMatrixBuilder2(mDFAMatrixes, mDFAMatrixes.size() / 2);
boost::thread thrd2(boost::bind(&DFAMatrixBuilder::ThreadStart,&lDFAMatrixBuilder2));
Build();
thrd1.join();
- mDFAMatrixes.Push(lDFAMatrixBuilder1.GetMatrix());
+ mDFAMatrixes.push_back(lDFAMatrixBuilder1.GetMatrix());
thrd2.join();
- mDFAMatrixes.Push(lDFAMatrixBuilder2.GetMatrix());
+ mDFAMatrixes.push_back(lDFAMatrixBuilder2.GetMatrix());
}
Build();
}
Modified: trunk/housebot/src/pattern/DFAMatrixBuilder.h
===================================================================
--- trunk/housebot/src/pattern/DFAMatrixBuilder.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrixBuilder.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -27,16 +27,28 @@
#define DFAMatrixBuilderH
#include "DFAMatrix.h"
+#include <vector>
+template <class T> class _Vector : public std::vector<T>
+{
+public:
+ inline T Pop()
+ {
+ T item = (*this)[std::vector<T>::size()-1];
+ std::vector<T>::pop_back();
+ return item;
+ }
+};
+
class DFAMatrixBuilder
{
protected:
- Vector<DFAMatrix*> mDFAMatrixes;
+ _Vector<DFAMatrix*> mDFAMatrixes;
bool BuildPass();
bool BuildPass3();
- DFAMatrixBuilder(Vector<DFAMatrix*>& pDFAMatrixes, unsigned int pCount);
+ DFAMatrixBuilder(_Vector<DFAMatrix*>& pDFAMatrixes, unsigned int pCount);
static void ThreadStart(DFAMatrixBuilder* pDFAMatrixBuilder);
public:
Modified: trunk/housebot/src/pattern/DFAMatrixCache.h
===================================================================
--- trunk/housebot/src/pattern/DFAMatrixCache.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrixCache.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -38,7 +38,7 @@
int value;
};
- Vector<CacheEntry>* mCacheEntries;
+ std::vector<CacheEntry>* mCacheEntries;
unsigned int mCacheSize;
@@ -53,16 +53,16 @@
if (mCacheSize > 1024 * 256)
mCacheSize = 1024 * 256;
- mCacheEntries = new Vector<CacheEntry>[mCacheSize];
+ mCacheEntries = new std::vector<CacheEntry>[mCacheSize];
}
inline int Search(int l, int r)
{
const unsigned int lHash = Hash(l,r);
- const Vector<CacheEntry>& lList = *(mCacheEntries+lHash);
+ const std::vector<CacheEntry>& lList = *(mCacheEntries+lHash);
- const unsigned int n = lList.Size();
+ const unsigned int n = lList.size();
for (unsigned int i = 0; i < n; i++)
if ( (lList[i].l == l)
@@ -88,7 +88,7 @@
const unsigned int lHash = Hash(l,r);
- (*(mCacheEntries+lHash)).Add(lCacheEntry);
+ (*(mCacheEntries+lHash)).push_back(lCacheEntry);
}
};
Modified: trunk/housebot/src/pattern/DFAMatrixCache3.h
===================================================================
--- trunk/housebot/src/pattern/DFAMatrixCache3.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAMatrixCache3.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -38,7 +38,7 @@
int value;
};
- Vector<CacheEntry>* mCacheEntries;
+ std::vector<CacheEntry>* mCacheEntries;
unsigned int mCacheSize;
@@ -53,16 +53,16 @@
if (mCacheSize > 1024 * 128)
mCacheSize = 1024 * 128;
- mCacheEntries = new Vector<CacheEntry>[mCacheSize];
+ mCacheEntries = new std::vector<CacheEntry>[mCacheSize];
}
inline int Search(int l, int m, int r)
{
const unsigned int lHash = Hash(l,m,r);
- const Vector<CacheEntry>& lList = *(mCacheEntries+lHash);
+ const std::vector<CacheEntry>& lList = *(mCacheEntries+lHash);
- const unsigned int n = lList.Size();
+ const unsigned int n = lList.size();
for (unsigned int i = 0; i < n; i++)
if ( (lList[i].l == l)
@@ -90,7 +90,7 @@
const unsigned int lHash = Hash(l,m,r);
- (*(mCacheEntries+lHash)).Add(lCacheEntry);
+ (*(mCacheEntries+lHash)).push_back(lCacheEntry);
}
};
Modified: trunk/housebot/src/pattern/DFANode.h
===================================================================
--- trunk/housebot/src/pattern/DFANode.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFANode.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -28,13 +28,13 @@
#include <utility>
#include "Pattern.h"
-#include "phil/Vector.h"
+#include <vector>
class DFANode
{
private:
int Dest[4];
- Vector<std::pair<Pattern*,int> >* DFAAttributeNodes;
+ std::vector<std::pair<Pattern*,int> >* DFAAttributeNodes;
public:
int Level;
@@ -65,10 +65,10 @@
return;
}
- DFAAttributeNodes = DEBUG_NEW Vector<std::pair<Pattern*,int> >;
+ DFAAttributeNodes = new std::vector<std::pair<Pattern*,int> >;
for(unsigned int i = 0; i < pDFANode.DFAAttributeNodes->size(); i++)
- DFAAttributeNodes->Add(pDFANode.GetNodeAttribute(i));
+ DFAAttributeNodes->push_back(pDFANode.GetNodeAttribute(i));
}
inline const int operator[](const unsigned int index) const
@@ -91,15 +91,15 @@
if (DFAAttributeNodes == NULL)
return 0;
- return DFAAttributeNodes->Size();
+ return DFAAttributeNodes->size();
}
inline void Add(std::pair<Pattern*,int> pPattern)
{
if (DFAAttributeNodes==NULL)
- DFAAttributeNodes = DEBUG_NEW Vector<std::pair<Pattern*,int> >;
+ DFAAttributeNodes = new std::vector<std::pair<Pattern*,int> >;
- DFAAttributeNodes->Add(pPattern);
+ DFAAttributeNodes->push_back(pPattern);
}
inline void Add(const DFANode& pDFANode)
@@ -110,10 +110,10 @@
return;
if (DFAAttributeNodes == NULL)
- DFAAttributeNodes = DEBUG_NEW Vector<std::pair<Pattern*,int> >;
+ DFAAttributeNodes = new std::vector<std::pair<Pattern*,int> >;
for (int i = 0; i < lNodeCount; i++)
- DFAAttributeNodes->Add(pDFANode.GetNodeAttribute(i));
+ DFAAttributeNodes->push_back(pDFANode.GetNodeAttribute(i));
}
};
Modified: trunk/housebot/src/pattern/DFAPattern.cpp
===================================================================
--- trunk/housebot/src/pattern/DFAPattern.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/DFAPattern.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -91,16 +91,16 @@
/*
-void DFAPattern::SetPattern(const GoBoard& pBoard, const Point& pPoint, const int pLen)
+void DFAPattern::SetPattern(const GoBoard& pBoard, const position& pPosition, const int pLen)
{
Coordinate s(0,0);
- Coordinate p(pPoint.x(),pPoint.y());
+ Coordinate p(pPosition.x(),pPosition.y());
for (int i = 0; i < pLen; i++)
{
const Coordinate c = s + p;
- mDFA.Add(pBoard.GetIntersection(Point(c)).ToChar());
+ mDFA.Add(pBoard.GetIntersection(position(c)).ToChar());
s.SpiralNext();
}
Modified: trunk/housebot/src/pattern/Makefile.am
===================================================================
--- trunk/housebot/src/pattern/Makefile.am 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/Makefile.am 2007-02-08 09:25:20 UTC (rev 468)
@@ -3,6 +3,6 @@
SUBDIRS = test
noinst_LIBRARIES = libpattern.a
-libpattern_a_SOURCES = DFAMatrix.cpp DFAPattern.cpp Pattern.cpp PatternInterpreter.cpp PatternCollection.cpp PatternScanner.cpp PatternSyntax.cpp PatternHit.cpp PatternDetector.cpp PatternTest.cpp DFAMatrixBuilder.cpp
+libpattern_a_SOURCES = DFAMatrix.cpp DFAPattern.cpp Pattern.cpp PatternInterpreter.cpp PatternCollection.cpp PatternScanner.cpp PatternSyntax.cpp PatternHit.cpp PatternDetector.cpp PatternTest.cpp DFAMatrixBuilder.cpp Coordinate.cpp
AM_CPPFLAGS = -I .. $(HB_CFLAGS)
Modified: trunk/housebot/src/pattern/Pattern.cpp
===================================================================
--- trunk/housebot/src/pattern/Pattern.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/Pattern.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -238,9 +238,9 @@
}
-int Pattern::Execute(const GoBoardInterface& pGoBoard, const color_t& pTurn, const Coordinate& pOriginPoint, int pTransform) const
+int Pattern::Execute(const GoBoardInterface& pGoBoard, const color_t& pTurn, const Coordinate& pOrigin, int pTransform) const
{
PatternInterpreter lPatternInterpreter(*this);
- return lPatternInterpreter.Execute(pGoBoard, pTurn, pOriginPoint, pTransform);
+ return lPatternInterpreter.Execute(pGoBoard, pTurn, pOrigin, pTransform);
}
Modified: trunk/housebot/src/pattern/Pattern.h
===================================================================
--- trunk/housebot/src/pattern/Pattern.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/Pattern.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -26,11 +26,11 @@
#ifndef PatternH
#define PatternH
-#include "phil/Point.h"
-#include "phil/Coordinate.h"
+
#include "phil/SmartString.h"
#include "phil/ErrorManagement.h"
#include "phil/GoBoardInterface.h"
+#include "Coordinate.h"
#include "PatternCode.h"
#include "DFAPattern.h"
@@ -279,7 +279,7 @@
static bool SelfTest(bool quiet = false);
- int Execute(const GoBoardInterface& pGoBoard, const color_t& pTurn, const Coordinate& pOriginPoint, int pTransform) const;
+ int Execute(const GoBoardInterface& pGoBoard, const color_t& pTurn, const Coordinate& pOrigin, int pTransform) const;
};
#endif
Modified: trunk/housebot/src/pattern/PatternCode.h
===================================================================
--- trunk/housebot/src/pattern/PatternCode.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternCode.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -27,14 +27,14 @@
#define PatternCodeH
#include "phil/Platform.h"
-#include "phil/Vector.h"
+#include <vector>
#include "PatternOperator.h"
#include "phil/ErrorManagement.h"
class PatternCode : public ErrorManagement
{
protected:
- Vector<PatternOperator> mPatternCode;
+ std::vector<PatternOperator> mPatternCode;
public:
PatternCode()
@@ -42,17 +42,17 @@
inline void Clear()
{
- mPatternCode.Clear();
+ mPatternCode.clear();
}
inline bool IsEmpty() const
{
- return (mPatternCode.Size() == 0);
+ return (mPatternCode.size() == 0);
}
inline const PatternOperator operator[](const unsigned int index) const
{
- if (index < mPatternCode.Size())
+ if (index < mPatternCode.size())
return mPatternCode[index];
else
return TOKEN_UNKNOWN;
@@ -60,14 +60,14 @@
inline void Add(const PatternOperator& pPatternOperator)
{
- mPatternCode.Add(pPatternOperator);
+ mPatternCode.push_back(pPatternOperator);
}
const SmartString ToString(int pStart = -1, int pEnd = -1) const
{
SmartString lString;
- for (int i = 0; i < (int) mPatternCode.Size(); i++)
+ for (int i = 0; i < (int) mPatternCode.size(); i++)
{
if (i == pStart)
lString.Add(" [ ");
Modified: trunk/housebot/src/pattern/PatternCollection.h
===================================================================
--- trunk/housebot/src/pattern/PatternCollection.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternCollection.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -28,14 +28,14 @@
#define PatternCollectionH
#include "Pattern.h"
-#include "phil/Vector.h"
+#include <vector>
#include "phil/ErrorManagement.h"
#include "Pattern.h"
class PatternCollection : public ErrorManagement
{
protected:
- Vector<Pattern> mPatterns;
+ std::vector<Pattern> mPatterns;
public:
inline PatternCollection()
@@ -48,23 +48,23 @@
inline void Clear()
{
- mPatterns.Clear();
+ mPatterns.clear();
}
inline void AddPattern(const Pattern& p)
{
- mPatterns.Add(p);
+ mPatterns.push_back(p);
}
inline const Pattern& operator[](const unsigned int i) const
{
- _ASSERT(i<mPatterns.Size());
+ _ASSERT(i<mPatterns.size());
return mPatterns[i];
}
inline unsigned int GetNumberOfPatterns() const
{
- return mPatterns.Size();
+ return mPatterns.size();
}
bool LoadPatterns(const SmartString& pFileName);
Modified: trunk/housebot/src/pattern/PatternDetector.cpp
===================================================================
--- trunk/housebot/src/pattern/PatternDetector.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternDetector.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -30,17 +30,17 @@
{
unsigned int lBoardSize = pGoBoard.GetBoardSize();
- mPatternHits.Clear();
- Vector<std::pair<Pattern*,int> > lPatternList;
+ mPatternHits.clear();
+ std::vector<std::pair<Pattern*,int> > lPatternList;
for (int t=0;t<8;t++)
for (GoBoardIterator iter(pGoBoard);!iter.IsDone();iter++)
if (pGoBoard.GetColor(*iter) == empty)
{
- const Point p = *iter;
+ const position p = *iter;
int lState = 1;
- lPatternList.Clear();
+ lPatternList.clear();
for (SpiralIterator iter2(p,t);!iter2.IsDone();iter2++)
{
@@ -50,7 +50,7 @@
if (s.IsOnBoard(lBoardSize))
{
- color_t lColor = pGoBoard.GetColor(Point(s));
+ color_t lColor = pGoBoard.GetColor(position(s));
// patterns are stored in white moves next
// so flip colors when is black's turn
@@ -66,16 +66,16 @@
break;
}
- for (unsigned int i=0;i<lPatternList.Size();i++)
+ for (unsigned int i=0;i<lPatternList.size();i++)
{
// std::cout << lPatternList[i].mPattern.mPatternName << " " << lPatternList[i].mTransformation << " " << Coordinate(p.x(),p.y()).ToString() << " or " <<p.ToString() << std::endl;
- if (lPatternList[i].first->Execute(pGoBoard, pPlayerToMove, Coordinate(p.x(),p.y()), lPatternList[i].second))
- mPatternHits.Add(PatternHit(lPatternList[i].first, t /*lPatternList[i].second */, p));
+ if (lPatternList[i].first->Execute(pGoBoard, pPlayerToMove, Coordinate(p.row,p.col), lPatternList[i].second))
+ mPatternHits.push_back(PatternHit(lPatternList[i].first, t /*lPatternList[i].second */, p));
}
- lPatternList.Clear();
+ lPatternList.clear();
}
- return mPatternHits.Size();
+ return mPatternHits.size();
}
Modified: trunk/housebot/src/pattern/PatternDetector.h
===================================================================
--- trunk/housebot/src/pattern/PatternDetector.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternDetector.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -50,7 +50,7 @@
}
public:
- Vector<PatternHit> mPatternHits;
+ std::vector<PatternHit> mPatternHits;
public:
PatternDetector(const PatternCollection& pPatterns)
Modified: trunk/housebot/src/pattern/PatternHit.h
===================================================================
--- trunk/housebot/src/pattern/PatternHit.h 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternHit.h 2007-02-08 09:25:20 UTC (rev 468)
@@ -26,7 +26,7 @@
#ifndef PatternHitH
#define PatternHitH
-#include "phil/Point.h"
+
#include "Pattern.h"
class PatternHit
@@ -34,16 +34,16 @@
public:
const Pattern* mPattern;
const int mTransformation;
- const Point mHitLocation;
+ const position mHitLocation;
- PatternHit(const Pattern& pPattern, int pTransformation, const Point& pHitLocation)
+ PatternHit(const Pattern& pPattern, int pTransformation, const position& pHitLocation)
: mPattern(&pPattern)
, mTransformation(pTransformation)
, mHitLocation(pHitLocation)
{
}
- PatternHit(const Pattern* pPattern, int pTransformation, const Point& pHitLocation)
+ PatternHit(const Pattern* pPattern, int pTransformation, const position& pHitLocation)
: mPattern(pPattern)
, mTransformation(pTransformation)
, mHitLocation(pHitLocation)
Modified: trunk/housebot/src/pattern/PatternInterpreter.cpp
===================================================================
--- trunk/housebot/src/pattern/PatternInterpreter.cpp 2007-02-07 01:56:38 UTC (rev 467)
+++ trunk/housebot/src/pattern/PatternInterpreter.cpp 2007-02-08 09:25:20 UTC (rev 468)
@@ -71,7 +71,7 @@
// std::cout << " P.Origin: " << lPatternOrigin.ToString() << " P.Variable: " << lPatternVariable.ToString() << " B.Origin: " << mOrigin.ToString() << " B.Variable: " << lNew.ToString() << std::endl;
- lParameters[lParameterCnt++] = *(Point(lNew)); // hack
+ lParameters[lParameterCnt++] = position(lNew).compress(); // hack
}
else
{
@@ -91,66 +91,66 @@
case FUNC_LIBERTY_COUNT :
{
if (pParamaterCnt == 1)
- return mGoBoard->GetStringLibertyCount( (Point) pParameters[0] );
+ return mGoBoard->GetStringLibertyCount( (position) pParameters[0] );
break;
}
case FUNC_SAMESTRING :
{
if (pParamaterCnt == 2)
- return mGoBoard->IsSameString( (Point) pParameters[0], (Point) pParameters[1] );
+ return mGoBoard->IsSameString( (position) pParameters[0], (position) pParameters[1] );
}
case FUNC_LIBERTY_COUNT_AFTER :
{
if (pParamaterCnt == 1)
- return mGoBoard->GetStringLibertyCountAfterPlay(mTurn, Point(mOrigin), (Point) pParameters[0] );
+ return mGoBoard->GetStringLibertyCountAfterPlay(mTurn, position(mOrigin), (position) pParameters[0] );
break;
}
case FUNC_STATUS_DEAD :
{
if (pParamaterCnt == 1)
- return (mGoBoard->GetLifeStatus((Point) pParameters[0] ) == DEAD);
+ return (mGoBoard->GetLifeStatus((position) pParameters[0] ) == DEAD);
break;
}
case FUNC_STATUS_ALIVE :
{
if (pParamaterCnt == 1)
- return (mGoBoard->GetLifeStatus((Point) pParameters[0] ) == ALIVE);
+ return (mGoBoard->GetLifeStatus((position) pParameters[0] ) == ALIVE);
break;
}
case FUNC_STATUS_UNKNOWN :
{
if (pParamaterCnt == 1)
- return (mGoBoard->GetLifeStatus((Point) pParameters[0] ) == UNKNOWN);
+ return (mGoBoard->GetLifeStatus((position) pParameters[0] ) == UNKNOWN);
break;
}
case FUNC_STATUS_KO :
{
if (pParamaterCnt == 1)
- return (mGoBoard->IsKO((Point) pParameters[0]));
+ ...
[truncated message content] |