Facebook
From MEHOW, 3 Years ago, written in Python.
This paste is a reply to TTT from MY - go back
Embed
Viewing differences between TTT and Re: TTT
\n\n
def init_board():
    board = [['.', '.', '.'],
                ['.', '.', '.'],
                ['.', '.', '.']]
    print (board)            
    return board

    
    
def get_move():
    board = init_board()
    round = 5 #wstępnie tutaj umieściłam round
    expected_result = [[0, 0], [0, 1], [0, 2], [
        1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
    move = input("Enter coordinates of choosen blank field(e.g. A1): ")
    round = round-1 #tutaj round - 1, ale nie wiem czy to będzie działać.
    move = move.upper()
    coordinates = []
    x = []
    y = []
    result = []
    
    def spliting():
        for letter in move:
            coordinates.append(letter)
    
    def checking():
        for it in coordinates:
            if it.isalpha() == True:
                if it == "A" or "B" or "C":
                    x.append(it)
            elif it.isnumeric() == True:
                if it == '1' or '2' or '3':
                    y.append(it)
    
    def convert():
        coordinates = []
        for item in x:
            if item == "A":
                result.append(0)
            elif item == "B":
                result.append(1)
            elif item == "C":
                result.append(2)
            elif item != 'A' or 'B' or 'C':
                result.append("err")
        for item in y:
            if item == "1":
                result.append(0)
            elif item == "2":
                result.append(1)
            elif item == "3":
                result.append(2)
            elif item != '1' or '2' or '3':
                result.append("err")
        if x == [] or y == []:
            result.append("err")
    
    def error():
        print("\n")
        coordinates.clear()
        x.clear()
        y.clear()
        result.clear()
        move = input("Enter coordinates of choosen blank field(e.g. A1): ")
        move = move.upper()
        for letter in move:
            coordinates.append(letter)
        checking()
        convert()
        return result
    
    spliting()
    checking()
    convert()
    while True:
        while result in expected_result != True:
            if board[result[0]][result[1]] != '.':
                print("\n")
                print("This place is taken. Choose another empty field :) ")
                print("\n")
                error()
            elif board[result[0]][result[1]] == '.':
                return result
        while result[0] == "err" or result[1] == "err":
            print("\n")
            print("Invalid input. Please enter your choose again :) ")
            print("\n")
            error()
        else:
            while result in expected_result != True:
                if board[result[0]][result[1]] != '.':
                    print("\n")
                    print("This place is taken. Choose another empty field :) ")
                    print("\n")
                    error()
                elif board[result[0]][result[1]] == '.':
                    return result
    
    
# init_board()
# print(get_move())

def mark (round,board) #w odpowiednim miejscu trzeba wstawić round = 5 i round = round - 1, żeby po każdym wyborze miejsca kółka lub krzyżyka odpadała jedna runda
    if round == 5:
        board[result[0]][result[1]] = "0"

    if round == 4:
        board[result[0]][result[1]] = "X"

    if round == 3:
        board[result[0]][result[1]] = "0"

    if round == 2:
    board[result[0]][result[1]] = "X"

    if round == 1:
    board[result[0]][result[1]] = "0"

    if round == 0:
        print ("KONIEC")

    
def has_won():
    board = init_board()
    win = ((board[0][0],board[0][1],board[0][2]),
        (board[1][0],board[1][1],board[1][2]),
        (board[2][0],board[2][1],board[2][2]),
        (board[0][0],board[1][0],board[2][0]),
        (board[0][1],board[1][1],board[2][1]),
        (board[0][2],board[1][2],board[2][2]),
        (board[0][0],board[1][1],board[2][2]),
        (board[2][0],board[1][1],board[0][2]))
    result = False
    for line in win:
        if line[0] == line[1] == line[2] != ".":
            result = True
    return result
  
  
# TEST HAS_WON
# if has_won() == True:
#     print("WYGRANA")

print("WYGRANA")


def is_full():
    board = init_board()
    result = True
    if board[0][0] == '.':
        result = False
    elif board[0][1] == '.':
        result = False
    elif board[0][2] == '.':
        result = False
    elif board[1][1] == '.':
        result = False
    elif board[2][1] == '.':
        result = False
    elif board[1][0] == '.':
        result = False
    elif board[1][2] == '.':
        result = False
    elif board[2][0] == '.':
        result = False
    elif board[2][2] == '.':
        result = False
    return result

# TEST IS FULL   
# board = init_board()
# if is_full() == True:
#     print("pełna")

get_move()