game

PHOTO EMBED

Sat Nov 26 2022 20:20:26 GMT+0000 (Coordinated Universal Time)

Saved by @yousef #python

def diagonal_word() :
    word = words_arr[random.randint(0,23)]
    i_first = random.randint(0,arr_rows-3)
    i = i_first
    j = random.randint(0,arr_columns-3)
    element_occupied = False
    for k in range(0,len(word)):
        if (i - k + len(word) - 1 > arr_rows - 1) or (j - k + len(word) - 1 > arr_columns - 1):
            element_occupied = True
            break
        if ((arr[i][j] != " ")&(arr[i][j] != word[k])):
            element_occupied = True
            i -= k
            j -= k
            break
        i += 1
        j += 1
        if k == len(word) - 1:
            i -= k + 1
            j -= k + 1
    if element_occupied == False:
        for k in range(0,len(word)):
            arr[i][j] = word[k]
            i += 1
            j += 1
            if k == len(word) - 1:
                i -= k + 1
                j -= k + 1
        for k in range(0,len(word)):
            hidden_words_arr[i][j] = word[k]
            i += 1
            j += 1
        return i - k - 1
    else :
        return diagonal_word()
def horizontal_word(count,index):
    count += 1
    if count == 950 :
        return -1
    word = words_arr[random.randint(0,162)]
    if check_word(word) == True or arr[i][3] != " " or arr[i][6] != " ":
        return horizontal_word(count,index)
    i_first = random.randint(1,arr_rows-2)
    i = i_first
    j = random.randint(0,arr_columns-5)
    element_occupied = False
    for k in range(0,len(word)):
        if (j - k + len(word) - 1) > (arr_columns - 1):
            element_occupied = True
            break
        #print(element_occupied)
        if ((arr[i][j] != " ")&(arr[i][j] != word[k])):
            element_occupied = True
            j -= k
            break
        #print(element_occupied)
        j += 1
        if k == len(word) - 1:
            j -= k + 1
    if element_occupied == False:
        for k in range(0,len(word)):
            arr[i][j] = word[k]
            j += 1
            if k == len(word) - 1:
                j -= k + 1
        for k in range(0,len(word)):
            hidden_horizontal_words_arr[i][j] = word[k]
            j += 1
        arr1[index] = word
        return count
    else :
        return horizontal_word(count,index) 
def vertical_word(count,index):
    count += 1 
    if count == 950:
        return -1
    word = words_arr[random.randint(0,162)]
    if check_word(word) == True:
        return vertical_word(count,index)
    i_first = random.randint(0,arr_rows - 5)
    i = i_first
    j = random.randint(1,arr_columns - 2)
    element_occupied = False
    for k in range(0,len(word)):
        if (i - k + len(word) - 1 > arr_rows-1) :
            element_occupied = True
            break
        if ((arr[i][j] != " ")&(arr[i][j] != word[k])):
            element_occupied = True
            i -= k
            break
        if 1:
            i += 1
        if k == len(word) - 1:
           i -= k + 1
    if element_occupied == False:
        for k in range(0,len(word)):
            arr[i][j] = word[k]
            i += 1
            if k == len(word) - 1:
                i -= k + 1
        for k in range(0,len(word)):
            hidden_vertical_words_arr[i][j] = word[k]
            i += 1
        arr1[index] = word
        return count
    else :
        return vertical_word(count,index)   
def clear_array():
    for i in range(0,arr_rows):
        for j in range(0,arr_columns):
            arr[i][j] = " "
    for i in range(0,arr_rows):
        for j in range(0,arr_columns):
            hidden_horizontal_words_arr[i][j] = " "
    for i in range(0,arr_rows):
        for j in range(0,arr_columns):
            hidden_vertical_words_arr[i][j] = " "
def complete_array():
    for i in range(0,arr_rows):
        for j in range(0,arr_columns):
            if arr[i][j] == " ":
                arr[i][j] = letters_arr[random.randint(0,25)]
def check_word(word):
    check_word_arr = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
    for i in range(0,arr_rows):
        check_word_arr[i] = arr[i][0]
        for j in range(1,arr_columns):
            check_word_arr[i] += arr[i][j]
    for j in range(0,arr_rows):
        check_word_arr[arr_rows + j] += arr[0][j]
        for i in range(1,arr_columns):
            check_word_arr[arr_rows + j] += arr[i][j]
    for i in range(0,arr_rows + arr_columns):
        if word in check_word_arr[i] :
            return True
    return False
import random
import time
letters_arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
#words_arr = ['apple','chair','company','elevator','television','summer','price','garden','phone','car','ice','desk','cake','board','bus']
#words_arr = ['autumn', 'bathroom', 'body', 'christmas', 'clothes', 'colour', 'food', 'fruits', 'furniture', 'pets', 'school', 'sport', 'spring', 'town', 'toys', 'balloons', 'banana', 'bank', 'basket', 'basketball', 'bat', 'bath', 'bed', 'bee']
#words_arr = ['Lewandowski', 'shed', 'tears', 'after', 'scoring', 'in', 'the', '82nd', 'minute.', 'He', 'raced', 'toward', 'the', 'corner', 'with', 'his', 'arms', 'outstretched,', 'then', 'stayed', 'slumped', 'on', 'the', 'field', 'as', 'teammates', 'rushed', 'to', 'congratulate', 'him.', 'He', 'got', 'up,', 'rubbed', 'his', 'face,', 'and', 'blew', 'a', 'kiss', 'to', 'the', 'crowd.', 'Today', 'everything', 'I', 'had', 'inside,', 'the', 'dreams,', 'the', 'importance', 'of', 'the', 'occasion,', 'all', 'those', 'dreams', 'from', 'my', 'childhood', 'came', 'through,', 'Lewandowski', 'said.', 'It', 'was', 'so', "significant.''One", 'of', 'the', 'best', 'forwards', 'in', 'the', 'world,', "Lewandowski's", 'barren', 'streak', 'at', 'the', 'World', 'Cup', 'was', 'somewhat', 'puzzling.', 'Now,', 'in', 'his', 'fifth', 'match', 'at', 'the', 'tournament,', "it's", 'over.', 'I', 'always', 'wanted', 'to', 'score', 'at', 'the', 'World', 'Cup', 'and', 'this', 'dream', 'came', "true,''", 'said', 'Lewandowski,', 'who', 'had', 'a', 'penalty', 'saved', 'in', "Poland's", '0-0', 'draw', 'with', 'Mexico', 'on', 'Tuesday.', "``It's", 'not', 'easy,', 'because', 'we', "didn't", 'have', 'many', 'opportunities', 'in', 'the', 'first', 'match', 'and', 'I', 'missed', 'that', "penalty.''Against", 'Saudi', 'Arabia,', 'Lewandowski', 'also', 'set', 'up', 'the', 'opener', 'in', 'the', '40th', 'minute', 'when', 'he', 'kept', 'the', 'ball', 'in', 'play', 'after', 'goalkeeper', 'Mohammed', "Al-Owais'", 'initial', 'block,', 'then', 'laid', 'it', 'back', 'for', 'Piotr', 'Zielinski', 'to', 'knock', 'in.', 'Lewandowski,', 'who', 'had', 'no', 'involvement', 'in', 'any', 'goals', 'in', 'his', 'first', 'four', 'World', 'Cup', 'games,', 'also', 'hit', 'the', 'post,', 'and', 'Al-Owais', 'later', 'denied', 'the', 'Barcelona', 'player', 'from', 'scoring', 'another', 'goal', 'toward', 'the', 'end', 'of', 'the', 'match.', 'It', 'was', 'the', 'one', 'that', 'went', 'in', 'that', 'brought', 'tears', 'to', 'the', '34-year-old', "striker's", 'eyes.', 'The', 'older', 'I', 'get,', 'the', 'more', 'emotional', 'I', "get,''", 'Lewandowski', 'said,', 'referring', 'to', 'his', 'reaction', 'after', 'finally', 'scoring.', "``I'm", 'aware', 'that', 'when', 'it', 'comes', 'to', 'the', 'World', 'Cup,', 'that', 'this', 'might', 'be', 'my', 'last', 'World', 'Cup.', 'And', 'I', 'wanted', 'to', 'underline', 'that', 'I', 'played', 'at', 'World', 'Cups', 'and', 'I', "scored.''Poland", 'coach', 'Czeslaw', 'Michniewicz', 'said', 'he', "wasn't", 'surprised', 'by', "Lewandowski's", 'moving', 'reaction.', 'I', 'know', 'how', 'deeply', 'he', 'lived', 'the', 'last', "match,''", 'Michniewicz', 'said.', "``I'm", 'very', 'sorry', 'he', "wasn't", 'lucky', 'enough,', 'he', 'hit', 'the', 'post', 'and', 'the', 'goalkeeper', 'made', 'a', 'save.', 'He', 'could', 'have', 'had', 'a', 'hat', 'trick', "today.''Poland", 'was', 'scrambling', 'for', 'long', 'periods', 'at', 'the', 'Education', 'City', 'Stadium', 'as', 'the', 'Saudi', 'team', 'was', 'pushed', 'forward', 'by', 'enthusiastic', 'fans', 'in', 'what', 'seemed', 'like', 'a', 'home', 'game.', 'The', 'frustration', 'was', 'clear', 'on', "Lewandowski's", 'face', 'as', "Poland's", 'yellow', 'cards', 'mounted.', 'Saudi', 'Arabia', 'had', 'a', 'chance', 'to', 'equalize', 'at', 'the', 'end', 'of', 'the', 'first', 'half', 'but', 'Poland', 'goalkeeper', 'Wojciech', 'Szczesny', 'saved', 'Salem', "Al-Dawsari's", 'penalty', 'kick.', 'He', 'then', 'blocked', 'Mohammed', "Al-Burayk's", 'shot', 'from', 'the', 'rebound.']
words_arr = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina', 'Faso', 'Burundi', 'Cabo', 'Cambodia', 'Cameroon', 'Canada', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo', 'Croatia', 'Cuba', 'Cyprus', 'Czech', 'Republic', 'Denmark', 'Djibouti', 'Dominica', 'Ecuador', 'Egypt', 'Salvador', 'Eritrea', 'Estonia', 'Eswatini', 'Ethiopia', 'Fiji', 'Finland', 'France', 'Gabon', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', 'Guinea', 'Guyana', 'Haiti', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Mauritania', 'Mauritius', 'Mexico', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', 'Romania', 'Russia', 'Rwanda', 'Samoa', 'Senegal', 'Serbia', 'Seychelles', 'Singapore', 'Slovakia', 'Slovenia', 'Somalia', 'Spain', 'Sudan', 'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tonga', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe']
arr1 = [' ' , ' ' , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " "]
word1 = "word1"
word2 = "word2"
word3 = "word3"
score = 0
print("spot the hidden words\n\n")

arr = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']]
hidden_vertical_words_arr = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']]
hidden_horizontal_words_arr = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']]
arr_rows = 7
arr_columns = 7
count = 0
player_answers = "right"
while (1):
    i_indices = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for i in range(0,6) :
        random_number = random.randint(1,2)
        count = 0
        if random_number == 0 :
            count = diagonal_word()
        #elif random_number == 1 :
        if i%2 == 0:
            count = vertical_word(count,i)
        else :
            count = horizontal_word(count,i)
        if count == -1 :
            clear_array()
            break
        #print(count)
        #print(count , " ", end = "")
    if count == -1 :
        continue 
    #else :
        #print(" ")
        #print("array completed")
    #complete_array()
    c = 1
    print(" "," "," ",end = "")
    for i in range(0,arr_columns):
        if (hidden_vertical_words_arr[3][i] != " " or hidden_vertical_words_arr[6][i] != " "):
            print(c," ",end = "")
            c += 1
        else :
            print(" "," ",end = "")
    print()
    print(" "," "," ",end = "")
    for i in range(0,arr_columns):
        if (hidden_vertical_words_arr[3][i] != " " or hidden_vertical_words_arr[6][i] != " "):
            print("v"," ",end = "")
        else :
            print(" "," ",end = "")
    print()
    for i in range(0,arr_rows):
        if (hidden_horizontal_words_arr[i][3] != " " or hidden_horizontal_words_arr[6][i] != " "):
            print(c,">"," ",end = "")
            c += 1
        else :
            print(" "," "," ",end = "")
        for j in range(0,arr_columns):
            if arr[i][j] == " " :
                print(arr[i][j]," ",end = "")
            else:
                print("_"," ",end = "")
        print()
    print()
    begin_time = time.time()
    for i in range(0,6):
        word = print()
    if (time.time() - begin_time < 1 and player_answers == "right"):
        score += 4
        print(" ")
        print("   ")
        print()
    else:
        print(f"your score is {score}")
        print("hidden words were:\n\n")
        for i in range(0,arr_rows):
            for j in range(0,arr_columns):
                print(arr[i][j]," ",end = "")
            print()
        print(arr1)
        player_answers = "right"
        break
    clear_array()
content_copyCOPY

https://www.programiz.com/python-programming/online-compiler/