Exemplo n.º 1
0
_inline bool IsCenterOfBlueCircle(int x, int y, int NoSnapShot, bool bUnchangedAreaInBlack)
{
	SnapShotData &SS = GtSnapShotData[NoSnapShot];
#ifdef ASSERT
	ASSERT(SS.IsInSnapShotRelative(x-22, y-13)); 
	ASSERT(SS.IsInSnapShotRelative(x+23, y+13));
#endif
	if (!IsBlue(SS.SSGetPixelRelative(x-19, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x+20, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x-18, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x+19, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x-17, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x+18, y)) || 
		!IsBlue(SS.SSGetPixelRelative(x, y-9)) || 
		!IsBlue(SS.SSGetPixelRelative(x, y+9)) ||
		!IsBlue(SS.SSGetPixelRelative(x, y+8)) ) return false;

	if (!bUnchangedAreaInBlack) return true; // Pas d'autres tests dans ce cas (risque d'erreur nettement accru)

	if ( !IsBlack(SS.SSGetPixelRelative(x, y-13)) ||
		 !IsBlack(SS.SSGetPixelRelative(x, y+13)) ||
		 !IsBlack(SS.SSGetPixelRelative(x-22, y)) ||
		 !IsBlack(SS.SSGetPixelRelative(x+23, y)) )
		 return false;

	for (int Xr=x-13; Xr<=x+14; Xr++)
		if (!IsBlack(SS.SSGetPixelRelative(Xr, y))) return false;
	for (int Yr=y-5; Yr<=y+4; Yr++)
		if (!IsBlack(SS.SSGetPixelRelative(x, Yr))) return false;
	return true;	
}
std::vector<int> Chessboard::GetFeature(int color) {
    std::vector<int> feature;
    for (int i = 0; i < BOARDSIZE; ++i)
        for (int j = 0; j < BOARDSIZE; ++j) {
            feature.push_back(color == BLACK ? IsBlack(i, j) : IsWhite(i, j));
            feature.push_back(color == WHITE ? IsWhite(i, j) : IsBlack(i, j));
            feature.push_back(IsEmpty(i, j));
            feature.push_back(CountOpenThree(i, j, color));
            feature.push_back(CountSimpleThree(i, j, color));
            feature.push_back(CountOpenFour(i, j, color));
            feature.push_back(CountSimpleFour(i, j, color));
            feature.push_back(CountOpenTwo(i, j, color));
            feature.push_back(IsFive(i, j, color));
            feature.push_back(CountOpenThree(i, j, color ^ 1));
            feature.push_back(CountSimpleThree(i, j, color ^ 1));
            feature.push_back(CountOpenFour(i, j, color ^ 1));
            feature.push_back(CountSimpleFour(i, j, color ^ 1));
            feature.push_back(CountOpenTwo(i, j, color ^ 1));
            feature.push_back(IsFive(i, j, color ^ 1));
        }
    return feature;
}
Exemplo n.º 3
0
void PyrGC::ScanFrames()
{
	VMGlobals *g = mVMGlobals;
	PyrFrame* frame = g->frame;
	while (frame) {
#if 1
		// this is more incremental
		if (IsWhite(frame)) {
			ToGrey2(frame);
		}
#else
		// this is more efficient
		if (!IsBlack(frame)) {
			ToBlack(frame);
			int32 size = ScanSize(frame);
			PyrSlot *slots = ((PyrObject*)frame)->slots;
			ScanSlots(slots, size);
		}
#endif
		frame = slotRawFrame(&frame->caller);
	}
}
Exemplo n.º 4
0
void TwitterTask::Entry(TaskServer &server, const std::atomic<bool> &cancel)
{
	// 初回実行時のみ
	// 自分の最後のツイート以降でフィルタする
	if (m_since_id == 0) {
		m_since_id = GetInitialSinceId();
		logger.Log(LogLevel::Info, "Initial since_id: %" PRIu64, m_since_id);
	}

	// ホームタイムラインを取得
	auto twitter = system::Get().twitter;
	auto json = twitter.Statuses_HomeTimeline({
		{"since_id", std::to_string(m_since_id)},
		{"count", "200"}});

	auto log_tweet = [](const json11::Json &status, std::time_t timestamp) {
		logger.Log(LogLevel::Info, "id=%s time=%s local=%s screen=%s name=%s",
			status["id_str"].string_value().c_str(),
			status["created_at"].string_value().c_str(),
			util::DateTimeStr(timestamp).c_str(),
			status["user"]["screen_name"].string_value().c_str(),
			status["user"]["name"].string_value().c_str());
		logger.Log(LogLevel::Info, "%s", status["text"].string_value().c_str());
	};

	for (const auto &status : json.array_items()) {
		// ID
		uint64_t id = util::to_uint64(status["id_str"].string_value());
		// ローカルタイムに変換
		std::time_t timestamp = util::StrToTimeTwitter(
			status["created_at"].string_value());
		struct tm local;
		::localtime_r(&timestamp, &local);

		// 自分のツイートには反応しない
		if (util::to_uint64(status["id_str"].string_value()) == twitter.MyId()) {
			continue;
		}
		// リツイートには反応しない
		if (!status["retweeted_status"].is_null()) {
			continue;
		}
		if (IsWhite(status)) {
			logger.Log(LogLevel::Info, "Find White");
			log_tweet(status, timestamp);

			std::string msg = u8"@";
			msg += status["user"]["screen_name"].string_value();
			msg += ' ';
			msg += u8"ホワイト!";
			twitter.Tweet(msg, status["id_str"].string_value());

			m_since_id = std::max(id, m_since_id);
		}
		if (IsBlack(status)) {
			logger.Log(LogLevel::Info, "Find Black");
			log_tweet(status, timestamp);

			std::string msg = u8"@";
			msg += status["user"]["screen_name"].string_value();
			msg += ' ';
			msg += u8"ブラック";
			twitter.Tweet(msg, status["id_str"].string_value());

			m_since_id = std::max(id, m_since_id);
		}
	}
}
 inline bool IsRelevantForSaving() const
 {
   return IsValid() && !IsBlack();
 }
Exemplo n.º 6
0
inline bool StoneBoard::IsOccupied(HexPoint cell) const
{
    BenzeneAssert(Const().IsLocation(cell));
    return (IsBlack(cell) || IsWhite(cell));
}
Exemplo n.º 7
0
void CPianoCtrl::Update(CSize Size)
{
	// compute number of white keys
	int	nWhites = 0;
	int	iKey;
	int	nKeys = m_Key.GetSize();	// get existing key count
	for (iKey = 0; iKey < nKeys; iKey++)	// for each key array element
		m_Key[iKey].m_Rgn.DeleteObject();	// delete key's polygonal area
	int	StartDelta = m_StartNote - m_PrevStartNote;
	if (StartDelta) {	// if start note changed
		if (StartDelta > 0)	// if start note increased
			m_Key.RemoveAt(0, min(StartDelta, nKeys));
		else {	// start note decreased
			CKey	key;
			m_Key.InsertAt(0, key, min(-StartDelta, nKeys));
		}
		m_PrevStartNote = m_StartNote;
	}
	nKeys = GetKeyCount();	// get new key count
	m_Key.SetSize(nKeys);	// resize key array, possibly reallocating it
	for (iKey = 0; iKey < nKeys; iKey++) {	// for each key
		int	iKeyInfo = (m_StartNote + iKey) % NOTES;	// account for start note
		if (!m_KeyInfo[iKeyInfo].BlackOffset)	// if key is black
			nWhites++;
	}
	// build array of key regions, one per key
	double	WhiteWidth;
	CSize	BlackSize;
	DWORD	dwStyle = GetStyle();
	bool	IsVertical = (dwStyle & PS_VERTICAL) != 0;
	if (IsVertical)	// if vertical orientation
		WhiteWidth = double(Size.cy) / nWhites;
	else	// horizontal orientation
		WhiteWidth = double(Size.cx) / nWhites;
	double	HScale = WhiteWidth / WHITE_WIDTH;
	double	BlackWidth = BLACK_WIDTH * HScale;
	if (IsVertical)	// if vertical orientation
		BlackSize = CSize(round(m_BlackHeightRatio * Size.cx), round(BlackWidth));
	else	// horizontal orientation
		BlackSize = CSize(round(BlackWidth), round(m_BlackHeightRatio * Size.cy));
	int	iStartWhite = m_KeyInfo[m_StartNote % NOTES].WhiteIndex;
	double	StartOffset = iStartWhite * WhiteWidth;
	int	iWhite = iStartWhite;
	int	PrevWhiteX = 0;
	int	PrevBlackOffset = 0;
	for (iKey = 0; iKey < nKeys; iKey++) {	// for each key
		CKey&	key = m_Key[iKey];
		int	iKeyInfo = (m_StartNote + iKey) % NOTES;	// account for start note
		int	BlackOffset = m_KeyInfo[iKeyInfo].BlackOffset;
		if (BlackOffset) {	// if black key
			double	OctaveOffset = (iWhite / WHITES) * WhiteWidth * WHITES;
			int	x = round(BlackOffset * HScale - StartOffset + OctaveOffset);
			CRect	rKey;
			if (IsVertical)	// if vertical orientation
				rKey = CRect(CPoint(0, Size.cy - x - BlackSize.cy), BlackSize);
			else	// horizontal orientation
				rKey = CRect(CPoint(x, 0), BlackSize);
			key.m_Rgn.CreateRectRgnIndirect(rKey);	// create black key region
			if (iKey) {	// if not first key
				// deduct this black key's region from previous white key's region
				CRgn&	PrevRgn = m_Key[iKey - 1].m_Rgn;
				PrevRgn.CombineRgn(&PrevRgn, &key.m_Rgn, RGN_DIFF);
			}
		} else {	// white key
			int	x = round((iWhite + 1) * WhiteWidth - StartOffset);
			CRect	rKey;
			if (IsVertical)	// if vertical orientation
				rKey = CRect(0, Size.cy - PrevWhiteX, Size.cx, Size.cy - x);
			else	// horizontal orientation
				rKey = CRect(PrevWhiteX, 0, x, Size.cy);
			key.m_Rgn.CreateRectRgnIndirect(rKey);	// create white key region
			if (PrevBlackOffset) {	// if previous key is black
				// deduct previous black key's region from this white key's region
				CRgn&	PrevRgn = m_Key[iKey - 1].m_Rgn;
				key.m_Rgn.CombineRgn(&key.m_Rgn, &PrevRgn, RGN_DIFF);
			}
			PrevWhiteX = x;
			iWhite++;
		}
		key.m_IsBlack = BlackOffset != 0;
		PrevBlackOffset = BlackOffset;
	}
	m_BlackKeySize = BlackSize;
	if (dwStyle & PS_SHOW_SHORTCUTS) {	// if showing shortcuts
		m_KeyLabel.RemoveAll();	// delete any existing labels
		m_KeyLabel.SetSize(nKeys);	// allocate labels
	}
	// if using or showing shortcuts
	if (dwStyle & (PS_SHOW_SHORTCUTS | PS_USE_SHORTCUTS)) {
		memset(m_ScanCodeToKey, -1, sizeof(m_ScanCodeToKey));
		int	iScanCode = 0;
		for (int iKey = 0; iKey < nKeys; iKey++) {	// for each key
			// if key is white, and first key or previous key is white
			if (!IsBlack(iKey) && (!iKey || !IsBlack(iKey - 1)))
				iScanCode++;	// advance one extra scan code
			if (iScanCode < _countof(m_ScanCode)) {	// if within scan code array
				int	ScanCode = m_ScanCode[iScanCode];
				ASSERT(ScanCode < _countof(m_ScanCodeToKey));
				m_ScanCodeToKey[ScanCode] = static_cast<char>(iKey);
				if (dwStyle & PS_SHOW_SHORTCUTS) {	// if showing shortcuts
					TCHAR	KeyName[2];	// buffer for shortcut key name
					if (GetKeyNameText(ScanCode << 16, KeyName, _countof(KeyName)))
						m_KeyLabel[iKey] = KeyName;
				}
			}
			iScanCode++;
		}
	}
	if (m_Font == NULL)	// if window font not specified
		UpdateKeyLabelFont(Size, dwStyle);	// update auto-scaled key label font
}
Exemplo n.º 8
0
void StorageBase::SetClean(bool clean)
{
    SetSwitch(Clean, clean);
    if (!clean && IsBlack())
        SetColor(ObjectColor::Grey);
}
Exemplo n.º 9
0
//nPly指明当前搜索的层数,每层将走法存在不同的位置,以免覆盖
//nSide指明产生哪一方的走法,TRUE为红方,FALSE是黑方
int CMoveGenerator::CreatePossibleMove(BYTE position[][9],int nPly,int nSide,int nUserChessColor)
{
    int nChessID;
    int i,j;

    m_nMoveCount=0;
    m_nUserChessColor=nUserChessColor;

    for(j=0;j<9;j++)
        for(i=0;i<10;i++)
        {
            if(position[i][j]!=NOCHESS)
            {
                nChessID=position[i][j];

                if(nUserChessColor==REDCHESS)
                {
                    if(!nSide && IsRed(nChessID))
                        continue;//如要产生黑棋走法,跳过红棋
                    
                    if(nSide && IsBlack(nChessID))
                        continue;//如要产生红棋走法,跳过黑棋
                }
                else
                {
                    if(nSide && IsRed(nChessID))
                        continue;//如要产生黑棋走法,跳过红棋
                    
                    if(!nSide && IsBlack(nChessID))
                        continue;//如要产生红棋走法,跳过黑棋
                }

                switch(nChessID)
                {
                case R_KING://红帅
                case B_KING://黑将
                    Gen_KingMove(position,i,j,nPly);
                    break;

                case R_BISHOP://红士
                    Gen_RBishopMove(position,i,j,nPly);
                    break;
                
                case B_BISHOP://黑士
                    Gen_BBishopMove(position,i,j,nPly);
                    break;
                
                case R_ELEPHANT://红相
                case B_ELEPHANT://黑象
                    Gen_ElephantMove(position,i,j,nPly);
                    break;
                
                case R_HORSE://红马
                case B_HORSE://黑马
                    Gen_HorseMove(position,i,j,nPly);
                    break;
                
                case R_CAR://红车
                case B_CAR://黑车
                    Gen_CarMove(position,i,j,nPly);
                    break;

                case R_PAWN://红兵
                    Gen_RPawnMove(position,i,j,nPly);
                    break;
                
                case B_PAWN://黑卒
                    Gen_BPawnMove(position,i,j,nPly);
                    break;
                
                case B_CANON://黑炮
                case R_CANON://红炮
                    Gen_CanonMove(position,i,j,nPly);
                    break;
                
                default:
                    break;
                }
            }
        }

    return m_nMoveCount;
}