21 game

You are encouraged to solve this task according to the task description, using any language you may know.
21 is a two player game, the game is played by choosing
a number (1, 2, or 3) to be added to the running total.

The game is won by the player whose chosen number causes the running total
to reach exactly 21.

The running total starts at zero.
One player will be the computer.

Players alternate supplying a number to be added to the running total.



Task

Write a computer program that will:

 do the prompting (or provide a button menu), 
 check for errors and display appropriate error messages, 
 do the additions (add a chosen number to the running total), 
 display the running total, 
 provide a mechanism for the player to quit/exit/halt/stop/close the program,
 issue a notification when there is a winner, and
 determine who goes first (maybe a random or user choice, or can be specified when the game begins). 


 
g21=: summarize@play@setup ::('g21: error termination'"_)
 
NB. non-verb must be defined before use, otherwise are assumed verbs.
Until=: 2 :'u^:(0-:v)^:_'
 
t=: 'score turn choice'
(t)=: i. # ;: t
empty erase't'
 
Fetch=: &{
Alter=: }
 
play=: move Until done
done=: 21 <: score Fetch
move=: [: update you`it@.(turn Fetch)
 
update=: swap@display@add
add=: score Alter~ (score Fetch + choice Fetch)
display=: [ ([: echo 'sum: {}' format~ score Fetch)
swap=: turn Alter~ ([: -. turn Fetch)
 
it=: ([ [: echo 'It chose {}.' format~ choice Fetch)@(choice Alter~ cb)
cb=: (1:`r`3:`2:)@.(4 | score Fetch)     NB. computer brain
r=: 3 :'>:?3'
 
you=: qio1@check@acquire@prompt
prompt=: [ ([: echo 'your choice?'"_)
acquire=: choice Alter~ ('123' i. 0 { ' ' ,~ read)
check=: (choice Alter~ (665 - score Fetch))@([ ([: echo 'g21: early termination'"_))^:(3 = choice Fetch)
qio1=: choice Alter~ ([: >: choice Fetch)
 
setup=: ([ [: echo 'On your turn enter 1 2 or 3, other entries exit'"_)@((3 :'?2') turn Alter ])@0 0 0"_  NB. choose first player randomly
summarize=: ' won' ,~  (];._2 'it you ') {~ turn Fetch
 
read=: 1!:1@:1:
write=: 1!:2 4: NB. unused
format=: ''&$: :([: ; (a: , [: ":&.> [) ,. '{}' ([ (E. <@}.;._1 ]) ,) ])
 