Nim, Grundy Numbers & Winning Positions
In short: in Nim, two players alternate taking any positive number of stones from one heap, and whoever takes the last stone wins. There's no searching needed to know who's winning: XOR every heap size together. If the result is 0, the player about to move is already losing against perfect play. If it's anything else, there's always a move — take from the heap whose own bit pattern can absorb the difference — that brings the XOR back to 0 and hands the loss to the opponent instead. Grundy numbers extend this idea past Nim to any "take-away" game: the Grundy number of a position is the mex (minimum excludant — the smallest non-negative integer not reachable in one move) of the Grundy numbers of everywhere one move can reach, and a position is a loss for the mover exactly when its Grundy number is 0.

Why XOR, and why zero loses
Each bit column is its own tiny vote. XOR of a column is 1 exactly when an odd number of heaps have a 1 there.
Column b2: 0, 1, 1 — two 1s, an even number, so XOR is 0. 4 by 3 table. 10 of 12 cells filled.
A losing position (XOR already 0) stays losing no matter what the mover does, because changing one heap always flips at least one bit somewhere, which can never bring an all-even column count back to all-even everywhere at once: