@4pip/

Boter Kaas en Eieren

Python

Boter Kaas en Eieren

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.928859364590713","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"I2RlZiB0aWNfdGFjX3RvZSB3YXQgbWFnIHdlbAojZGVmIGRyYXcgaGV0IHRla2VuIHZhbiBoZXQgYm9yZAojZGVmIHByb2dyYW1tYSAxIGVlbiBudW1tZXIga2llemVuIDEKI2RlZiBwcm9ncmFtbWEgMiBlZW4gbnVtbWVyIGtpZXplbiAyCiNkZWYgY2hvaWNlIG51bWJlciB0ZXN0ZW4gb3AgZ29lZGUgbnVtbWVyCiNkZWYgY2hlY2sgYm9hcmQsIHRlc3RlbiBvcCBoZXQgYm9yZAojd2hpbGUgbm90IGVuZCwgd2UgZ2FhbiB2ZXJkZXIKI2lmIGVuZCwgbm9nIGVuIGtlZXIKCgpkZWYgYm90ZXJfa2Fhc19laWVyZW4oKToKICAgIHByaW50ICgpCiAgICBwcmludCAoJ0JvdGVyIEthYXMgJiBFaWVyZW4nKQogICAgcHJpbnQgKCkKICAgIGJvYXJkID0gWzEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDldCiAgICBlbmQgPSBGYWxzZQogICAgd2luX2NvbW1iaW5hdGlvbnMgPSAoKDAsIDEsIDIpLCAoMywgNCwgNSksICg2LCA3LCA4KSwgKDAsIDMsIDYpLCAoMSwgNCwgNyksICgyLCA1LCA4KSwgKDAsIDQsIDgpLCAoMiwgNCwgNikpCgogICAgZGVmIGRyYXcoKToKICAgICAgICBwcmludChib2FyZFswXSwgYm9hcmRbMV0sIGJvYXJkWzJdKQogICAgICAgIHByaW50KGJvYXJkWzNdLCBib2FyZFs0XSwgYm9hcmRbNV0pCiAgICAgICAgcHJpbnQoYm9hcmRbNl0sIGJvYXJkWzddLCBib2FyZFs4XSkKICAgICAgICBwcmludCgpCgogICAgZGVmIHAxKCk6CiAgICAgICAgbiA9IGNob29zZV9udW1iZXIoKQogICAgICAgIGlmIGJvYXJkW25dID09ICJYIiBvciBib2FyZFtuXSA9PSAiTyI6CiAgICAgICAgICAgIHByaW50KCJcbkRhdCBtYWcgbmlldCwgbm9nIGVlbiBrZWVyIikKICAgICAgICAgICAgcDEoKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGJvYXJkW25dID0gIlgiCgogICAgZGVmIHAyKCk6CiAgICAgICAgbiA9IGNob29zZV9udW1iZXIoKQogICAgICAgIGlmIGJvYXJkW25dID09ICJYIiBvciBib2FyZFtuXSA9PSAiTyI6CiAgICAgICAgICAgIHByaW50KCJcbkRhdCBtYWcgbmlldCwgbm9nIGVlbiBrZWVyIikKICAgICAgICAgICAgcDIoKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGJvYXJkW25dID0gIk8iCgogICAgZGVmIGNob29zZV9udW1iZXIoKToKICAgICAgICB3aGlsZSBUcnVlOgogICAgICAgICAgICB3aGlsZSBUcnVlOgogICAgICAgICAgICAgICAgYSA9IGlucHV0KCkKICAgICAgICAgICAgICAgIHRyeToKICAgICAgICAgICAgICAgICAgICBhICA9IGludChhKQogICAgICAgICAgICAgICAgICAgIGEgLT0gMQogICAgICAgICAgICAgICAgICAgIGlmIGEgaW4gcmFuZ2UoMCwgOSk6CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBhCiAgICAgICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnQoIlxuRGF0IG1hZyBuaWV0LCBub2cgZWVuIGtlZXIiKQogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZQogICAgICAgICAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6CiAgICAgICAgICAgICAgICAgICBwcmludCgiXG5EYXQgbWFnIG5pZXQsIG5vZyBlZW4ga2VlciIpCiAgICAgICAgICAgICAgICAgICBjb250aW51ZQoKICAgIGRlZiBjaGVja19ib2FyZCgpOgogICAgICAgIGNvdW50ID0gMAogICAgICAgIGZvciBhIGluIHdpbl9jb21tYmluYXRpb25zOgogICAgICAgICAgICBpZiBib2FyZFthWzBdXSA9PSBib2FyZFthWzFdXSA9PSBib2FyZFthWzJdXSA9PSAiWCI6CiAgICAgICAgICAgICAgICBwcmludCgiU3BlbGVyMSB3aW50IVxuIikKICAgICAgICAgICAgICAgIHByaW50KCJHZWZlbGljaXRlZXJkIVxuIikKICAgICAgICAgICAgICAgIHJldHVybiBUcnVlCgogICAgICAgICAgICBpZiBib2FyZFthWzBdXSA9PSBib2FyZFthWzFdXSA9PSBib2FyZFthWzJdXSA9PSAiTyI6CiAgICAgICAgICAgICAgICBwcmludCgiU3BlbGVyIDIgd2ludCFcbiIpCiAgICAgICAgICAgICAgICBwcmludCgiR2VmZWxpY3RpZWVyZCFcbiIpCiAgICAgICAgICAgICAgICByZXR1cm4gVHJ1ZQogICAgICAgIGZvciBhIGluIHJhbmdlKDkpOgogICAgICAgICAgICBpZiBib2FyZFthXSA9PSAiWCIgb3IgYm9hcmRbYV0gPT0gIk8iOgogICAgICAgICAgICAgICAgY291bnQgKz0gMQogICAgICAgICAgICBpZiBjb3VudCA9PSA5OgogICAgICAgICAgICAgICAgcHJpbnQoIkhldCBpcyBnZWxpamtzcGVsXG4iKQogICAgICAgICAgICAgICAgcmV0dXJuIFRydWUKCiAgICB3aGlsZSBub3QgZW5kOgogICAgICAgIGRyYXcoKQogICAgICAgIGVuZCA9IGNoZWNrX2JvYXJkKCkKICAgICAgICBpZiBlbmQgPT0gVHJ1ZToKICAgICAgICAgICAgYnJlYWsKICAgICAgICBwcmludCgiU3BlbGVyIDEgbWFnIGtpZXplbiIpCiAgICAgICAgcDEoKQogICAgICAgIGRyYXcoKQogICAgICAgIGVuZCA9IGNoZWNrX2JvYXJkKCkKICAgICAgICBpZiBlbmQgPT0gVHJ1ZToKICAgICAgICAgICAgYnJlYWsKICAgICAgICBwcmludCgiU3BlbGVyIDIgbWFnIGtpZXplbiIpCiAgICAgICAgcDIoKQoKICAgIGlmIGlucHV0KCJOb2cgZWVuIGtlZXI/IChqL24pXG4iKSA9PSAiaiI6CiAgICAgICAgcHJpbnQoKQogICAgICAgIGJvdGVyX2thYXNfZWllcmVuKCkKCmJvdGVyX2thYXNfZWllcmVuKCk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#def tic_tac_toe wat mag wel
#def draw het teken van het bord
#def programma 1 een nummer kiezen 1
#def programma 2 een nummer kiezen 2
#def choice number testen op goede nummer
#def check board, testen op het bord
#while not end, we gaan verder
#if end, nog en keer


def boter_kaas_eieren():
    print ()
    print ('Boter Kaas & Eieren')
    print ()
    board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    end = False
    win_commbinations = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))

    def draw():
        print(board[0], board[1], board[2])
        print(board[3], board[4], board[5])
        print(board[6], board[7], board[8])
        print()

    def p1():
        n = choose_number()
        if board[n] == "X" or board[n] == "O":
            print("\nDat mag niet, nog een keer")
            p1()
        else:
            board[n] = "X"

    def p2():
        n = choose_number()
        if board[n] == "X" or board[n] == "O":
            print("\nDat mag niet, nog een keer")
            p2()
        else:
            board[n] = "O"

    def choose_number():
        while True:
            while True:
                a = input()
                try:
                    a  = int(a)
                    a -= 1
                    if a in range(0, 9):
                        return a
                    else:
                        print("\nDat mag niet, nog een keer")
                        continue
                except ValueError:
                   print("\nDat mag niet, nog een keer")
                   continue

    def check_board():
        count = 0
        for a in win_commbinations:
            if board[a[0]] == board[a[1]] == board[a[2]] == "X":
                print("Speler1 wint!\n")
                print("Gefeliciteerd!\n")
                return True

            if board[a[0]] == board[a[1]] == board[a[2]] == "O":
                print("Speler 2 wint!\n")
                print("Gefelictieerd!\n")
                return True
        for a in range(9):
            if board[a] == "X" or board[a] == "O":
                count += 1
            if count == 9:
                print("Het is gelijkspel\n")
                return True

    while not end:
        draw()
        end = check_board()
        if end == True:
            break
        print("Speler 1 mag kiezen")
        p1()
        draw()
        end = check_board()
        if end == True:
            break
        print("Speler 2 mag kiezen")
        p2()

    if input("Nog een keer? (j/n)\n") == "j":
        print()
        boter_kaas_eieren()

boter_kaas_eieren()