In Game Theory, Nim is a mathematical game that involves taking heaps from piles, and the person who clicks the last one wins. The instructions are below, and the mathematics of the game are in the credits. ***Instructions*** On each turn, a player must choose a row and remove a number of objects (at least 1) from that row. The player who must remove the last piece wins.
https://scratch.mit.edu/projects/222662897/ - A Neural Network! ***Mathematics*** A "normal" game of nim (where the last person to grab nim piece wins) has been mathematically solved for any collection of arbitrary piles. In fact, any impartial game, essentially where a player where each player can make the same move if given the same board, can be reduced to a game of nim. It is important to note that there is a different type of nim called misère where the person who take the last one loses, but that version plays less nicely with game theory. The instructions for how to win a game of nim are below. ***Winning the game*** First, convert the number of "nims" in every row into binary. For example, 7 becomes 111, 5 becomes 101, 3 becomes 11 and 1 becomes 1. Each of these numbers is called a nimber. We then add all of the numbers together using a special kind called nimber addition. When two nimbers are added, 1 plus 1 becomes 0, not 10 like it would in normal binary addition. In this way, 1+11+101+111 =10+101+111=111+111=0. If the nimbers in every row add to 0, we call it balanced. Otherwise, it is imbalanced. For normal nim games, it is a player's goal to finish every one of his moves with a nim sum of zero. This is because when the nim sum is zero the next player will have to make it unbalanced, and at the end of the game this will mean the other player has to take the second to last piece, losing the normal game. If both players play an optimal strategy, we can predict who will win any nim game based on the nim sum of the rows. If the nim sum is an odd number of non-zero digits, then player one will win; otherwise player 2 will.