Пример #1
0
bool Position::IsGameOver(std::string& message)
{
  bool hasMoves = false;
  MoveList mvlist;
  mvlist.GenAllMoves(*this);
  for (int i = 0; i < mvlist.Size(); ++i)
  {
    if (MakeMove(mvlist[i].m_mv))
    {
      hasMoves = true;
      UnmakeMove();
      break;
    }
  }
  
  if (hasMoves == false)
  {
    if (InCheck())
      message = (m_side == WHITE)? "0-1 {Black mates}" : "1-0 {White mates}";
    else
      message = "1/2-1/2 {Draw: stalemate}";
    return true;
  }

  if (EstimateDraw(*this) == EVAL_THEORETICAL_DRAW)
  {
    message = "1/2-1/2 {Draw: material}";
    return true;
  }

  if (GetRepetitions() >= 3)
  {
    message = "1/2-1/2 {Draw: 3rd repetition}";
    return true;
  }

  return false;
}
Пример #2
0
// Returns value of given attribute.
int CGXDLMSAutoConnect::GetValue(CGXDLMSSettings& settings, CGXDLMSValueEventArg& e)
{
    if (e.GetIndex() == 1)
    {
        int ret;
        CGXDLMSVariant tmp;
        if ((ret = GetLogicalName(this, tmp)) != 0)
        {
            return ret;
        }
        e.SetValue(tmp);
        return DLMS_ERROR_CODE_OK;
    }
    if (e.GetIndex() == 2)
    {
        e.SetValue((unsigned char) GetMode());
        return DLMS_ERROR_CODE_OK;
    }
    if (e.GetIndex() == 3)
    {
        e.SetValue(GetRepetitions());
        return DLMS_ERROR_CODE_OK;
    }
    if (e.GetIndex() == 4)
    {
        e.SetValue(GetRepetitionDelay());
        return DLMS_ERROR_CODE_OK;
    }
    if (e.GetIndex() == 5)
    {
        int cnt = m_CallingWindow.size();
        CGXByteBuffer data;
        data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
        int ret;
        //Add count
        GXHelpers::SetObjectCount(cnt, data);
        if (cnt != 0)
        {
            CGXDLMSVariant s, e;
            for (std::vector<std::pair< CGXDateTime, CGXDateTime> >::iterator it = m_CallingWindow.begin(); it != m_CallingWindow.end(); ++it)
            {
                data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
                data.SetUInt8(2); //Count
                s = it->first;
                e = it->second;
                if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, s)) != 0 || //start_time
                        (ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, e)) != 0) //end_time
                {
                    return ret;
                }
            }
        }
        e.SetValue(data);
        return DLMS_ERROR_CODE_OK;
    }
    if (e.GetIndex() == 6)
    {
        CGXByteBuffer data;
        data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
        int ret;
        int cnt = m_Destinations.size();
        //Add count
        GXHelpers::SetObjectCount(cnt, data);
        for (std::vector< std::string >::iterator it = m_Destinations.begin(); it != m_Destinations.end(); ++it)
        {
            CGXDLMSVariant value;
            e.GetValue().Add(&(*it)[0], it->size());
            if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, value)) != 0) //destination
            {
                return ret;
            }
        }
        e.SetValue(data);
        return DLMS_ERROR_CODE_OK;
    }
    return DLMS_ERROR_CODE_INVALID_PARAMETER;
}