File size: 1,890 Bytes
2752e5e
 
ac27494
8ea503c
 
ac27494
 
 
5f4fc3b
8ef9f1b
 
 
b98e47a
fdbcf27
d4929d9
fdbcf27
8ef9f1b
fdbcf27
 
 
 
ac27494
0a08d3b
 
40f1b61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16a24f4
40f1b61
ac27494
58902ba
63525c3
58902ba
fdbcf27
63525c3
 
cb70215
c224d5d
 
 
 
 
cd716fe
c224d5d
74695d2
 
 
 
ac27494
2752e5e
fdbcf27
 
 
 
 
ac27494
 
cd716fe
dab6f19
40f1b61
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
import streamlit as st

#Globals
if "legal_numbers" not in st.session_state:
    st.session_state.legal_numbers = [1,2,3,4,5,6,7,8,9]

def get_userInput(): 
    input = st.text_input("Enter a number between 1 to 9: ", key="input")
    return input

def validate_userInput(user_input):
    if user_input.isdigit():
        if int(user_input) < 1 or int(user_input) > 9:
            return False
        else:    
            return True
    else:
        return False

def error_Message(msg):
    st.write(msg)

def display_board(firstRun):  
    if firstRun:
        col1, col2, col3 = st.columns(3)
        col4, col5, col6 = st.columns(3)
        col7, col8, col9 = st.columns(3)
        with col1:
            st.text("X")
        with col2:
           st.text("O")
        with col3:
           st.text("...")
        with col4:
            st.text(" X ")
        with col5:
           st.text(" O ")
        with col6:
           st.text(" ... ")
        with col7:
            st.text(" X ")
        with col8:
           st.text(" O ")
        with col9:
           st.text(" ... ")
 #   else:
        

def reset_legalNumbers():
    st.session_state.legal_numbers = [1,2,3,4,5,6,7,8,9]
    
def update_legalNumbers(number):
    st.session_state.legal_numbers.remove(int(user_input))
    st.write("Legal Numbers: " + "".join(str(st.session_state.legal_numbers)))

#UIApp starts here
st.set_page_config(page_title="Python - Tic Tac Toe", page_icon=":python:")
st.header("Python - Tic Tac Toe")

user_input=get_userInput()
display_board(True)

#UI Buttons
submit=st.button('Submit')
replay=st.button('Replay')

#Button functionality
if submit:
    response=validate_userInput(user_input)
    if response:
        update_legalNumbers(user_input)
    else:
         error_Message("Please enter a digit between 1 to 9.")

if replay:
    display_board(True)
    #reset_legalNumbers()