unsigned Map::didWin(char player) const { std::vector<bool> visited; std::vector<unsigned> route; Loc startLoc = {0,0}; unsigned int* incr = nullptr; if (player == US) { startLoc.y = 0; incr = &startLoc.x; } else { startLoc.x = 0; incr = &startLoc.y; } for (unsigned i = 0; i < BOARD_DIM; i++) { unsigned numSqs = 0; route.clear(); route.reserve(BOARD_SIZE * 2); visited.clear(); visited.assign(BOARD_SIZE, false); *incr = i; if (get(startLoc).owner != player) continue; unsigned start = get(startLoc).num; visited[start] = true; route.push_back(start); while (!route.empty()) { unsigned temp(route.back()); if (getLoc(temp).y == BOARD_DIM-1 && player == US) return numSqs; else if (getLoc(temp).x == BOARD_DIM-1 && player == ENEMY) return numSqs; route.pop_back(); std::vector<unsigned> adjs = getAdj(temp, player); for (unsigned j = 0; j < adjs.size(); j++) { if (visited[adjs[j]]) continue; visited[adjs[j]] = true; route.push_back(adjs[j]); if (orig->get(adjs[j]).owner == player) { numSqs++; } } } } return 0; }
/* * Return the degree (i.e. the number of neighorbs) of node u. * * Preconditions: u is a legal label; */ unsigned MatrixGraph::degree(NodeID u) const { if (0 <= u < M.size()) { return getAdj(u).size(); } }
unsigned ListGraph::degree(NodeID u) const{ if(0 <= u < edgeList.size()) return getAdj(u).size(); }
unsigned int MatrixGraph::degree(NodeID u) const { return getAdj(u).size(); }
// Returns the number of nodes neighboring node u unsigned ListGraph::degree(NodeID u) const{ if(u >= 0 && u < edgeList.size()){ return getAdj(u).size(); } }