NIM

Program: RMnim.z80

Like the Slow Square Root program, this is recent, but based  - in this case very loosely - on one I wrote for a Diehl programmable calculator, the first machine I ever programmed, back in 1973/4, that I've referred to elsewhere. The Diehl calculator had very limited programming capabilities - no text capability for messages and a limited number of programming steps - and the NIM program I wrote for it would have likely lacked validation of the user's input.

In this game, players take turns to remove 1, 2, or 3 counters from a pile of counters. The player taking the last counter loses the game. 

To win, at the end of each go, players should aim to leave 4n + 1 counters for their opponent, where n=0,1, 2, etc. The computer will always win if given the opportunity to implement the strategy.