{
  "id": "P080",
  "slug": "rock-paper-scissors",
  "key": "P080-rock-paper-scissors",
  "title": "Rock paper scissors",
  "summary": "Rock paper scissors against a computer that learns how often you play each move and what you play after each, guessing your next move and playing what beats it; fixed strategies played for hundreds of rounds; and what it has learned about you.",
  "entry": "main.eml",
  "ui": "terminal",
  "readme": "# P080 - Rock paper scissors\n\nRock paper scissors against a computer that learns how you play. You can\nplay it yourself, or let a fixed strategy play it for up to 300 rounds,\nand see what it has learned about you.\n\n- `main.eml` - the menu, playing rounds, the strategies, and what it has\n  learned\n- `rps.eml` - the rules, the computer's memory and guess, one round, and\n  the fixed strategies\n\nHow each part works:\n\n- The rules, as in the corpus case `rock-paper-scissors-simulator`, here\n  with moves as 0 rock, 1 paper, 2 scissors: (m + 1) % 3 beats m, and\n  (you - computer + 3) % 3 says who won.\n- The computer counts how often you play each move, and what you play\n  after each move. To guess your next move it looks at what you have\n  played after your last one; with nothing there, at what you play most;\n  with nothing at all, it picks at random. Then it plays what beats the\n  guess. It chooses before it sees your move. A tie between equally\n  common moves is broken at random, from a linear congruential\n  generator's top 16 bits, so the order of the moves cannot steer it.\n- What it can and cannot learn: a cycle (rock, paper, scissors, ...) or\n  always the same move, it learns within a few rounds and then wins\n  almost every time. Against random moves it can do no better than a\n  third. It only remembers your own last move, so a strategy built on\n  ITS last move - playing what beats it, or copying it - is something it\n  cannot see. Over 300 rounds it wins only 41% and 43% of those.\n\nWhat is checked: menu choices 1 to 5; moves as rock, paper, scissors or\nr, p, s, an empty answer stopping; a strategy of cycle, rock, copy,\nbeat-last or random; 10 to 300 rounds.\n\nSessions: `sessions/basic.in` gives:\n- nine rounds of rock, paper, scissors over and over: the computer wins\n  the first by luck, draws three while it learns, then wins every round;\n- what it learned from them;\n- 300 rounds each of cycle (99.0% to the computer), random (30.7%),\n  beat-last (41.3%) and copy (43.0%), and 30 of rock (100%);\n- forgetting, then nothing learned.\n\n`sessions/bad-input.in` gives:\n- menu choices 0 and x;\n- the moves rk and lizard, then stopping after no rounds;\n- the strategy mirror, then 9, 301 and abc rounds, and two cancels.\n\nBuilt on the verified corpus case `rock-paper-scissors-simulator` (who\nbeats whom, and keeping score).\n",
  "modules": [
    {
      "name": "main.eml",
      "eml": "# P080 rock paper scissors against a computer that learns: play it\n# yourself, or let a fixed strategy play it for many rounds, and see what\n# it has learned about you.\nimport rps\n\ndef trim(s):\n    0 => i\n    len(s) => j\n    while i < j and s[i] == \" \":\n        i + 1 => i\n    while j > i and s[j - 1] == \" \":\n        j - 1 => j\n    return s[i:j]\n\ndef number(s):\n    if len(s) == 0 or len(s) > 3:\n        return -1\n    0 => n\n    for c in s:\n        if not (c >= \"0\" and c <= \"9\"):\n            return -1\n        n * 10 + int(c) => n\n    return n\n\ndef lpad(s, n):\n    while len(s) < n:\n        \" \" + s => s\n    return s\n\ndef pad(s, n):\n    while len(s) < n:\n        s + \" \" => s\n    return s\n\n[\"rock\", \"paper\", \"scissors\"] => NAMES\n\ndef move_of(s):\n    if s == \"rock\" or s == \"r\":\n        return 0\n    if s == \"paper\" or s == \"p\":\n        return 1\n    if s == \"scissors\" or s == \"s\":\n        return 2\n    return -1\n\ndef percent(a, b):\n    # a / b as a percentage to one decimal, rounded half up.\n    2000 * a + b => n\n    2 * b => d\n    0 => q\n    while n >= d:\n        n - d => n\n        q + 1 => q\n    0 => whole\n    q => r\n    while r >= 10:\n        r - 10 => r\n        whole + 1 => whole\n    return str(whole) + \".\" + str(r) + \"%\"\n\ndef score(mem):\n    return \"You \" + str(mem[5]) + \", computer \" + str(mem[6]) + \", draws \" + str(mem[7]) + \".\"\n\ndef why(how, last):\n    if how == \"after\":\n        return \"from what you played after \" + NAMES[last]\n    if how == \"often\":\n        return \"from what you play most\"\n    return \"at random, with nothing to go on\"\n\ndef play(mem):\n    0 => k\n    while True:\n        trim(input(\"your move (rock, paper, scissors, or r, p, s)> \")) => s\n        if s == \"\":\n            (\"Stopped after \" + str(k) + \" rounds. \" + score(mem)) ^0\n            return mem\n        move_of(s) => you\n        if you == -1:\n            \"Type rock, paper or scissors (or r, p, s); an empty answer stops.\" ^0\n        else:\n            mem[2] => last\n            rps.play(mem, you) => r\n            r[0] => mem\n            k + 1 => k\n            [\"A draw.\", \"You win.\", \"The computer wins.\"] => said\n            (\"You \" + NAMES[you] + \", computer \" + NAMES[r[1]] + \" - it guessed \" + NAMES[r[2]] + \" \" + why(r[3], last) + \". \" + said[r[4]]) ^0\n            score(mem) ^0\n\ndef auto(mem):\n    while True:\n        trim(input(\"strategy (cycle, rock, copy, beat-last or random)> \")) => name\n        if name == \"\":\n            \"Cancelled.\" ^0\n            return mem\n        if name == \"cycle\" or name == \"rock\" or name == \"copy\" or name == \"beat-last\" or name == \"random\":\n            while True:\n                trim(input(\"rounds (10 to 300)> \")) => a\n                if a == \"\":\n                    \"Cancelled.\" ^0\n                    return mem\n                number(a) => n\n                if n >= 10 and n <= 300:\n                    rps.new_memory(2026) => m\n                    -1 => last_cpu\n                    99 => x\n                    for k in [0:n - 1]:\n                        rps.strategy_move(name, k, last_cpu, x) => sm\n                        sm[1] => x\n                        rps.play(m, sm[0]) => r\n                        r[0] => m\n                        r[1] => last_cpu\n                    (str(n) + \" rounds of \" + name + \" against a fresh computer: strategy \" + str(m[5]) + \", computer \" + str(m[6]) + \", draws \" + str(m[7]) + \".\") ^0\n                    (\"The computer won \" + percent(m[6], n) + \" of the rounds - against moves chosen at random it could expect a third.\") ^0\n                    return mem\n                \"Type a whole number from 10 to 300.\" ^0\n        \"Type cycle, rock, copy, beat-last or random.\" ^0\n\ndef learned(mem):\n    if mem[4] == 0:\n        \"Nothing yet: no rounds played.\" ^0\n        return\n    (\"After \" + str(mem[4]) + \" rounds:\") ^0\n    (\"  \" + pad(\"\", 16) + lpad(\"rock\", 6) + lpad(\"paper\", 7) + lpad(\"scissors\", 10)) ^0\n    (\"  \" + pad(\"you played\", 16) + lpad(str(mem[0][0]), 6) + lpad(str(mem[0][1]), 7) + lpad(str(mem[0][2]), 10)) ^0\n    for m in [0:2]:\n        mem[1][m] => row\n        (\"  \" + pad(\"after \" + NAMES[m], 16) + lpad(str(row[0]), 6) + lpad(str(row[1]), 7) + lpad(str(row[2]), 10)) ^0\n    rps.guess(mem) => g\n    (\"Next it guesses \" + NAMES[g[0]] + \" \" + why(g[1], mem[2]) + \", so it will play \" + NAMES[rps.beats(g[0])] + \".\") ^0\n\nrps.new_memory(2026) => memory\n\n\"== Rock paper scissors ==\" ^0\n\"Against a computer that learns how often you play each move, and what you play after each.\" ^0\nTrue => running\nwhile running:\n    \"\" ^0\n    \"1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\" ^0\n    trim(input(\"choice> \")) => choice\n    if choice == \"1\":\n        play(memory) => memory\n    elif choice == \"2\":\n        auto(memory) => memory\n    elif choice == \"3\":\n        learned(memory)\n    elif choice == \"4\":\n        rps.new_memory(2026) => memory\n        \"It has forgotten everything.\" ^0\n    elif choice == \"5\":\n        False => running\n    else:\n        \"Pick a number from 1 to 5.\" ^0\n\"Bye.\" ^0\n",
      "python": "import rps\n\ndef trim(s):\n    i = 0\n    j = len(s)\n    while i < j and s[i] == \" \":\n        i = i + 1\n    while j > i and s[j - 1] == \" \":\n        j = j - 1\n    return s[i:j]\n\ndef number(s):\n    if len(s) == 0 or len(s) > 3:\n        return -1\n    n = 0\n    for c in s:\n        if not (c >= \"0\" and c <= \"9\"):\n            return -1\n        n = n * 10 + int(c)\n    return n\n\ndef lpad(s, n):\n    while len(s) < n:\n        s = \" \" + s\n    return s\n\ndef pad(s, n):\n    while len(s) < n:\n        s = s + \" \"\n    return s\n\nNAMES = [\"rock\", \"paper\", \"scissors\"]\n\ndef move_of(s):\n    if s == \"rock\" or s == \"r\":\n        return 0\n    if s == \"paper\" or s == \"p\":\n        return 1\n    if s == \"scissors\" or s == \"s\":\n        return 2\n    return -1\n\ndef percent(a, b):\n    n = 2000 * a + b\n    d = 2 * b\n    q = 0\n    while n >= d:\n        n = n - d\n        q = q + 1\n    whole = 0\n    r = q\n    while r >= 10:\n        r = r - 10\n        whole = whole + 1\n    return str(whole) + \".\" + str(r) + \"%\"\n\ndef score(mem):\n    return \"You \" + str(mem[5]) + \", computer \" + str(mem[6]) + \", draws \" + str(mem[7]) + \".\"\n\ndef why(how, last):\n    if how == \"after\":\n        return \"from what you played after \" + NAMES[last]\n    if how == \"often\":\n        return \"from what you play most\"\n    return \"at random, with nothing to go on\"\n\ndef play(mem):\n    k = 0\n    while True:\n        s = trim(input(\"your move (rock, paper, scissors, or r, p, s)> \"))\n        if s == \"\":\n            print(\"Stopped after \" + str(k) + \" rounds. \" + score(mem))\n            return mem\n        you = move_of(s)\n        if you == -1:\n            print(\"Type rock, paper or scissors (or r, p, s); an empty answer stops.\")\n        else:\n            last = mem[2]\n            r = rps.play(mem, you)\n            mem = r[0]\n            k = k + 1\n            said = [\"A draw.\", \"You win.\", \"The computer wins.\"]\n            print(\"You \" + NAMES[you] + \", computer \" + NAMES[r[1]] + \" - it guessed \" + NAMES[r[2]] + \" \" + why(r[3], last) + \". \" + said[r[4]])\n            print(score(mem))\n\ndef auto(mem):\n    while True:\n        name = trim(input(\"strategy (cycle, rock, copy, beat-last or random)> \"))\n        if name == \"\":\n            print(\"Cancelled.\")\n            return mem\n        if name == \"cycle\" or name == \"rock\" or name == \"copy\" or name == \"beat-last\" or name == \"random\":\n            while True:\n                a = trim(input(\"rounds (10 to 300)> \"))\n                if a == \"\":\n                    print(\"Cancelled.\")\n                    return mem\n                n = number(a)\n                if n >= 10 and n <= 300:\n                    m = rps.new_memory(2026)\n                    last_cpu = -1\n                    x = 99\n                    for k in range(0, n):\n                        sm = rps.strategy_move(name, k, last_cpu, x)\n                        x = sm[1]\n                        r = rps.play(m, sm[0])\n                        m = r[0]\n                        last_cpu = r[1]\n                    print(str(n) + \" rounds of \" + name + \" against a fresh computer: strategy \" + str(m[5]) + \", computer \" + str(m[6]) + \", draws \" + str(m[7]) + \".\")\n                    print(\"The computer won \" + percent(m[6], n) + \" of the rounds - against moves chosen at random it could expect a third.\")\n                    return mem\n                print(\"Type a whole number from 10 to 300.\")\n        print(\"Type cycle, rock, copy, beat-last or random.\")\n\ndef learned(mem):\n    if mem[4] == 0:\n        print(\"Nothing yet: no rounds played.\")\n        return\n    print(\"After \" + str(mem[4]) + \" rounds:\")\n    print(\"  \" + pad(\"\", 16) + lpad(\"rock\", 6) + lpad(\"paper\", 7) + lpad(\"scissors\", 10))\n    print(\"  \" + pad(\"you played\", 16) + lpad(str(mem[0][0]), 6) + lpad(str(mem[0][1]), 7) + lpad(str(mem[0][2]), 10))\n    for m in range(0, 3):\n        row = mem[1][m]\n        print(\"  \" + pad(\"after \" + NAMES[m], 16) + lpad(str(row[0]), 6) + lpad(str(row[1]), 7) + lpad(str(row[2]), 10))\n    g = rps.guess(mem)\n    print(\"Next it guesses \" + NAMES[g[0]] + \" \" + why(g[1], mem[2]) + \", so it will play \" + NAMES[rps.beats(g[0])] + \".\")\n\nmemory = rps.new_memory(2026)\nprint(\"== Rock paper scissors ==\")\nprint(\"Against a computer that learns how often you play each move, and what you play after each.\")\nrunning = True\nwhile running:\n    print(\"\")\n    print(\"1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\")\n    choice = trim(input(\"choice> \"))\n    if choice == \"1\":\n        memory = play(memory)\n    elif choice == \"2\":\n        memory = auto(memory)\n    elif choice == \"3\":\n        learned(memory)\n    elif choice == \"4\":\n        memory = rps.new_memory(2026)\n        print(\"It has forgotten everything.\")\n    elif choice == \"5\":\n        running = False\n    else:\n        print(\"Pick a number from 1 to 5.\")\nprint(\"Bye.\")\n"
    },
    {
      "name": "rps.eml",
      "eml": "# P080 rock paper scissors - a computer that learns how you play. It counts\n# how often you play each move, and what you play after each move; it\n# guesses your next move from what you played last (or, with nothing to go\n# on, from how often you play each), and plays what beats it. Moves are 0\n# rock, 1 paper, 2 scissors; (m + 1) % 3 beats m.\n\ndef beats(m):\n    return (m + 1) % 3\n\ndef result(you, cpu):\n    # 0 a draw, 1 you win, 2 the computer wins.\n    return (you - cpu + 3) % 3\n\ndef draw(x):\n    # One step of a linear congruential generator (Numerical Recipes'\n    # constants, mod 2^32): [next state, its top 16 bits]; x / 65536 is a\n    # division by a power of two below 2^53, so it is exact.\n    (1664525 * x + 1013904223) % 4294967296 => x\n    return [x, int(x / 65536)]\n\ndef new_memory(seed):\n    # [how often each move, after each move how often each next move, your\n    # last move (-1 none), the random state, rounds, your wins, its wins,\n    # draws, right guesses].\n    return [[0, 0, 0], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], -1, seed, 0, 0, 0, 0, 0]\n\ndef most(counts, x):\n    # The move with the highest count; a tie is broken at random, so the\n    # guess cannot be steered by the order of the moves. [move, state].\n    0 => top\n    for c in counts:\n        if c > top:\n            c => top\n    [] => best\n    for m in [0:2]:\n        if counts[m] == top:\n            best + [m] => best\n    if len(best) == 1:\n        return [best[0], x]\n    draw(x) => d\n    return [best[d[1] % len(best)], d[0]]\n\ndef guess(mem):\n    # The guess and why: [move, \"after\" | \"often\" | \"random\", state].\n    mem[3] => x\n    if mem[2] >= 0:\n        mem[1][mem[2]] => after\n        if after[0] + after[1] + after[2] > 0:\n            most(after, x) => g\n            return [g[0], \"after\", g[1]]\n    if mem[0][0] + mem[0][1] + mem[0][2] > 0:\n        most(mem[0], x) => g\n        return [g[0], \"often\", g[1]]\n    draw(x) => d\n    return [d[1] % 3, \"random\", d[0]]\n\ndef play(mem, you):\n    # One round: the computer commits to its move before seeing yours,\n    # then learns from yours. Returns [memory, its move, its guess, why,\n    # result].\n    guess(mem) => g\n    beats(g[0]) => cpu\n    result(you, cpu) => r\n    [mem[0][0], mem[0][1], mem[0][2]] => often\n    often[you] + 1 => often[you]\n    [[mem[1][0][0], mem[1][0][1], mem[1][0][2]], [mem[1][1][0], mem[1][1][1], mem[1][1][2]], [mem[1][2][0], mem[1][2][1], mem[1][2][2]]] => after\n    if mem[2] >= 0:\n        after[mem[2]][you] + 1 => after[mem[2]][you]\n    [often, after, you, g[2], mem[4] + 1, mem[5], mem[6], mem[7], mem[8]] => out\n    if r == 1:\n        out[5] + 1 => out[5]\n    elif r == 2:\n        out[6] + 1 => out[6]\n    else:\n        out[7] + 1 => out[7]\n    if g[0] == you:\n        out[8] + 1 => out[8]\n    return [out, cpu, g[0], g[1], r]\n\ndef strategy_move(name, k, last_cpu, x):\n    # What a fixed strategy plays in round k (from 0): [move, state].\n    if name == \"cycle\":\n        return [k % 3, x]\n    if name == \"rock\":\n        return [0, x]\n    if name == \"copy\":\n        if last_cpu == -1:\n            return [0, x]\n        return [last_cpu, x]\n    if name == \"beat-last\":\n        if last_cpu == -1:\n            return [0, x]\n        return [beats(last_cpu), x]\n    draw(x) => d\n    return [d[1] % 3, d[0]]\n",
      "python": "def beats(m):\n    return (m + 1) % 3\n\ndef result(you, cpu):\n    return (you - cpu + 3) % 3\n\ndef draw(x):\n    x = (1664525 * x + 1013904223) % 4294967296\n    return [x, int(x / 65536)]\n\ndef new_memory(seed):\n    return [[0, 0, 0], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], -1, seed, 0, 0, 0, 0, 0]\n\ndef most(counts, x):\n    top = 0\n    for c in counts:\n        if c > top:\n            top = c\n    best = []\n    for m in range(0, 3):\n        if counts[m] == top:\n            best = best + [m]\n    if len(best) == 1:\n        return [best[0], x]\n    d = draw(x)\n    return [best[d[1] % len(best)], d[0]]\n\ndef guess(mem):\n    x = mem[3]\n    if mem[2] >= 0:\n        after = mem[1][mem[2]]\n        if after[0] + after[1] + after[2] > 0:\n            g = most(after, x)\n            return [g[0], \"after\", g[1]]\n    if mem[0][0] + mem[0][1] + mem[0][2] > 0:\n        g = most(mem[0], x)\n        return [g[0], \"often\", g[1]]\n    d = draw(x)\n    return [d[1] % 3, \"random\", d[0]]\n\ndef play(mem, you):\n    g = guess(mem)\n    cpu = beats(g[0])\n    r = result(you, cpu)\n    often = [mem[0][0], mem[0][1], mem[0][2]]\n    often[you] = often[you] + 1\n    after = [[mem[1][0][0], mem[1][0][1], mem[1][0][2]], [mem[1][1][0], mem[1][1][1], mem[1][1][2]], [mem[1][2][0], mem[1][2][1], mem[1][2][2]]]\n    if mem[2] >= 0:\n        after[mem[2]][you] = after[mem[2]][you] + 1\n    out = [often, after, you, g[2], mem[4] + 1, mem[5], mem[6], mem[7], mem[8]]\n    if r == 1:\n        out[5] = out[5] + 1\n    elif r == 2:\n        out[6] = out[6] + 1\n    else:\n        out[7] = out[7] + 1\n    if g[0] == you:\n        out[8] = out[8] + 1\n    return [out, cpu, g[0], g[1], r]\n\ndef strategy_move(name, k, last_cpu, x):\n    if name == \"cycle\":\n        return [k % 3, x]\n    if name == \"rock\":\n        return [0, x]\n    if name == \"copy\":\n        if last_cpu == -1:\n            return [0, x]\n        return [last_cpu, x]\n    if name == \"beat-last\":\n        if last_cpu == -1:\n            return [0, x]\n        return [beats(last_cpu), x]\n    d = draw(x)\n    return [d[1] % 3, d[0]]\n"
    }
  ],
  "sessions": [
    {
      "name": "bad-input",
      "input": "0\nx\n1\nrk\nlizard\n\n2\nmirror\ncycle\n9\n301\nabc\n\n2\n\n5\n",
      "screen": "== Rock paper scissors ==\nAgainst a computer that learns how often you play each move, and what you play after each.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 0\nPick a number from 1 to 5.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> x\nPick a number from 1 to 5.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 1\nyour move (rock, paper, scissors, or r, p, s)> rk\nType rock, paper or scissors (or r, p, s); an empty answer stops.\nyour move (rock, paper, scissors, or r, p, s)> lizard\nType rock, paper or scissors (or r, p, s); an empty answer stops.\nyour move (rock, paper, scissors, or r, p, s)> \nStopped after 0 rounds. You 0, computer 0, draws 0.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> mirror\nType cycle, rock, copy, beat-last or random.\nstrategy (cycle, rock, copy, beat-last or random)> cycle\nrounds (10 to 300)> 9\nType a whole number from 10 to 300.\nrounds (10 to 300)> 301\nType a whole number from 10 to 300.\nrounds (10 to 300)> abc\nType a whole number from 10 to 300.\nrounds (10 to 300)> \nCancelled.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> \nCancelled.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 5\nBye.\n",
      "interpreter": "equal"
    },
    {
      "name": "basic",
      "input": "1\nr\np\ns\nr\np\ns\nrock\npaper\nscissors\n\n3\n2\ncycle\n300\n2\nrock\n30\n2\nrandom\n300\n2\nbeat-last\n300\n2\ncopy\n300\n4\n3\n5\n",
      "screen": "== Rock paper scissors ==\nAgainst a computer that learns how often you play each move, and what you play after each.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 1\nyour move (rock, paper, scissors, or r, p, s)> r\nYou rock, computer paper - it guessed rock at random, with nothing to go on. The computer wins.\nYou 0, computer 1, draws 0.\nyour move (rock, paper, scissors, or r, p, s)> p\nYou paper, computer paper - it guessed rock from what you play most. A draw.\nYou 0, computer 1, draws 1.\nyour move (rock, paper, scissors, or r, p, s)> s\nYou scissors, computer scissors - it guessed paper from what you play most. A draw.\nYou 0, computer 1, draws 2.\nyour move (rock, paper, scissors, or r, p, s)> r\nYou rock, computer rock - it guessed scissors from what you play most. A draw.\nYou 0, computer 1, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> p\nYou paper, computer scissors - it guessed paper from what you played after rock. The computer wins.\nYou 0, computer 2, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> s\nYou scissors, computer rock - it guessed scissors from what you played after paper. The computer wins.\nYou 0, computer 3, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> rock\nYou rock, computer paper - it guessed rock from what you played after scissors. The computer wins.\nYou 0, computer 4, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> paper\nYou paper, computer scissors - it guessed paper from what you played after rock. The computer wins.\nYou 0, computer 5, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> scissors\nYou scissors, computer rock - it guessed scissors from what you played after paper. The computer wins.\nYou 0, computer 6, draws 3.\nyour move (rock, paper, scissors, or r, p, s)> \nStopped after 9 rounds. You 0, computer 6, draws 3.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 3\nAfter 9 rounds:\n                    rock  paper  scissors\n  you played           3      3         3\n  after rock           0      3         0\n  after paper          0      0         3\n  after scissors       2      0         0\nNext it guesses rock from what you played after scissors, so it will play paper.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> cycle\nrounds (10 to 300)> 300\n300 rounds of cycle against a fresh computer: strategy 0, computer 297, draws 3.\nThe computer won 99.0% of the rounds - against moves chosen at random it could expect a third.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> rock\nrounds (10 to 300)> 30\n30 rounds of rock against a fresh computer: strategy 0, computer 30, draws 0.\nThe computer won 100.0% of the rounds - against moves chosen at random it could expect a third.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> random\nrounds (10 to 300)> 300\n300 rounds of random against a fresh computer: strategy 112, computer 92, draws 96.\nThe computer won 30.7% of the rounds - against moves chosen at random it could expect a third.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> beat-last\nrounds (10 to 300)> 300\n300 rounds of beat-last against a fresh computer: strategy 135, computer 124, draws 41.\nThe computer won 41.3% of the rounds - against moves chosen at random it could expect a third.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 2\nstrategy (cycle, rock, copy, beat-last or random)> copy\nrounds (10 to 300)> 300\n300 rounds of copy against a fresh computer: strategy 31, computer 129, draws 140.\nThe computer won 43.0% of the rounds - against moves chosen at random it could expect a third.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 4\nIt has forgotten everything.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 3\nNothing yet: no rounds played.\n\n1) play  2) let a strategy play  3) what it has learned  4) make it forget  5) quit\nchoice> 5\nBye.\n",
      "interpreter": "equal"
    }
  ],
  "builtOn": [
    {
      "slug": "rock-paper-scissors-simulator",
      "caseId": "035-rock-paper-scissors-simulator",
      "title": "Case corpus: a self-authored rock-paper-scissors simulator"
    }
  ],
  "updated": "2026-10-14"
}
