コード例 #1
0
void GoRegionBoard::OnExecutedUncodedMove(int move, SgBlackWhite moveColor)
{
    if (DEBUG_REGION_BOARD)
        SgDebug() << "OnExecutedUncodedMove " << SgWritePoint(move) << '\n';
    {
        m_stack.StartMoveInfo();
        if (move != SG_PASS)
        {
            SG_ASSERT(! Board().LastMoveInfo(GO_MOVEFLAG_SUICIDE));
            // can't handle yet,
            // should be forbidden anyway. @todo allowed in Chinese rules.
            bool fWasCapture = Board().LastMoveInfo(GO_MOVEFLAG_CAPTURING);

            UpdateBlock(move, moveColor);

            {
                GoRegion* r = PreviousRegionAt(move, moveColor);
                bool split = GoEyeUtil::IsSplitPt(move, r->Points());

                r->OnAddStone(move);
                PushStone(r, move);
                SgPointSet points = r->Points();
                // needed even after RemoveRegion(r).
                if (split || points.IsEmpty())
                // must remove old region before generating new ones,
                // because removing clears m_anchor[]
                    RemoveRegion(r);

                if (split) // find new regions
                {
                    for (SgConnCompIterator it(points, Board().Size());
                         it; ++it)
                        GenRegion(*it, moveColor);
                }
            }

            if (fWasCapture)
            {
            //  FindNewNeighborRegions(move, moveColor);
                MergeAdjacentAndAddBlock(move, SgOppBW(moveColor));
            }

            m_code = Board().GetHashCode();
            if (HEAVYCHECK)
                CheckConsistency();
        }
    }

    {
        for (SgBWIterator it; it; ++it)
        {
            SgBlackWhite color(*it);
            for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
            {   GoRegion* r1 = *it;
                if (! r1->IsValid())
                    r1->ComputeBasicFlags();
            }
        }
    }
}
コード例 #2
0
GoRegion* GoRegionBoard::MergeAll(const SgVectorOf<GoRegion>& regions,
                                       const SgPointSet& captured,
                                       SgBlackWhite color)
{
    SgPointSet area(captured);
    for (SgVectorIteratorOf<GoRegion> it(regions); it; ++it)
        area |= (*it)->Points();
    {for (SgVectorIteratorOf<GoRegion> it(regions); it; ++it)
        RemoveRegion(*it);
    }
    GoRegion* r = GenRegion(area, color);

    return r;
}
コード例 #3
0
ファイル: Unit.cpp プロジェクト: Rizoo/snoxd-koserver
bool Unit::RegisterRegion()
{
	uint16 
		new_region_x = GetNewRegionX(), new_region_z = GetNewRegionZ(), 
		old_region_x = GetRegionX(),	old_region_z = GetRegionZ();

	if (GetRegion() == nullptr
		|| (old_region_x == new_region_x && old_region_z == new_region_z))
		return false;

	AddToRegion(new_region_x, new_region_z);

	RemoveRegion(old_region_x - new_region_x, old_region_z - new_region_z);
	InsertRegion(new_region_x - old_region_x, new_region_z - old_region_z);	

	return true;
}
コード例 #4
0
ファイル: Npc.cpp プロジェクト: DeathsEffigy/snoxd-koserver-1
void CNpc::RegisterRegion()
{
	int iRegX = 0, iRegZ = 0, old_region_x = 0, old_region_z = 0;
	iRegX = (int)(m_fCurX / VIEW_DISTANCE);
	iRegZ = (int)(m_fCurZ / VIEW_DISTANCE);

	if (m_sRegion_X != iRegX || m_sRegion_Z != iRegZ)
	{
		C3DMap* pMap = GetMap();
		if (pMap == NULL)
			return;
		
		old_region_x = m_sRegion_X;	old_region_z = m_sRegion_Z;
		pMap->RegionNpcRemove(m_sRegion_X, m_sRegion_Z, m_sNid);
		m_sRegion_X = iRegX;		m_sRegion_Z = iRegZ;
		pMap->RegionNpcAdd(m_sRegion_X, m_sRegion_Z, m_sNid);

		RemoveRegion( old_region_x - m_sRegion_X, old_region_z - m_sRegion_Z );	// delete npc 는 계산 방향이 진행방향의 반대...
		InsertRegion( m_sRegion_X - old_region_x, m_sRegion_Z - old_region_z );	// add npc 는 계산 방향이 진행방향...
	}
}
コード例 #5
0
ファイル: TestSpaceManager.cpp プロジェクト: ahadzi/celtx
// Test of removing regions. We especially need to test that we correctly
// coalesce adjacent rects and bands
//
// This tests the following:
// 1. simple test of removing the one and only band rect
// 2. removing a shared rect and verifying adjacent rects are coalesced
// 3. removing a band rect and making sure adjacent bands are combined
PRBool MySpaceManager::TestRemoveRegion()
{
  BandsInfo bandsInfo;
  BandRect* bandRect;
  nsresult  status;

  // Clear any existing regions
  ClearRegions();
  NS_ASSERTION(mBandList.IsEmpty(), "clear regions failed");

  /////////////////////////////////////////////////////////////////////////////
  // #1. A simple test of removing the one and only band rect
  status = AddRectRegion((nsIFrame*)0x01, nsRect(10, 100, 100, 100));
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");
  status = RemoveRegion((nsIFrame*)0x01);
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");
  GetBandsInfo(bandsInfo);
  if (bandsInfo.numBands != 0) {
    printf("TestRemoveRegion: wrong number of bands (#1): %i\n", bandsInfo.numBands);
    return PR_FALSE;
  }

  /////////////////////////////////////////////////////////////////////////////
  // #2. Test removing a rect that's shared. Make sure adjacent rects are
  // coalesced
  status = AddRectRegion((nsIFrame*)0x01, nsRect(10, 100, 100, 100));
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");
  status = AddRectRegion((nsIFrame*)0x02, nsRect(40, 100, 20, 100));
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");

  // Verify there are three rects in the band
  GetBandsInfo(bandsInfo);
  if (bandsInfo.bands[0].numRects != 3) {
    printf("TestRemoveRegion: wrong number of rects (#2): %i\n", bandsInfo.bands[0].numRects);
    return PR_FALSE;
  }

  // Remove the region associated with the second frame
  status = RemoveRegion((nsIFrame*)0x02);
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");
  GetBandsInfo(bandsInfo);
  if (bandsInfo.bands[0].numRects != 1) {
    printf("TestRemoveRegion: failed to coalesce adjacent rects (#2)\n");
    return PR_FALSE;
  }
  bandRect = bandsInfo.bands[0].firstRect;
  if ((bandRect->mLeft != 10) || (bandRect->mRight != 110)) {
    printf("TestRemoveRegion: wrong size rect (#2)\n");
    return PR_FALSE;
  }

  /////////////////////////////////////////////////////////////////////////////
  // #3. Test removing a band rect and making sure adjacent bands are combined
  status = AddRectRegion((nsIFrame*)0x02, nsRect(10, 140, 20, 20));
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");

  // Verify there are three bands and that each band has three rects
  GetBandsInfo(bandsInfo);
  if (bandsInfo.numBands != 3) {
    printf("TestRemoveRegion: wrong number of bands (#3): %i\n", bandsInfo.numBands);
    return PR_FALSE;
  }
  if (bandsInfo.bands[0].numRects != 1) {
    printf("TestRemoveRegion: band #1 wrong number of rects (#3): %i\n", bandsInfo.bands[0].numRects);
    return PR_FALSE;
  }
  if (bandsInfo.bands[1].numRects != 2) {
    printf("TestRemoveRegion: band #2 wrong number of rects (#3): %i\n", bandsInfo.bands[1].numRects);
    return PR_FALSE;
  }
  if (bandsInfo.bands[2].numRects != 1) {
    printf("TestRemoveRegion: band #3 wrong number of rects (#3): %i\n", bandsInfo.bands[2].numRects);
    return PR_FALSE;
  }

  // Remove the region associated with the second frame
  status = RemoveRegion((nsIFrame*)0x02);
  NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status");
  GetBandsInfo(bandsInfo);
  if (bandsInfo.bands[0].numRects != 1) {
    printf("TestRemoveRegion: failed to coalesce adjacent rects (#3)\n");
    return PR_FALSE;
  }
  bandRect = bandsInfo.bands[0].firstRect;
  if ((bandRect->mLeft != 10) || (bandRect->mRight != 110)) {
    printf("TestRemoveRegion: wrong size rect (#3)\n");
    return PR_FALSE;
  }

  return PR_TRUE;
}
コード例 #6
0
void GoRegionBoard::OnUndoneMove()
// Called after a move has been undone. The board is guaranteed to be in
// a legal state.
{
    //SG_ASSERT(false); // incremental code is incomplete, do not call
    if (DEBUG_REGION_BOARD)
        SgDebug() << "OnUndoneMove " << '\n';

    const bool IS_UNDO = false;
    SgVectorOf<GoRegion> changed;

    for (int val = m_stack.PopEvent(); val != SG_NEXTMOVE;
         val = m_stack.PopEvent())
    {

        switch (val)
        {
            case REGION_REMOVE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                AddRegion(r, IS_UNDO);
                changed.Insert(r);
            }
            break;
            case REGION_ADD:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                RemoveRegion(r, IS_UNDO);
            }
            break;
            case REGION_REMOVE_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                AddBlock(b, IS_UNDO);
                for (int nu = m_stack.PopInt(); nu > 0; --nu)
                {
                    GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                    if (CHECK)
                        SG_ASSERT(! r->Blocks().Contains(b));
                    r->BlocksNonConst().PushBack(b);
                    changed.Insert(r);
                }
            }
            break;
            case REGION_ADD_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                RemoveBlock(b, IS_UNDO, true);
            }
            break;
            case REGION_ADD_STONE:
            {   GoRegion* r = static_cast<GoRegion*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                r->OnRemoveStone(p);
                m_region[r->Color()][p] = r;
                changed.Insert(r);
            }
            break;
            case REGION_ADD_STONE_TO_BLOCK:
            {   GoBlock* b = static_cast<GoBlock*>(m_stack.PopPtr());
                SgPoint p = m_stack.PopInt();
                b->RemoveStone(p);
                m_block[p] = 0;
            }
            break;
            default:
                SG_ASSERT(false);
        }
    }

    for (SgVectorIteratorOf<GoRegion> it(changed); it; ++it)
    {
        (*it)->ResetNonBlockFlags();
        (*it)->ComputeBasicFlags();
    }

    if (HEAVYCHECK)
    {
        for (SgBWIterator it; it; ++it)
        {
            SgBlackWhite color(*it);
            for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it)
            {
                const GoRegion* r = *it;
                SG_UNUSED(r);
                SG_ASSERT(r->IsValid());
            }
        }
    }

    m_code = Board().GetHashCode();
    if (HEAVYCHECK)
        CheckConsistency();
}