示例#1
0
/* remove item from list */
void ListTakeOut
    (
    LinkedList  list,   /* list handler */
    MemPtr      item    /* list item */
    )
{
    if ( list != NULL && item != NULL ) {
        ListNode* node;
        ListNode* prev;

        node = list->first;
        prev = NULL;

        while ( node != NULL && node->data != item ) {
            prev = node;
            node = node->next;
        }

        if ( node != NULL ) {
            if ( IsFirst( list, node ) )
                list->first = node->next;
            if ( IsLast( list, node ) )
                list->last = prev;
            if ( prev != NULL )
                prev->next = node->next;

            SafeMemPtrFree( node );
            list->count--;
        }
    }
}
示例#2
0
void DiscardScene::Update(MahjongTable* pMahjongTable, SharedPlayers* pSharedPlayers, SharedPlayer* pOwnerPlayer)
{
	if (m_frame >= 6)
	{
		m_isNextScene = true;
	}
	std::cout << "捨て牌フレーム:" << m_frame << std::endl;
	m_frame++;
	
	if (IsFirst())
	{
		(*pOwnerPlayer)->MyTurn(true);
	}
}
示例#3
0
 /**
  * Is the specified item the first or the last one in the list?
  */
 bool IsEdge(const ListHead &item) const {
   return IsFirst(item) || IsLast(item);
 }
示例#4
0
void
nsGenConList::Insert(nsGenConNode* aNode)
{
  // Check for append.
  if (mList.isEmpty() || NodeAfter(aNode, mList.getLast())) {
    mList.insertBack(aNode);
  } else {
    // Binary search.

    // the range of indices at which |aNode| could end up.
    // (We already know it can't be at index mSize.)
    uint32_t first = 0, last = mSize - 1;

    // A cursor to avoid walking more than the length of the list.
    nsGenConNode* curNode = mList.getLast();
    uint32_t curIndex = mSize - 1;

    while (first != last) {
      uint32_t test = (first + last) / 2;
      if (last == curIndex) {
        for ( ; curIndex != test; --curIndex)
          curNode = Prev(curNode);
      } else {
        for ( ; curIndex != test; ++curIndex)
          curNode = Next(curNode);
      }

      if (NodeAfter(aNode, curNode)) {
        first = test + 1;
        // if we exit the loop, we need curNode to be right
        ++curIndex;
        curNode = Next(curNode);
      } else {
        last = test;
      }
    }
    curNode->setPrevious(aNode);
  }
  ++mSize;

  // Set the mapping only if it is the first node of the frame.
  // The DEBUG blocks below are for ensuring the invariant required by
  // nsGenConList::DestroyNodesFor. See comment there.
  if (IsFirst(aNode) ||
      Prev(aNode)->mPseudoFrame != aNode->mPseudoFrame) {
#ifdef DEBUG
    if (nsGenConNode* oldFrameFirstNode = mNodes.Get(aNode->mPseudoFrame)) {
      MOZ_ASSERT(Next(aNode) == oldFrameFirstNode,
                 "oldFrameFirstNode should now be immediately after "
                 "the newly-inserted one.");
    } else {
      // If the node is not the only node in the list.
      if (!IsFirst(aNode) || !IsLast(aNode)) {
        nsGenConNode* nextNode = Next(aNode);
        MOZ_ASSERT(!nextNode || nextNode->mPseudoFrame != aNode->mPseudoFrame,
                   "There shouldn't exist any node for this frame.");
        // If the node is neither the first nor the last node
        if (!IsFirst(aNode) && !IsLast(aNode)) {
          MOZ_ASSERT(Prev(aNode)->mPseudoFrame != nextNode->mPseudoFrame,
                     "New node should not break contiguity of nodes of "
                     "the same frame.");
        }
      }
    }
#endif
    mNodes.Put(aNode->mPseudoFrame, aNode);
  } else {
#ifdef DEBUG
    nsGenConNode* frameFirstNode = mNodes.Get(aNode->mPseudoFrame);
    MOZ_ASSERT(frameFirstNode, "There should exist node map for the frame.");
    for (nsGenConNode* curNode = Prev(aNode);
         curNode != frameFirstNode; curNode = Prev(curNode)) {
      MOZ_ASSERT(curNode->mPseudoFrame == aNode->mPseudoFrame,
                 "Every node between frameFirstNode and the new node inserted "
                 "should refer to the same frame.");
      MOZ_ASSERT(!IsFirst(curNode),
                 "The newly-inserted node should be in a contiguous run after "
                 "frameFirstNode, thus frameFirstNode should be reached before "
                 "the first node of mList.");
    }
#endif
  }

  NS_ASSERTION(IsFirst(aNode) || NodeAfter(aNode, Prev(aNode)),
               "sorting error");
  NS_ASSERTION(IsLast(aNode) || NodeAfter(Next(aNode), aNode),
               "sorting error");
}
void Board::UpdatePathsStatsAllShortestPathsBFS(Board& aBoard, const Player& winner) {

    // bfs queue
    short queue[Dim::actual_field_count / 2 + 1];
    // marks in which step node was visited
    unsigned short visited[Dim::actual_field_count];
    // queue markings
    short beg = 0, end = -1;

    memset(visited, 0, Dim::actual_field_count * sizeof(visited[0]));

    if (Player::First() == winner) {
        for (uint i = Dim::OfPos(1, 1); i <= Dim::OfPos(Dim::board_size, 1); i = i + Dim::right)
            if (IsFirst(board[i])) {
                // I put to queue every node by the edge
                queue[++end]=i;
                //and mark it as visited in first step
                visited[i]=1;
            }

        /*
         * Standard BFS:
         * I try to reach the other edge of the board using nodes
         * that belong to the first player. I know that is possible because
         * first player is the winner. For each visited guy I count length of
         * a shotrest path leading from first edge to him.
         */
        for (; beg <= end; ++beg)
            FOR_SIX(int dir)
                if ((visited[queue[beg] + dir] == 0) && IsFirst(board[queue[beg] + dir])){
                    queue[++end] = queue[beg] + dir;
                    visited[queue[end]] = visited[queue[beg]] + 1;
                }

        /*
         * Now I have to find the shortest paths.
         * I find out which nodes by the other edge were visited as first ones
         */
        uint min = (uint) - 1;
        for (uint i = Dim::OfPos(1,Dim::board_size); i <= Dim::OfPos(Dim::board_size,Dim::board_size); i = i + Dim::right)
            if(visited[i] > 0 && visited[i] < min)
                min = visited[i];

        // cleaning queue
        beg = 0;
        end = -1;
        /*
         * Have to be prepared for second BFS. It shall start from the other edge
         * and shall be done backwards. We add to the queue neighbor(actual) if
         * player(actual)==player(neighbor(actual)) and if visited(actual)==visited(neighbor(actual))+1.
         * It guarantee that we visit only those nodes that are placed on a shortest path.
         * actual_mins says "how much nodes are waiting in queue to be expand and visited(those nodes)
         * was equal to min before it has been zeroed"
         * next_mins says "how much nodes are waiting in queue to be expand and visited(those nodes)
         * was equal to (min-1) before it has been zeroed"
         * I need those two variables to get know when decrease min.
         */
        int actual_mins = 0;
        int next_mins = 0;
        for (uint i = Dim::OfPos(1,Dim::board_size); i <= Dim::OfPos(Dim::board_size,Dim::board_size); i = i + Dim::right)
            if (visited[i] == min){
                queue[++end] = i;
                aBoard.timesOfBeingOnShortestPath[i]++;
                visited[i] = 0;
                actual_mins++;
            }

        for(; beg <= end; beg++) {
            FOR_SIX(int dir)
                if (visited[queue[beg] + dir] == min - 1 && visited[queue[beg] + 1]) {
                    next_mins++;
                    queue[++end]=queue[beg] + dir;
                    visited[queue[end]] = 0;
                    aBoard.timesOfBeingOnShortestPath[queue[end]]++;
                }
            if (--actual_mins == 0){
                actual_mins =next_mins;
                next_mins = 0;
                min--;
            }
        }

    } else {
        /*
         * Analogically for the other player marked with values < 0
         * there are changes in 'for' statements (vertically, not horizontally)
         * and in checking if player is second, not first
         */

        for (uint i = Dim::OfPos(1,1); i <= Dim::OfPos(1,Dim::board_size); i = i + Dim::down)