How to resolve the algorithm Rock-paper-scissors step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Rock-paper-scissors step by step in the Quackery programming language

Table of Contents

Problem Statement

Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player. Rock Paper Scissors is a two player game. Each player chooses one of rock, paper or scissors, without knowing the other player's choice. The winner is decided by a set of rules:

If both players choose the same thing, there is no winner for that round. For this task, the computer will be one of the players. The operator will select Rock, Paper or Scissors and the computer will keep a record of the choice frequency, and use that information to make a weighted random choice in an attempt to defeat its opponent.

Support additional choices   additional weapons.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rock-paper-scissors step by step in the Quackery programming language

Source code in the quackery programming language

  [ 0 ]                                  is rock       (     --> n )
  [ 1 ]                                  is paper      (     --> n )
  [ 2 ]                                  is scissor    (     --> n )

  [ $ "Choose rock, paper or scissors: "
    input cr
    trim reverse trim reverse
    $ "" swap witheach [ lower join ]
    dup $ "rock"  = iff
      [ drop rock ] done
    dup $ "paper" = iff
      [ drop paper ] done
    $ "scissors"  = iff
      scissor done
      again ]                            is player     (     --> n )

  [ stack 1 ]                            is rocks      (     --> s )
  [ stack 1 ]                            is papers     (     --> s )
  [ stack 1 ]                            is scissors   (     --> s )

  [ 1 swap
    [ table rocks papers scissors ]
    do tally ]                           is notechoice (   n -->   )

  [ 0 ' [ rocks papers scissors ]
    witheach [ share + ]
    random
    dup rocks share < iff
      [ drop paper ] done
    rocks share -
    papers share < iff
      scissor done
    rock ]                              is computer    (     --> n )

  [ say "Computer chose "
    [ table rock paper scissors ]
    echo say "." cr ]                   is echomove    (   n -->   )

  [ [ table
      [ table 0 1 2 ]
      [ table 2 0 1 ]
      [ table 1 2 0 ] ] do ]            is result      ( n n --> n )

  [ [ table
      $ "It's a draw."
      $ "Computer wins."
      $ "Player wins." ]
    do echo$ cr cr ]                    is announce    (   n -->   )

  [ stack 0 ]                           is draws       (     --> s )
  [ stack 0 ]                           is cwins       (     --> s )
  [ stack 0 ]                           is pwins       (     --> s )

  [ [ table draws cwins pwins ]
    1 swap tally ]                      is keepscore   (   n -->   )

  [ say "Computer: " cwins share echo
    say "  Player: " pwins share echo
    say "   Draws: " draws share echo
    cr cr ]                             is scoreboard  (     -->   )

  [ ' [ rocks papers scissors ]
    witheach [ 1 swap replace ]
    ' [ draws cwins pwins ]
    witheach [ 0 swap replace ] ]       is initialise  (     -->   )  

  [ 0
    [ drop
      $ "How many games? " input
      trim reverse trim reverse
      $->n until ]
    cr ]                                is games       (     --> n )

  [ initialise
    games times
      [ computer
        player dup notechoice
        over echomove
        result dup announce
        keepscore
        scoreboard ] ]                  is play        (     -->   )

  

You may also check:How to resolve the algorithm Comma quibbling step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the Raku programming language
You may also check:How to resolve the algorithm 9 billion names of God the integer step by step in the Sidef programming language
You may also check:How to resolve the algorithm Esthetic numbers step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Arrays step by step in the TI-83 BASIC programming language