00001 //---------------------------------------------------------------------------- 00002 /** @file DfsData.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "Misc.hpp" 00007 #include "DfsData.hpp" 00008 #include "BoardUtils.hpp" 00009 00010 using namespace benzene; 00011 00012 //---------------------------------------------------------------------------- 00013 00014 int DfsData::PackedSize() const 00015 { 00016 return (sizeof(m_win) + 00017 sizeof(m_flags) + 00018 sizeof(m_numStates) + 00019 sizeof(m_numMoves) + 00020 sizeof(m_bestMove)); 00021 } 00022 00023 /** @bug NOT THREADSAFE! */ 00024 byte* DfsData::Pack() const 00025 { 00026 // replace this to make it threadsafe 00027 static byte data[256]; 00028 00029 int index = 0; 00030 MiscUtil::WordToBytes(m_win, &data[index]); 00031 index += 4; 00032 00033 MiscUtil::WordToBytes(m_flags, &data[index]); 00034 index += 4; 00035 00036 MiscUtil::WordToBytes(m_numStates, &data[index]); 00037 index += 4; 00038 00039 MiscUtil::WordToBytes(m_numMoves, &data[index]); 00040 index += 4; 00041 00042 MiscUtil::WordToBytes(m_bestMove, &data[index]); 00043 index += 4; 00044 00045 return data; 00046 } 00047 00048 void DfsData::Unpack(const byte* data) 00049 { 00050 int index = 0; 00051 00052 m_win = MiscUtil::BytesToWord(&data[index]); 00053 index += 4; 00054 00055 m_flags = MiscUtil::BytesToWord(&data[index]); 00056 index += 4; 00057 00058 m_numStates = MiscUtil::BytesToWord(&data[index]); 00059 index += 4; 00060 00061 m_numMoves = MiscUtil::BytesToWord(&data[index]); 00062 index += 4; 00063 00064 m_bestMove = static_cast<HexPoint>(MiscUtil::BytesToWord(&data[index])); 00065 } 00066 00067 void DfsData::Rotate(const ConstBoard& brd) 00068 { 00069 if (m_bestMove != INVALID_POINT) 00070 m_bestMove = BoardUtils::Rotate(brd, m_bestMove); 00071 } 00072 00073 void DfsData::Mirror(const ConstBoard& brd) 00074 { 00075 if (m_bestMove != INVALID_POINT) 00076 m_bestMove = BoardUtils::Mirror(brd, m_bestMove); 00077 } 00078 //----------------------------------------------------------------------------