diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..0086366b3a930c37e73b0e2814ddbb8d4b84cea6 --- /dev/null +++ b/app.py @@ -0,0 +1,144 @@ +import streamlit as st +from PIL import Image +import random, operator, ast, sqlite3, datetime, json, math +from itertools import product, permutations +from utils import * +from sqlite3 import Connection +import pandas as pd + +@st.cache_data() +def static_variables(): + suits = ["hearts","spades","diamonds","clubs"]; jo = "_of_"; path = "static/" + return suits, jo, path + +@st.cache_data(ttl=3600*4) +def static_layout_top(): + st.header("24 Game!") + st.markdown(f"""Welcome! Today is {st.session_state.date}""") + + st.markdown(""" + #### How to play: + + - Using +, -, *, / , and () on 4 cards to get 24; + - Each card represent a number as shown, where J=11, Q=12, K=13, and A=1 + - You will have 3 operations, and you have to express the first and second + operation explicitly, e.g. even though you have 6, 6, 6, 6 and you know that + 6 + 6 + 6 + 6 = 24, you need to type your expression clearly as ((6+6)+6)+6 or + (6+6)+(6+6) to specify your first two operations. + - The algorithm encourage thinking of associativity, so, (12/6)*(11+1) and + (12/6)*(1+11) would be counted as two different and correct answers. + + """) + c0, c1, c2, c3 = st.columns([0.25,0.25,0.25,0.25]); cs = [c0,c1,c2,c3] + for idx, x in enumerate(cs): + with x: + im = Image.open(path+str(st.session_state.nums[idx])+jo+st.session_state.su[idx]+".png") + st.image(im) + +@st.cache_resource(ttl=3600*4) +def get_cards(): + i = True + while i: + nums = random.sample(range(1,14),4) + suit = random.sample(suits,4) + sols = solve24(nums) + i = (len(sols) == 0) + conn = get_connection("data24.db"); date = str(datetime.date.today()) + value = (date, str(nums), str(suit), str(sols), len(sols)) + insert_value_games(conn, value) + return nums, suit, sols, date, conn + +def check_ans_default(inp): # for non-id player + if inp in st.session_state.sols: + if st.session_state.get('ans') == None: + st.session_state['ans'] = {inp} + + else: + s1 = st.session_state['ans'] + s1.add(inp) + st.session_state['ans'] = s1 + a1, a2 = st.columns([0.5,0.5]) + with a1: + st.markdown(f"Got one! :green[${inp}=24$]") + with a2: + st.markdown(f"There are {len(st.session_state.sols)} expressions in total. :chart_with_upwards_trend:") + else: + st.write("Oop! Incorrect.....") + return + +def check_ans_user(inp): # On session, but data on cache_resource + id = int(st.session_state.u_id); date = st.session_state.date; + nums = str(st.session_state.nums); suit = str(st.session_state.su) + df = get_plays_answer(st.session_state.conn, id, date, nums) + if len(df) > 0: + st.session_state['ans'] = set(ast.literal_eval(df.values[0][0])) + else: + st.session_state['ans'] = set() + if inp in st.session_state.sols: + s1 = st.session_state['ans'] + if len(s1) > 0: + s1.add(inp) + else: + s1 = {inp} + st.session_state['ans'] = s1 + if st.session_state.u_id is not None: + if not check_plays_user(st.session_state.conn, id, date, nums): + value = (id, date, nums, suit, json.dumps(s1,default=tuple)) + insert_value_plays(st.session_state.conn, value) + else: + update_value_plays(st.session_state.conn, id, date, nums, json.dumps(s1,default=tuple)) + else: + st.write("Oop! Incorrect.....") + + +# Call statics and session variables +suits, jo, path = static_variables() +st.session_state['nums'], st.session_state['su'], st.session_state['sols'], st.session_state['date'], st.session_state['conn'] = get_cards() + + +# Call page layout +#with st.sidebar: +# df = get_top_board(st.session_state.conn) +# df = top_board_df(df) +# st.write(df) + +static_layout_top() + +# User data collecting +#with st.expander("If you want to join the competition"): +# u1, u2 = st.columns([0.5,0.5]) +# with u1: +# st.text_input("Enter your TGS id for prize:", key="u_id") +# with u2: +# st.text_input("The user name, one per TGS id", key="u_name") +# if st.button("Join Weekly Competition"): +# conn = st.session_state.conn; u_id = int(st.session_state.u_id); u_name = st.session_state.u_name +# if check_value_user(conn, u_id): +# st.write("You already joined the competition, good luck! :smile:") +# else: +# insert_value_user(conn, (u_id, u_name)) +# st.write(f"Welcome {u_name}! You just signed up for this week's competition! Good Luck!") + +# User plays collecting +inp = st.text_input("Enter your expression here: ").replace(" ", "") +if st.button("Try your luck!"): + if st.session_state.u_id: + check_ans_user(inp) + else: + check_ans_default(inp) + +#st.write(st.session_state.ans) #-- local testing only +# Display session answers +if st.session_state.get('ans') == None: + pass +else: + st.markdown("### Your correct answers: ") + col = 4; n = len(st.session_state.ans) + row = math.ceil(n / col) + for i in range(row): + cols = st.columns(col) + for m in range(min(4, n-4*i)): + cols[m].latex(list(st.session_state.ans)[m+i*4].replace("/","\div")) + st.markdown("##") + +#st.write(st.session_state.sols) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d42be3bad9e2342c73200c7a3745535bd5e5b1c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +SQLAlchemy==2.0.19 +pandas==1.5.3 +streamlit==1.24.0 +Pillow==9.5.0 diff --git a/static/10_of_clubs.png b/static/10_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..18af741dbd2d8eb0f8ac494065d50ee8b7bc326a Binary files /dev/null and b/static/10_of_clubs.png differ diff --git "a/static/10_of_clubs.png\357\200\272Zone.Identifier" "b/static/10_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/10_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/10_of_diamonds.png b/static/10_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..3bbc4e06bc6042f026761c8c1437a07ad8977c1b Binary files /dev/null and b/static/10_of_diamonds.png differ diff --git "a/static/10_of_diamonds.png\357\200\272Zone.Identifier" "b/static/10_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/10_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/10_of_spades.png b/static/10_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..0b3d29475d9caa3291a68324e87af4790244500c Binary files /dev/null and b/static/10_of_spades.png differ diff --git "a/static/10_of_spades.png\357\200\272Zone.Identifier" "b/static/10_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/10_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/11_of_clubs.png b/static/11_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..5e003be2d4c3fc8e67a0f63979c6b9054cd37fd6 Binary files /dev/null and b/static/11_of_clubs.png differ diff --git a/static/11_of_diamonds.png b/static/11_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..131a97731b51cca6f26dfb295d5937e964d1ebad Binary files /dev/null and b/static/11_of_diamonds.png differ diff --git a/static/11_of_hearts.png b/static/11_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..bf342bcb2963500e8f899222f788fb3e1e08d0ad Binary files /dev/null and b/static/11_of_hearts.png differ diff --git a/static/11_of_spades.png b/static/11_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..f539c19c6cfc002f9edfec34f8dbbd65227e6249 Binary files /dev/null and b/static/11_of_spades.png differ diff --git a/static/12_of_clubs.png b/static/12_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..7be5f9a96a5188a17e3606907d0076497b902958 Binary files /dev/null and b/static/12_of_clubs.png differ diff --git a/static/12_of_spades.png b/static/12_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..7983d034ddb7b54e26e36c9141b048bff003bfc0 Binary files /dev/null and b/static/12_of_spades.png differ diff --git a/static/13_of_clubs.png b/static/13_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..68e57747d7e6d518e438bc1e0b45310abf25cae7 Binary files /dev/null and b/static/13_of_clubs.png differ diff --git a/static/13_of_hearts.png b/static/13_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..1d3c468d8e986a15e38d5fb2b9319b17ff183a4b Binary files /dev/null and b/static/13_of_hearts.png differ diff --git a/static/13_of_spades.png b/static/13_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..2edbbc14848662fb5bcde268d046041a25c193a4 Binary files /dev/null and b/static/13_of_spades.png differ diff --git a/static/1_of_clubs.png b/static/1_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..42bf5ec94d627831e095c53dd5480521f771f97d Binary files /dev/null and b/static/1_of_clubs.png differ diff --git a/static/1_of_diamonds.png b/static/1_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..79cd3b8a8054644e23619008b58f7b89601a2ec6 Binary files /dev/null and b/static/1_of_diamonds.png differ diff --git a/static/2_of_clubs.png b/static/2_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..291ed975f29d7873765c9f3259ebad8fd8a9d040 Binary files /dev/null and b/static/2_of_clubs.png differ diff --git "a/static/2_of_clubs.png\357\200\272Zone.Identifier" "b/static/2_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/2_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/2_of_diamonds.png b/static/2_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..4deee7cc848386b049cafd105cb9a92c8ce2cbcd Binary files /dev/null and b/static/2_of_diamonds.png differ diff --git a/static/2_of_hearts.png b/static/2_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..75a014f364dbbdc00fb4bb8f3f808370f37907b8 Binary files /dev/null and b/static/2_of_hearts.png differ diff --git "a/static/2_of_hearts.png\357\200\272Zone.Identifier" "b/static/2_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/2_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/2_of_spades.png b/static/2_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..1ce0ffe8b82efc672d92c53d1a0261defc1c8824 Binary files /dev/null and b/static/2_of_spades.png differ diff --git "a/static/2_of_spades.png\357\200\272Zone.Identifier" "b/static/2_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/2_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/3_of_diamonds.png b/static/3_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..8ee0b4b902d308d64b51ec880a0389a34f836dd3 Binary files /dev/null and b/static/3_of_diamonds.png differ diff --git a/static/3_of_hearts.png b/static/3_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..8e74673f8222007b4b8a8c82d00d10a782ec7031 Binary files /dev/null and b/static/3_of_hearts.png differ diff --git "a/static/3_of_hearts.png\357\200\272Zone.Identifier" "b/static/3_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/3_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/3_of_spades.png b/static/3_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..f9e06b4f019efca9dc2011b755404453b5928349 Binary files /dev/null and b/static/3_of_spades.png differ diff --git "a/static/3_of_spades.png\357\200\272Zone.Identifier" "b/static/3_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/3_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/4_of_clubs.png b/static/4_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..8be9e089225fdf93c7be1b51031819fc85054c73 Binary files /dev/null and b/static/4_of_clubs.png differ diff --git "a/static/4_of_clubs.png\357\200\272Zone.Identifier" "b/static/4_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/4_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/4_of_diamonds.png b/static/4_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..70e82e839b4e29647a5e2fefd7b08f4ca30829f1 Binary files /dev/null and b/static/4_of_diamonds.png differ diff --git a/static/4_of_hearts.png b/static/4_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..ceecbfe02f2e1e0af4a64dc457ed46940f954c81 Binary files /dev/null and b/static/4_of_hearts.png differ diff --git "a/static/4_of_hearts.png\357\200\272Zone.Identifier" "b/static/4_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/4_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/4_of_spades.png\357\200\272Zone.Identifier" "b/static/4_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/4_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/5_of_clubs.png b/static/5_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..bde9777696e8e8d42402bdeeb6058b7d6605d0a0 Binary files /dev/null and b/static/5_of_clubs.png differ diff --git "a/static/5_of_clubs.png\357\200\272Zone.Identifier" "b/static/5_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/5_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/5_of_diamonds.png b/static/5_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..bb9252558a0c6a0b3f6b4756e9d1a1c54c43fdb4 Binary files /dev/null and b/static/5_of_diamonds.png differ diff --git "a/static/5_of_diamonds.png\357\200\272Zone.Identifier" "b/static/5_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/5_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/5_of_hearts.png b/static/5_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..d923456fe88b17c1ab8d45f11b8d947957732a6c Binary files /dev/null and b/static/5_of_hearts.png differ diff --git "a/static/5_of_hearts.png\357\200\272Zone.Identifier" "b/static/5_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/5_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/5_of_spades.png b/static/5_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..53a1aad26c9990b695ed24c1241843eef0a704f0 Binary files /dev/null and b/static/5_of_spades.png differ diff --git "a/static/5_of_spades.png\357\200\272Zone.Identifier" "b/static/5_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/5_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/6_of_clubs.png b/static/6_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..a9660a037257ac7d6ab05604fe896b2e51ac4171 Binary files /dev/null and b/static/6_of_clubs.png differ diff --git "a/static/6_of_clubs.png\357\200\272Zone.Identifier" "b/static/6_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/6_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/6_of_diamonds.png b/static/6_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..78a80ad06a3705f9035bf3b96a1f047c428ac877 Binary files /dev/null and b/static/6_of_diamonds.png differ diff --git "a/static/6_of_diamonds.png\357\200\272Zone.Identifier" "b/static/6_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/6_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/6_of_hearts.png b/static/6_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..361643efc36ed607f3834a502840b858dc0498d9 Binary files /dev/null and b/static/6_of_hearts.png differ diff --git a/static/6_of_spades.png b/static/6_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..40242a718bfbec2252610f21196eaacdb9446884 Binary files /dev/null and b/static/6_of_spades.png differ diff --git "a/static/6_of_spades.png\357\200\272Zone.Identifier" "b/static/6_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/6_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/7_of_clubs.png b/static/7_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..9d6b54554f5792e0bbef4c2fa3fd898cb6354b6f Binary files /dev/null and b/static/7_of_clubs.png differ diff --git "a/static/7_of_clubs.png\357\200\272Zone.Identifier" "b/static/7_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/7_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/7_of_diamonds.png b/static/7_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..6ad5f15b51e7b949c825f6ecf1d70a6ba6c8f9ec Binary files /dev/null and b/static/7_of_diamonds.png differ diff --git "a/static/7_of_diamonds.png\357\200\272Zone.Identifier" "b/static/7_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/7_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/7_of_hearts.png b/static/7_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..19b89a2e7e8511b44f824f19172059a0b0bae7a4 Binary files /dev/null and b/static/7_of_hearts.png differ diff --git "a/static/7_of_hearts.png\357\200\272Zone.Identifier" "b/static/7_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/7_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/7_of_spades.png b/static/7_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..b9f1b93d33e8c81a441df99c3da822631d202c50 Binary files /dev/null and b/static/7_of_spades.png differ diff --git a/static/8_of_clubs.png b/static/8_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..cec743cbcd188453a8c14edde55147683ae24859 Binary files /dev/null and b/static/8_of_clubs.png differ diff --git a/static/8_of_diamonds.png b/static/8_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..ed1295121de438df71dfed44026046a34ec959ba Binary files /dev/null and b/static/8_of_diamonds.png differ diff --git "a/static/8_of_diamonds.png\357\200\272Zone.Identifier" "b/static/8_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/8_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/8_of_hearts.png b/static/8_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..fb39723cb19cff1271bee430875a3c0d6d570e99 Binary files /dev/null and b/static/8_of_hearts.png differ diff --git a/static/8_of_spades.png b/static/8_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..b6b3b3813dce1260129d482550dbfdd465fca085 Binary files /dev/null and b/static/8_of_spades.png differ diff --git a/static/9_of_clubs.png b/static/9_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..2174db58e12a0cef03c8f68cfdad9e296f5b31b9 Binary files /dev/null and b/static/9_of_clubs.png differ diff --git a/static/9_of_diamonds.png b/static/9_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..0b933fb0e664b980d3f2668443922062eb083cec Binary files /dev/null and b/static/9_of_diamonds.png differ diff --git a/static/9_of_hearts.png b/static/9_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..7b196d6dc080409b1e7ae97f6bf1e651742fb0ff Binary files /dev/null and b/static/9_of_hearts.png differ diff --git "a/static/9_of_hearts.png\357\200\272Zone.Identifier" "b/static/9_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/9_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/ace_of_clubs.png\357\200\272Zone.Identifier" "b/static/ace_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/ace_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/ace_of_diamonds.png\357\200\272Zone.Identifier" "b/static/ace_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/ace_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/ace_of_spades2.png b/static/ace_of_spades2.png new file mode 100644 index 0000000000000000000000000000000000000000..fbc3a2dcad00d5ce42aa35839e1f0c57f11d5511 Binary files /dev/null and b/static/ace_of_spades2.png differ diff --git "a/static/ace_of_spades2.png\357\200\272Zone.Identifier" "b/static/ace_of_spades2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/ace_of_spades2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/black_joker.png b/static/black_joker.png new file mode 100644 index 0000000000000000000000000000000000000000..000b640bff459b7c6b7f3c319618bf74fba24194 Binary files /dev/null and b/static/black_joker.png differ diff --git "a/static/jack_of_clubs2.png\357\200\272Zone.Identifier" "b/static/jack_of_clubs2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/jack_of_clubs2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/jack_of_diamonds.png b/static/jack_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..0494785163ee9ee0c4ae2fce8f766893123f2290 Binary files /dev/null and b/static/jack_of_diamonds.png differ diff --git "a/static/jack_of_diamonds2.png\357\200\272Zone.Identifier" "b/static/jack_of_diamonds2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/jack_of_diamonds2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/jack_of_hearts.png b/static/jack_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..03cdfd473cf24c4924f8923548f674a136dee003 Binary files /dev/null and b/static/jack_of_hearts.png differ diff --git "a/static/jack_of_hearts.png\357\200\272Zone.Identifier" "b/static/jack_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/jack_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/jack_of_hearts2.png\357\200\272Zone.Identifier" "b/static/jack_of_hearts2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/jack_of_hearts2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/jack_of_spades.png b/static/jack_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..734e4b173698421021feba0737ff420bd5957a8c Binary files /dev/null and b/static/jack_of_spades.png differ diff --git "a/static/jack_of_spades2.png\357\200\272Zone.Identifier" "b/static/jack_of_spades2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/jack_of_spades2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/king_of_clubs.png b/static/king_of_clubs.png new file mode 100644 index 0000000000000000000000000000000000000000..ebde974ab422c88e324cee3dd98f996c86075561 Binary files /dev/null and b/static/king_of_clubs.png differ diff --git "a/static/king_of_clubs.png\357\200\272Zone.Identifier" "b/static/king_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/king_of_clubs2.png\357\200\272Zone.Identifier" "b/static/king_of_clubs2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_clubs2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/king_of_diamonds.png b/static/king_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..4c9aaf20daf0d9e6f3e47a3f07d7c31f8b0f5725 Binary files /dev/null and b/static/king_of_diamonds.png differ diff --git "a/static/king_of_diamonds.png\357\200\272Zone.Identifier" "b/static/king_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/king_of_diamonds2.png\357\200\272Zone.Identifier" "b/static/king_of_diamonds2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_diamonds2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/king_of_hearts.png b/static/king_of_hearts.png new file mode 100644 index 0000000000000000000000000000000000000000..27d235a34f8be3f00973dbc2758d44028cfb15d1 Binary files /dev/null and b/static/king_of_hearts.png differ diff --git "a/static/king_of_hearts.png\357\200\272Zone.Identifier" "b/static/king_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/king_of_spades.png b/static/king_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..b7abc52ac0ba5ac0e0d40b04a8bdc2898f6e7889 Binary files /dev/null and b/static/king_of_spades.png differ diff --git "a/static/king_of_spades.png\357\200\272Zone.Identifier" "b/static/king_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/king_of_spades2.png\357\200\272Zone.Identifier" "b/static/king_of_spades2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/king_of_spades2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/queen_of_clubs.png\357\200\272Zone.Identifier" "b/static/queen_of_clubs.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_clubs.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/queen_of_clubs2.png\357\200\272Zone.Identifier" "b/static/queen_of_clubs2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_clubs2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/queen_of_diamonds.png b/static/queen_of_diamonds.png new file mode 100644 index 0000000000000000000000000000000000000000..791b273df3aac02ed9e6e425933bab267b51d4f6 Binary files /dev/null and b/static/queen_of_diamonds.png differ diff --git "a/static/queen_of_diamonds.png\357\200\272Zone.Identifier" "b/static/queen_of_diamonds.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_diamonds.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/queen_of_hearts.png\357\200\272Zone.Identifier" "b/static/queen_of_hearts.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_hearts.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git "a/static/queen_of_hearts2.png\357\200\272Zone.Identifier" "b/static/queen_of_hearts2.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_hearts2.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/queen_of_spades.png b/static/queen_of_spades.png new file mode 100644 index 0000000000000000000000000000000000000000..c6c69cac15e3bd155e497bf77c2498d9f4568c26 Binary files /dev/null and b/static/queen_of_spades.png differ diff --git "a/static/queen_of_spades.png\357\200\272Zone.Identifier" "b/static/queen_of_spades.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/queen_of_spades.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/static/red_joker.png b/static/red_joker.png new file mode 100644 index 0000000000000000000000000000000000000000..55b3ef9ba552b0be07dcadfae5830a28561408f3 Binary files /dev/null and b/static/red_joker.png differ diff --git "a/static/red_joker.png\357\200\272Zone.Identifier" "b/static/red_joker.png\357\200\272Zone.Identifier" new file mode 100644 index 0000000000000000000000000000000000000000..114de44b05a3d02d6a81740c700af62be278b03f --- /dev/null +++ "b/static/red_joker.png\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\tgs\aiclub\PNG-cards-1.3.zip diff --git a/utils.py b/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..1079d3dcfa6870164142fbd3666de518fc83d5d8 --- /dev/null +++ b/utils.py @@ -0,0 +1,105 @@ +# utils.py +import operator +from itertools import product, permutations +import ast +import sqlite3 +from sqlite3 import Connection +import pandas as pd +import datetime + +def mydiv(n, d): + if d==0: + r = 99999 + else: + r = operator.truediv(n,d) + return r + +def solve24(nums): + syms = [operator.add, operator.sub, operator.mul, mydiv] + op = {sym: ch for sym, ch in zip(syms, '+-*/')} + sols = []; + for x, y, z in product(syms, repeat=3): + for a, b, c, d in permutations(nums): + if round(x(y(a,b),z(c,d)),5) == 24: + sols.append(f"({a}{op[y]}{b}){op[x]}({c}{op[z]}{d})") + if round(x(a,y(b,z(c,d))),5) == 24: + sols.append(f"{a}{op[x]}({b}{op[y]}({c}{op[z]}{d}))") + if round(x(y(z(c,d),b),a),5) == 24: + sols.append(f"(({c}{op[z]}{d}){op[y]}{b}){op[x]}{a}") + if round(x(y(b,z(c,d)),a),5) == 24: + sols.append(f"({b}{op[y]}({c}{op[z]}{d})){op[x]}{a}") + if round(x(a,y(z(c,d),b)),5) == 24: + sols.append(f"{a}{op[x]}(({c}{op[z]}{d}){op[y]}{b})") + + return sols + +def check_extra(sol): + if eval(sol) == 24 and sol.count(")")==2: + return True + else: + return False + +def get_connection(path: str): + return sqlite3.connect(path, check_same_thread=False) + +def insert_value_user (conn, value:tuple): + q = f"INSERT INTO user (id, name) VALUES {value}" + conn.execute(q) + conn.commit() + +def check_value_user (conn, id:int): + q = f"SELECT EXISTS(SELECT 1 FROM user WHERE id={id}) LIMIT 1;" + return pd.read_sql(q, con=conn).values[0][0] == 1 + +def insert_value_games (conn, value:tuple): + q = f"INSERT OR IGNORE INTO games (date, num, suit, sols, num_sols) VALUES {value}" + conn.execute(q) + conn.commit() + +def insert_value_plays (conn, value:tuple): + q = f"INSERT INTO plays (id, date, num, suit, sol) VALUES {value}" + conn.execute(q) + conn.commit() + +def update_value_plays(conn, id, date, num, value): + q = f""" + UPDATE plays + SET sol = '{value}' + WHERE id = {id} + AND date='{date}' + AND num='{num}' + ; + """ + conn.execute(q) + conn.commit() + +def check_plays_user (conn, id, date, num): + q = f"SELECT EXISTS(SELECT 1 FROM plays WHERE id={id} AND date = '{date}' AND num = '{num}') LIMIT 1;" + return pd.read_sql(q, con=conn).values[0][0] == 1 + +def get_plays_answer(conn, id, date, num): + q = f""" + SELECT sol + FROM plays + WHERE id = {id} + AND date = '{date}' + and num = '{num}'; + """ + return pd.read_sql(q, con=conn) + +def get_top_board(conn): + q = """ + SELECT plays.sol as ans, + plays.date as Date, + user.name as name + FROM plays + INNER JOIN user ON plays.id = user.id + ; + """ + return pd.read_sql(q, con=conn) + +def top_board_df(df): + df['scores'] = df.ans.apply(ast.literal_eval).apply(len) + new = df.groupby('name')['scores'].sum().reset_index() + return new.head(10) +