Nim game

You are encouraged to solve this task according to the task description, using any language you may know.
Nim is a simple game where the second player ─── if they know the trick ─── will always win.



The game has only 3 rules:

   start with   12   tokens
   each player takes   1,  2,  or  3   tokens in turn
  the player who takes the last token wins.


To win every time,   the second player simply takes 4 minus the number the first player took.   So if the first player takes 1,   the second takes 3 ─── if the first player takes 2,   the second should take 2 ─── and if the first player takes 3,   the second player will take 1.



Task

Design a simple Nim game where the human player goes first, and the computer always wins. The game should enforce the rules.




		;; MS-DOS Nim; assembles with nasm.
		bits	16		
		cpu	8086
getch:		equ	1
putch:		equ	2
puts:		equ	9 		; INT 21h calls		
maxtokens:	equ	12		; Amount of tokens there are
section		.text
		org	100h
		mov	dx,nim		; Print sign-on
		call	outs
		mov	ch,maxtokens	; CH = amount of tokens we have
loop:		mov	dx,tokens	; Tokens: |||...
		call	outs
		mov	ah,putch	; Print a | for each token
		mov	dl,'|'
		mov	dh,ch
puttoks:	int	21h
		dec	dh
		jnz	puttoks
		mov	dx,prompt	; Ask the user how many to take
		call	outs
ask:		mov	ah,getch	; Read keypress
		int	21h
		sub	al,'1'		; Make number (minus one)
		jc	bad		; Carry, it was <1 (bad)
		inc	al		; Add 1 (because we subtracted '1')
		cmp	al,3
		ja	bad		; If it was >3, it is bad
		cmp	al,ch
		ja	bad		; If it was > amount left, it is bad
		sub	ch,al		; Remove your tokens from pile
		mov	cl,4		; I take 4-N, which is 3-N-1
		sub	cl,al
		sub	ch,cl		; Remove my tokens from pile
		mov	dx,response	; Tell the user how many I took.
		call	outs
		mov	dl,'0'
		add	dl,cl
		mov	ah,putch
		int	21h
		cmp	ch,0		; Are there any tokens left?
		jne	loop		; If not, prompt again
		mov	dx,lose		; But otherwise, you've lost
		; Fall through into print string routine and then stop.
		;; Print string in DX. (This saves a byte each CALL)
outs:		mov	ah,puts
		int	21h
		ret
		;; Input is bad; beep, erase, ask again
bad:		mov	dx,wronginp
		call	outs
		jmp	ask
section		.data
nim:		db	'Nim$'
prompt:		db	13,10,'How many will you take (1-3)? $'
response:	db	13,10,'I take $'
tokens:		db	13,10,13,10,'Tokens: $'
lose:		db	13,10,'You lose!$'
wronginp:       db      8,7,32,8,'$' 