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). 


  [ say
    "Who goes first: Computer, Player"
    say " or Random?"  cr
    [ $ "Enter C, P or R: " input
      dup size 1 != iff drop again
      0 peek
      dup char C = iff [ drop 0 ] done
      dup char P = iff [ drop 1 ] done
      char R = iff [ 2 random ] done
       again ]
    cr
    dup iff [ say "You go first." ]
    else [ say "I will go first." ]
    cr ]                                  is chooseplayer (   --> n   )
 
                                  forward is player       ( n --> n x )
 
  [ [ dup 17 > iff 1 done
      4 over 4 mod
      dup 0 = if [ drop 3 ]
      - ]
    dup say "Computer chooses " echo
    say "." cr
    + ' player ]                          is computer     ( n --> n x )
 
  [ say "Choose 1 2 or 3 (running "
    $ "total must not exceed 21, Q to quit): " input
    dup $ "Q" = iff [ drop 21 999 ] done
    trim reverse trim reverse
    $->n not iff drop again
    dup 1 4 within not iff drop again
    2dup + 21 > iff drop again
    + ' computer ]                  resolves player       ( n --> n x )
 
  [ say "The player who makes 21 loses." cr
    0 chooseplayer
    iff [ ' player ] else [ ' computer ]
    [ say "Running total is "
      over echo say "." cr cr
      do
      over 21 = until ]
    cr
    dup 999 = iff
      [ drop 2drop say "Quitter!" ] done
    ' computer = iff
        [ say "The computer won!" ]
    else [ say "You won! Well done!" ]
    drop ]                                 is play        (   -->     )