{
  "format": "tokbit",
  "version": 1,
  "name": "Logik s počtem pokusů",
  "main": [
    {
      "id": "u6",
      "kind": "call",
      "call": "background(BLACK)"
    },
    {
      "id": "u7",
      "kind": "call",
      "call": "border(BLACK)"
    },
    {
      "id": "u8",
      "kind": "call",
      "call": "cls()"
    },
    {
      "id": "u9",
      "kind": "declare",
      "name": "barvy",
      "type": "list[int]",
      "init": "[RED, GREEN, YELLOW, PURPLE, CYAN, ORANGE]"
    },
    {
      "id": "u10",
      "kind": "declare",
      "name": "kod",
      "type": "list[int]",
      "init": "[]"
    },
    {
      "id": "u11",
      "kind": "for",
      "variable": "i",
      "range": "4",
      "body": [
        {
          "id": "u12",
          "kind": "call",
          "call": "kod.append(randint(1, 6))"
        }
      ]
    },
    {
      "id": "u13",
      "kind": "call",
      "call": "color(WHITE)"
    },
    {
      "id": "u14",
      "kind": "call",
      "call": "at(0, 0)"
    },
    {
      "id": "u15",
      "kind": "output",
      "values": "\"Barvy:\"",
      "newline": false
    },
    {
      "id": "u16",
      "kind": "for",
      "variable": "c",
      "range": "1, 7",
      "body": [
        {
          "id": "u17",
          "kind": "call",
          "call": "color(barvy[c - 1])"
        },
        {
          "id": "u18",
          "kind": "call",
          "call": "at(10 + (c - 1) * 4, 0)"
        },
        {
          "id": "u19",
          "kind": "output",
          "values": "str(c) + \"O\"",
          "newline": false
        }
      ]
    },
    {
      "id": "u20",
      "kind": "declare",
      "name": "tip",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u21",
      "kind": "declare",
      "name": "dobre",
      "type": "bool",
      "init": "False"
    },
    {
      "id": "u22",
      "kind": "declare",
      "name": "t",
      "type": "list[int]",
      "init": "[]"
    },
    {
      "id": "u23",
      "kind": "declare",
      "name": "pokus",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u24",
      "kind": "declare",
      "name": "cerne",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u25",
      "kind": "declare",
      "name": "bile",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u26",
      "kind": "declare",
      "name": "shody",
      "type": "int",
      "init": "0"
    },
    {
      "id": "u27",
      "kind": "declare",
      "name": "vyhra",
      "type": "bool",
      "init": "False"
    },
    {
      "id": "u28",
      "kind": "while",
      "condition": "pokus < 10 and not vyhra",
      "body": [
        {
          "id": "u29",
          "kind": "call",
          "call": "at(0, 22)"
        },
        {
          "id": "u30",
          "kind": "output",
          "values": "\" \" * 39",
          "newline": false
        },
        {
          "id": "u31",
          "kind": "call",
          "call": "at(0, 22)"
        },
        {
          "id": "u32",
          "kind": "input",
          "target": "tip",
          "prompt": "Tip (4 číslice 1 až 6):"
        },
        {
          "id": "u33",
          "kind": "assign",
          "target": "dobre",
          "value": "len(tip) == 4"
        },
        {
          "id": "u34",
          "kind": "for",
          "variable": "i",
          "range": "len(tip)",
          "body": [
            {
              "id": "u35",
              "kind": "if",
              "condition": "tip[i] not in \"123456\"",
              "then": [
                {
                  "id": "u36",
                  "kind": "assign",
                  "target": "dobre",
                  "value": "False"
                }
              ],
              "else": []
            }
          ]
        },
        {
          "id": "u37",
          "kind": "call",
          "call": "at(0, 20)"
        },
        {
          "id": "u38",
          "kind": "output",
          "values": "\" \" * 39",
          "newline": false
        },
        {
          "id": "u39",
          "kind": "if",
          "condition": "dobre",
          "then": [
            {
              "id": "u40",
              "kind": "assign",
              "target": "pokus",
              "value": "pokus + 1"
            },
            {
              "id": "u41",
              "kind": "assign",
              "target": "t",
              "value": "[]"
            },
            {
              "id": "u42",
              "kind": "for",
              "variable": "i",
              "range": "4",
              "body": [
                {
                  "id": "u43",
                  "kind": "call",
                  "call": "t.append(int(tip[i]))"
                }
              ]
            },
            {
              "id": "u44",
              "kind": "assign",
              "target": "cerne",
              "value": "0"
            },
            {
              "id": "u45",
              "kind": "for",
              "variable": "i",
              "range": "4",
              "body": [
                {
                  "id": "u46",
                  "kind": "if",
                  "condition": "t[i] == kod[i]",
                  "then": [
                    {
                      "id": "u47",
                      "kind": "assign",
                      "target": "cerne",
                      "value": "cerne + 1"
                    }
                  ],
                  "else": []
                }
              ],
              "comment": "Černý kolík: správná barva na správném místě."
            },
            {
              "id": "u48",
              "kind": "assign",
              "target": "shody",
              "value": "0"
            },
            {
              "id": "u49",
              "kind": "for",
              "variable": "c",
              "range": "1, 7",
              "body": [
                {
                  "id": "u50",
                  "kind": "assign",
                  "target": "shody",
                  "value": "shody + min(pocet(kod, c), pocet(t, c))"
                }
              ],
              "comment": "Shody barev bez ohledu na místo; bílé jsou shody bez černých."
            },
            {
              "id": "u51",
              "kind": "assign",
              "target": "bile",
              "value": "shody - cerne"
            },
            {
              "id": "u52",
              "kind": "for",
              "variable": "i",
              "range": "4",
              "body": [
                {
                  "id": "u53",
                  "kind": "call",
                  "call": "color(barvy[t[i] - 1])"
                },
                {
                  "id": "u54",
                  "kind": "call",
                  "call": "at(2 + i * 2, 2 + pokus)"
                },
                {
                  "id": "u55",
                  "kind": "output",
                  "values": "\"O\"",
                  "newline": false
                }
              ]
            },
            {
              "id": "u56",
              "kind": "call",
              "call": "color(WHITE)"
            },
            {
              "id": "u57",
              "kind": "call",
              "call": "at(12, 2 + pokus)"
            },
            {
              "id": "u58",
              "kind": "output",
              "values": "\"černé\", cerne, \"bílé\", bile",
              "newline": false
            },
            {
              "id": "u59",
              "kind": "assign",
              "target": "vyhra",
              "value": "cerne == 4"
            },
            {
              "id": "u60",
              "kind": "call",
              "call": "beep(440 + cerne * 110, 60)"
            }
          ],
          "else": [
            {
              "id": "u61",
              "kind": "call",
              "call": "color(LIGHT_RED)"
            },
            {
              "id": "u62",
              "kind": "call",
              "call": "at(0, 20)"
            },
            {
              "id": "u63",
              "kind": "output",
              "values": "\"Zadej čtyři číslice 1 až 6.\"",
              "newline": false
            },
            {
              "id": "u64",
              "kind": "call",
              "call": "color(WHITE)"
            }
          ]
        }
      ]
    },
    {
      "id": "u65",
      "kind": "call",
      "call": "at(0, 20)"
    },
    {
      "id": "u66",
      "kind": "output",
      "values": "\" \" * 39",
      "newline": false
    },
    {
      "id": "u67",
      "kind": "call",
      "call": "at(0, 22)"
    },
    {
      "id": "u68",
      "kind": "output",
      "values": "\" \" * 39",
      "newline": false
    },
    {
      "id": "u69",
      "kind": "if",
      "condition": "vyhra",
      "then": [
        {
          "id": "u70",
          "kind": "call",
          "call": "color(LIGHT_GREEN)"
        },
        {
          "id": "u71",
          "kind": "call",
          "call": "at(0, 20)"
        },
        {
          "id": "u72",
          "kind": "output",
          "values": "\"Uhodl jsi kód na \" + str(pokus) + \". pokus!\"",
          "newline": false
        }
      ],
      "else": [
        {
          "id": "u73",
          "kind": "call",
          "call": "color(LIGHT_RED)"
        },
        {
          "id": "u74",
          "kind": "call",
          "call": "at(0, 20)"
        },
        {
          "id": "u75",
          "kind": "output",
          "values": "\"Došly pokusy. Kód:\"",
          "newline": false
        }
      ]
    },
    {
      "id": "u76",
      "kind": "for",
      "variable": "i",
      "range": "4",
      "body": [
        {
          "id": "u77",
          "kind": "call",
          "call": "color(barvy[kod[i] - 1])"
        },
        {
          "id": "u78",
          "kind": "call",
          "call": "at(24 + i * 2, 20)"
        },
        {
          "id": "u79",
          "kind": "output",
          "values": "\"O\"",
          "newline": false
        }
      ]
    },
    {
      "id": "u80",
      "kind": "call",
      "call": "color(WHITE)"
    },
    {
      "id": "u81",
      "kind": "call",
      "call": "at(0, 22)"
    }
  ],
  "functions": [
    {
      "name": "pocet",
      "params": [
        {
          "name": "seznam",
          "type": "list[int]"
        },
        {
          "name": "c",
          "type": "int"
        }
      ],
      "returnType": "int",
      "blocks": [
        {
          "id": "u1",
          "kind": "declare",
          "name": "n",
          "type": "int",
          "init": "0"
        },
        {
          "id": "u2",
          "kind": "for",
          "variable": "i",
          "range": "len(seznam)",
          "body": [
            {
              "id": "u3",
              "kind": "if",
              "condition": "seznam[i] == c",
              "then": [
                {
                  "id": "u4",
                  "kind": "assign",
                  "target": "n",
                  "value": "n + 1"
                }
              ],
              "else": []
            }
          ]
        },
        {
          "id": "u5",
          "kind": "return",
          "value": "n"
        }
      ],
      "comment": "Kolikrát je barva c v seznamu."
    }
  ],
  "comment": "Řešení úlohy „Na kolikátý pokus“: Po uhodnutí program napíše, na kolikátý pokus se to povedlo."
}
