From f39ab522dc01d031f3cf9a7eb597bfa5cd3494f2 Mon Sep 17 00:00:00 2001
From: Tamazouzt AIT ELDJOUDI <tamazouzt.ait-eldjoudi@etu.univ-amu.fr>
Date: Mon, 27 Jun 2022 13:18:50 +0200
Subject: [PATCH] added arithmetic expressions to app functions and main

---
 app_functions.py |   6 ++-
 image_maker.py   |   4 +-
 logic.py         |   7 +--
 main.py          | 120 ++++++++++++++++++++++++++++++++++-------------
 4 files changed, 97 insertions(+), 40 deletions(-)

diff --git a/app_functions.py b/app_functions.py
index d531f84..3fabad7 100644
--- a/app_functions.py
+++ b/app_functions.py
@@ -25,6 +25,7 @@ SUB= new_abs(x,new_abs(y,new_app(new_app(y,PRED),x)))
 AND= new_abs(x,new_abs(y,new_app(new_app(x,y),FALSE)))
 OR= new_abs(x,new_abs(y,new_app(new_app(x,TRUE),y)))
 NOT = new_abs(x,new_abs(y,new_abs(z, new_app(new_app(x,z),y))))
+XOR= new_abs(x,new_abs(y,new_app(new_app(x,new_app(new_app(y,FALSE),TRUE)),y)))
 
 
 #definition des entiers de church
@@ -68,4 +69,7 @@ def dec_to_lambda_relative_integers(number):
 #      return beta_reduction_totale(new_app(IS_ZERO,n),None,False)
 
 #def predec(n):#done
-#     return beta_reduction_totale(new_app(PRED, n),None,True)
\ No newline at end of file
+#     return beta_reduction_totale(new_app(PRED, n),None,True)
+
+#print(to_string(beta_reduction_totale(new_app(new_app(XOR,TRUE),FALSE),None,False)))
+#print(to_string(dec_to_lambda_relative_integers(5)))
\ No newline at end of file
diff --git a/image_maker.py b/image_maker.py
index e3be561..d615153 100644
--- a/image_maker.py
+++ b/image_maker.py
@@ -21,8 +21,8 @@ def color_image(img,color):
 
 def new_color():  
     for i in range(3):
-        r = random.randint(0,255)
-        g = random.randint(0,255)
+        r = random.randint(0,255) 
+        g = random.randint(0,255) 
         b = random.randint(0,255)
     return (r,g,b)
 
diff --git a/logic.py b/logic.py
index b707552..81d28af 100644
--- a/logic.py
+++ b/logic.py
@@ -210,14 +210,11 @@ def captureImage(terme, path, counter=True, date= True):
 
 
 def beta_reduction_totale(terme, path, saveImages=True):
-    save_image_choice = input("Voulez vous sauvegarder les images (y/n)?  ")
-    while save_image_choice not in ["y","n"]:
-        save_image_choice = input("Voulez vous sauvegarder les images (y/n)?  ")
-    if save_image_choice == "n":
+    if saveImages==False:
         if beta_reduction(terme) != None:
             return beta_reduction_totale(beta_reduction(terme), path, False)
         return (terme)
-    elif save_image_choice == "y":
+    else:
         if path == None:
             captureImage(terme, None)
         else:
diff --git a/main.py b/main.py
index 00a3b93..4f6bcc5 100644
--- a/main.py
+++ b/main.py
@@ -17,7 +17,8 @@ main_menu_options = {
     2: 'Interactive Beta-Reduction',
     3: 'Arithmetic Operations',
     4: 'Show Numbers',
-    5: 'Exit',
+    5: 'boolean expression',
+    6: 'Exit',
 }
 
 arithmetic_operations_options = {
@@ -35,15 +36,16 @@ choice_number_representation= {
     2: 'Relative numbers',
     3: 'Back'
 }
-#vide un repertoire
-def delete_images(path):
-    for file in os.listdir(path):
-        file_path = os.path.join(path, file)
-        try:
-            if os.path.isfile(file_path):
-                os.unlink(file_path)
-        except Exception as e:
-            print(e)
+
+boolean_representation= {
+    1: 'NOT',
+    2: 'AND',
+    3: 'OR',
+    4: 'XOR',
+    5: 'IS_ZERO',
+    6: 'back'
+
+}
 
 def return_main_menu():
     not_pressed = True
@@ -68,7 +70,13 @@ def run_beta_reduction_totale(terme,path='beta_reduction_totale'):
     os.makedirs(path, exist_ok=True)# cree le rep si il existe pas, le vide si non
     if len(os.listdir(path)) > 0:
         logic.image_counter = 0
-    logic.beta_reduction_totale(terme,path)
+    t=logic.beta_reduction_totale(terme,path)
+    save_image_choice = input('Do you want to save the image? (y/n): ')
+    while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+    if save_image_choice == 'y':
+            logic.captureImage(terme,path)
+
 
 def run_beta_reduction_interactive_totale(terme,path='beta_reduction_interactive_totale'):
     terme = parsing.parseTerm(terme)
@@ -108,6 +116,64 @@ def run_show_numbers(path):
             logic.captureImage(t,path,'ENTIER-RELATIF-'+str(terme),False)
     elif choice==3:
         run_main_menu()
+
+def run_boolean_expression(path):
+    os.makedirs(path, exist_ok=True)
+    print_menu(boolean_representation)
+    choice = int(input("enter your choice : "))
+    while choice not in boolean_representation:
+        clear()
+        print_menu(boolean_representation)
+        choice = int(input('Invalid choice. Enter your choice: '))
+    if choice ==1:
+        clear()
+        t = app_functions.NOT
+        print('Voici le terme:',logic.to_string(t))
+        save_image_choice = input('Do you want to save the image? (y/n): ')
+        while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+        if save_image_choice == 'y':
+            logic.captureImage(t,path,'NOT',False)
+    elif choice==2:
+        clear()
+        t = app_functions.AND
+        print('Voici le terme:',logic.to_string(t))
+        save_image_choice = input('Do you want to save the image? (y/n): ')
+        while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+        if save_image_choice == 'y':
+            logic.captureImage(t,path,'AND',False)
+    elif choice==3:
+        clear()
+        t = app_functions.OR
+        print('Voici le terme:',logic.to_string(t))
+        save_image_choice = input('Do you want to save the image? (y/n): ')
+        while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+        if save_image_choice == 'y':
+            logic.captureImage(t,path,'OR',False)
+    elif choice ==4:
+        clear()
+        t = app_functions.XOR
+        print('Voici le terme:',logic.to_string(t))
+        save_image_choice = input('Do you want to save the image? (y/n): ')
+        while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+        if save_image_choice == 'y':
+            logic.captureImage(t,path,'XOR',False)
+
+    elif choice==5:
+        clear()
+        t = app_functions.IS_ZERO
+        print('Voici le terme:',logic.to_string(t))
+        save_image_choice = input('Do you want to save the image? (y/n): ')
+        while save_image_choice not in ['y','n']:
+            save_image_choice = input('Invalid choice. Do you want to save the image? (y/n): ')
+        if save_image_choice == 'y':
+            logic.captureImage(t,path,'IS_ZERO',False)
+    elif choice==6:
+        run_main_menu()
+
     
 
 
@@ -149,7 +215,11 @@ def run_main_menu():
         clear()
         run_show_numbers('show_numbers')
         return_main_menu()
-    elif choice == 5:
+    elif choice== 5:
+        clear()
+        run_boolean_expression('boolean expression')
+        return_main_menu()
+    elif choice == 6:
         clear()
         print(good_bye_banner)
 
@@ -165,48 +235,34 @@ def run_arithmetic_operations_menu(path='arithmetic expressions'):
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.ADD))
         logic.captureImage(app_functions.ADD,path,'ADD', False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu()
     elif choice == 2:
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.SUB))
         logic.captureImage(app_functions.SUB,path,'SUB', False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu()
     elif choice == 3:
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.MUL))
         logic.captureImage(app_functions.MUL,path,'MUL',False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu()
     elif choice==4:
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.POW))
         logic.captureImage(app_functions.POW,path,'POWER',False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu()
     elif choice==5:
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.SUCCS))
         logic.captureImage(app_functions.SUCCS,path,'SUCCS',False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu()
     elif choice==6:
         clear()
         print("Voici le terme: "+ logic.to_string(app_functions.PRED))
         logic.captureImage(app_functions.PRED,path,'PRED',False)
-        time.sleep(1)
-        clear()
-        run_arithmetic_operations_menu()
+        return_main_menu
     elif choice == 7:
         clear()
         run_main_menu()
 
 run_main_menu()
-
-input()
\ No newline at end of file
-- 
GitLab