The Grundy number of a position is the minimum excludant (MEX) of the Grundy numbers of all positions you can move to. MEX of a set is the smallest non-negative integer not in the set. For example, MEX of {, , } is . Terminal positions have Grundy number . For other positions, compute MEX of successor Grundy numbers.
This takes time on DAGs. You compute Grundy numbers recursively: the Grundy number of a position is the minimum excludant of all positions reachable in one move. For combined games, XOR the Grundy numbers.