From 02be145dcd8d512e76afddae844d785023594ea6 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 29 Mar 2022 23:02:04 +0900 Subject: [PATCH 01/42] branch change test 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c08480c..8cbc9a9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # APTP 2022 - **{팀명}** ###### Asterisk Python Team Project 2022 -구성원: 아스터 | 리스크 | 홍길동 | Change +구성원: 아스터 | 리스크 | 홍길동 ## 1. 주제 {주제 작성} From 8582e41f1d9ff761c4b969ecdffeb6edea33e572 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Thu, 31 Mar 2022 18:51:56 +0900 Subject: [PATCH 02/42] Update README.md Added coworkers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c08480c..28051e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # APTP 2022 - **{팀명}** ###### Asterisk Python Team Project 2022 -구성원: 아스터 | 리스크 | 홍길동 | Change +구성원: 김덕용 | 김가현 | 송준서 | 배정윤 | 윤석영 ## 1. 주제 {주제 작성} From d88220d39a9b6632fdec4f316f21e5821c6f2ffe Mon Sep 17 00:00:00 2001 From: kimgahyeon Date: Tue, 5 Apr 2022 14:25:58 +0900 Subject: [PATCH 03/42] test --- test.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..ce47b77 --- /dev/null +++ b/test.py @@ -0,0 +1 @@ +print("hello") \ No newline at end of file From a34e62544afd16f16f51d6f61e8412c9381227a2 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Sun, 17 Apr 2022 14:23:46 +0900 Subject: [PATCH 04/42] =?UTF-8?q?=EC=A3=BC=EC=A0=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28051e2..9498b03 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 구성원: 김덕용 | 김가현 | 송준서 | 배정윤 | 윤석영 ## 1. 주제 -{주제 작성} +{Implicant 탐색 프로그램} ## 2. 동기 {동기 작성} From a8ca1def8b3dc259ea6dfcec8386e68a92183790 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Sun, 17 Apr 2022 14:23:59 +0900 Subject: [PATCH 05/42] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9498b03..74dd48a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 구성원: 김덕용 | 김가현 | 송준서 | 배정윤 | 윤석영 ## 1. 주제 -{Implicant 탐색 프로그램} +Implicant 탐색 프로그램 ## 2. 동기 {동기 작성} From e1fd30de38731acfd0c35871ed25d203bff4e72a Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:21:53 +0900 Subject: [PATCH 06/42] some --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 74dd48a..8c11719 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,17 @@ Implicant 탐색 프로그램 ## 2. 동기 -{동기 작성} +기초논리회로 수업을 듣던 중 Implicant를 찾아주는 프로그램이 있으면 좋다고 생각했다. ## 3. 프로그램 사용 대상 -{사용 대상 작성} +기초논리회로 수업을 수강하는 학생 / Implicant를 알고싶은 사람 ## 4. 목적 -{목적 작성} +Implicant를 찾아준다 ## 5. 주요기능 -1. 주요한 기능 -2. 두번째로 주요한 기능 +1. Prime Implicant 찾아주기 +2. 3. 등등등 ## 6. 프로젝트 핵심 From 34c6368d7a146885b87e32dcd4f8b1e4a1a3a6e4 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:29:42 +0900 Subject: [PATCH 07/42] Final change --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8c11719..79a7dce 100644 --- a/README.md +++ b/README.md @@ -16,26 +16,26 @@ Implicant를 찾아준다 ## 5. 주요기능 1. Prime Implicant 찾아주기 -2. -3. 등등등 +2. 입력 갯수 (2, 3, 4, 5)에 따른 Implicant 찾아주기 +3. UI를 통해 이를 그림으로 보여주기 ## 6. 프로젝트 핵심 -1. 첫번째 핵심 -2. 두번째 핵심 -3. 세번째 핵심 +1. 2차원 배열 해석 ( 백준 연구소 ) +2. UI 구현 +3. Essential Prime Implicant 판정 ## 7. 구현에 필요한 라이브러리나 기술 -{pygame, sys, socket, ...} +pygame ## 8. **분업 계획** -홍길동: GUI 구현, board 구현 -아스터: 상자 Class 구현 -리스크: 서버 및 클라이언트 구현 +김덕용: GUI 구현 +김가현: 5개 Implicant 구현 +송준서: 4개 Implicant 구현 +배정윤: 3개 Implicant 구현 +윤석영: 2개 Implicant 구현 ## 9. 기타 -1. 기타적인 무엇 -2. 등등 작성
From 7188824637a0a6b3a7f57692ffa2060f581240f0 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:32:00 +0900 Subject: [PATCH 08/42] some more changes --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79a7dce..90b08c2 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ Implicant 탐색 프로그램 Implicant를 찾아준다 ## 5. 주요기능 -1. Prime Implicant 찾아주기 -2. 입력 갯수 (2, 3, 4, 5)에 따른 Implicant 찾아주기 -3. UI를 통해 이를 그림으로 보여주기 +1. Prime Implicant 찾아줄 수 있다. +2. 입력 갯수 (2, 3, 4, 5)에 따른 Implicant 찾아줄 수 있다. +3. UI를 통해 이를 그림으로 보여줄 수 있다. +4. UI를 통해 입력값을 설정할 수 있다. +5. Essential Prime Implicant를 표시할 수 있다. ## 6. 프로젝트 핵심 1. 2차원 배열 해석 ( 백준 연구소 ) From 66fcd51e1b53fac7799e16985996f7f24cacf2ff Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:11:38 +0900 Subject: [PATCH 09/42] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90b08c2..1557af0 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,11 @@ Implicant를 찾아준다 pygame ## 8. **분업 계획** -김덕용: GUI 구현 -김가현: 5개 Implicant 구현 -송준서: 4개 Implicant 구현 -배정윤: 3개 Implicant 구현 -윤석영: 2개 Implicant 구현 +김덕용: GUI 구현 +김가현: 5개 Implicant 구현 +송준서: 4개 Implicant 구현 +배정윤: 3개 Implicant 구현 +윤석영: 2개 Implicant 구현. ## 9. 기타 From 67c09334d18559649db732828f8feda340e32c85 Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:11:52 +0900 Subject: [PATCH 10/42] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1557af0..c9c59e5 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ pygame 김가현: 5개 Implicant 구현 송준서: 4개 Implicant 구현 배정윤: 3개 Implicant 구현 -윤석영: 2개 Implicant 구현. +윤석영: 2개 Implicant 구현 ## 9. 기타 From eb48a0b89891d6ca6ecb7aca8378b25ed1208c79 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 15:45:15 +0900 Subject: [PATCH 11/42] Add color, key, basic screen --- .idea/APTP2022.iml | 6 +++-- .idea/misc.xml | 2 +- GUI.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 GUI.py diff --git a/.idea/APTP2022.iml b/.idea/APTP2022.iml index d0876a7..8279fbb 100644 --- a/.idea/APTP2022.iml +++ b/.idea/APTP2022.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d56657a..2e5173c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/GUI.py b/GUI.py new file mode 100644 index 0000000..8a6678e --- /dev/null +++ b/GUI.py @@ -0,0 +1,63 @@ +from turtle import color + +import pygame +import sys + + +class Color: + color = { + 'white': (255, 255, 255), + 'black': (0, 0, 0), + 'red': (255, 0, 0), + 'green': (0, 255, 0), + 'blue': (0, 0, 255) + } + + +class Key: + alphabet = {pygame.K_a: 'a', pygame.K_b: 'b', pygame.K_c: 'c', pygame.K_d: 'd', pygame.K_e: 'e', + pygame.K_f: 'f', pygame.K_g: 'g', pygame.K_h: 'h', pygame.K_i: 'i', pygame.K_j: 'j', + pygame.K_k: 'k', pygame.K_l: 'l', pygame.K_m: 'm', pygame.K_n: 'n', pygame.K_o: 'o', + pygame.K_p: 'p', pygame.K_q: 'q', pygame.K_r: 'r', pygame.K_s: 's', pygame.K_t: 't', + pygame.K_u: 'u', pygame.K_v: 'v', pygame.K_w: 'w', pygame.K_x: 'x', pygame.K_y: 'y', + pygame.K_z: 'z'} + + number = {pygame.K_0: '0', pygame.K_1: '1', pygame.K_2: '2', pygame.K_3: '3', pygame.K_4: '4', + pygame.K_5: '5', pygame.K_6: '6', pygame.K_7: '7', pygame.K_8: '8', pygame.K_9: '9'} + + command = {pygame.K_BACKSPACE: 'backspace', pygame.K_RETURN: 'return', pygame.K_SPACE: ' '} + + direction = {pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'} + + key_l = [alphabet, number, command, direction] + + +class Screen: + def __init__(self, size): + pygame.init() + self.size = size + self.screen = pygame.display.set_mode(size) + + def ShowText(self, word, size, color, position): + """ + Function to show text on screen + :param word: str + :param size: int + :param color: set + :param position: set + :return: none + """ + font = pygame.font.SysFont("notosanscjkk", size) + word = font.render(str(word), True, color) + self.screen.blit(word, position) + pygame.display.flip() + + def ShowScreen(self): + self.screen.fill(Color.color['white']) + + +a = Screen((300, 300)) + +while True: + a.ShowScreen() + a.ShowText("Hi There", 90, Color.color['black'], (20, 20)) From 83c893f56154cca80542cc9dfb55b5cd954987a5 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 15:47:44 +0900 Subject: [PATCH 12/42] add __name__ == __init__ --- GUI.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GUI.py b/GUI.py index 8a6678e..4209444 100644 --- a/GUI.py +++ b/GUI.py @@ -56,8 +56,9 @@ def ShowScreen(self): self.screen.fill(Color.color['white']) -a = Screen((300, 300)) +if __name__ == '__main__': + a = Screen((300, 300)) -while True: - a.ShowScreen() - a.ShowText("Hi There", 90, Color.color['black'], (20, 20)) + while True: + a.ShowScreen() + a.ShowText("Hi There", 90, Color.color['black'], (20, 20)) From 0461c80b0015c9d07b2eb73fbebb9edcc33a2cac Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 16:59:43 +0900 Subject: [PATCH 13/42] basic display is ready --- GUI.py | 108 ++++++++++++++++++++++++++++++++++--------------------- TABLE.py | 12 +++++++ 2 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 TABLE.py diff --git a/GUI.py b/GUI.py index 4209444..e7933b5 100644 --- a/GUI.py +++ b/GUI.py @@ -1,64 +1,90 @@ -from turtle import color - import pygame import sys +import TABLE +color = { + 'white': (255, 255, 255), + 'black': (0, 0, 0), + 'red': (255, 0, 0), + 'green': (0, 255, 0), + 'blue': (0, 0, 255) +} -class Color: - color = { - 'white': (255, 255, 255), - 'black': (0, 0, 0), - 'red': (255, 0, 0), - 'green': (0, 255, 0), - 'blue': (0, 0, 255) - } - +alphabet = {pygame.K_a: 'a', pygame.K_b: 'b', pygame.K_c: 'c', pygame.K_d: 'd', pygame.K_e: 'e', + pygame.K_f: 'f', pygame.K_g: 'g', pygame.K_h: 'h', pygame.K_i: 'i', pygame.K_j: 'j', + pygame.K_k: 'k', pygame.K_l: 'l', pygame.K_m: 'm', pygame.K_n: 'n', pygame.K_o: 'o', + pygame.K_p: 'p', pygame.K_q: 'q', pygame.K_r: 'r', pygame.K_s: 's', pygame.K_t: 't', + pygame.K_u: 'u', pygame.K_v: 'v', pygame.K_w: 'w', pygame.K_x: 'x', pygame.K_y: 'y', + pygame.K_z: 'z'} -class Key: - alphabet = {pygame.K_a: 'a', pygame.K_b: 'b', pygame.K_c: 'c', pygame.K_d: 'd', pygame.K_e: 'e', - pygame.K_f: 'f', pygame.K_g: 'g', pygame.K_h: 'h', pygame.K_i: 'i', pygame.K_j: 'j', - pygame.K_k: 'k', pygame.K_l: 'l', pygame.K_m: 'm', pygame.K_n: 'n', pygame.K_o: 'o', - pygame.K_p: 'p', pygame.K_q: 'q', pygame.K_r: 'r', pygame.K_s: 's', pygame.K_t: 't', - pygame.K_u: 'u', pygame.K_v: 'v', pygame.K_w: 'w', pygame.K_x: 'x', pygame.K_y: 'y', - pygame.K_z: 'z'} +number = {pygame.K_0: '0', pygame.K_1: '1', pygame.K_2: '2', pygame.K_3: '3', pygame.K_4: '4', + pygame.K_5: '5', pygame.K_6: '6', pygame.K_7: '7', pygame.K_8: '8', pygame.K_9: '9'} - number = {pygame.K_0: '0', pygame.K_1: '1', pygame.K_2: '2', pygame.K_3: '3', pygame.K_4: '4', - pygame.K_5: '5', pygame.K_6: '6', pygame.K_7: '7', pygame.K_8: '8', pygame.K_9: '9'} +command = {pygame.K_BACKSPACE: 'backspace', pygame.K_RETURN: 'return', pygame.K_SPACE: ' '} - command = {pygame.K_BACKSPACE: 'backspace', pygame.K_RETURN: 'return', pygame.K_SPACE: ' '} +direction = {pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'} - direction = {pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'} +key_l = [alphabet, number, command, direction] - key_l = [alphabet, number, command, direction] +class Screen(TABLE.Table): + """ + Responsibility on Showing Screen + """ -class Screen: - def __init__(self, size): + def __init__(self, screen_size, table, table_size): + """ + Screen Information + :param screen_size: tuple + :param table: list + :param table_size: tuple + """ + super().__init__(table, table_size) pygame.init() - self.size = size - self.screen = pygame.display.set_mode(size) + self.screen_size = screen_size + self.screen = pygame.display.set_mode(screen_size) - def ShowText(self, word, size, color, position): + def ShowText(self, word, text_size, font_color, text_position): """ Function to show text on screen :param word: str - :param size: int - :param color: set - :param position: set + :param text_size: int + :param font_color: str + :param text_position: Tuple :return: none """ - font = pygame.font.SysFont("notosanscjkk", size) - word = font.render(str(word), True, color) - self.screen.blit(word, position) - pygame.display.flip() - - def ShowScreen(self): - self.screen.fill(Color.color['white']) + font = pygame.font.SysFont("notosanscjkk", text_size) + word = font.render(str(word), True, color[font_color]) + self.screen.blit(word, text_position) + + def ShowScreen(self, screen_color): + self.screen.fill(color[screen_color]) + + def ShowTable(self, cell_size, cell_color, cell_border, position): + for i in range(self.table_size[0]): + for j in range(self.table_size[1]): + adjust_position = (position[0] + j * cell_size - cell_border * j, + position[1] + i * cell_size - cell_border * i) + pygame.draw.rect(self.screen, color[cell_color], + (adjust_position[0], + adjust_position[1], + cell_size, + cell_size), + cell_border) + self.ShowText(self.table[i][j], cell_size, cell_color, + (adjust_position[0] + cell_size/3, + adjust_position[1] + cell_size/6)) if __name__ == '__main__': - a = Screen((300, 300)) + t = [[0, 0], + [0, 0], + [0, 0], + [0, 0]] + a = Screen((1000, 1000), t, (4, 2)) while True: - a.ShowScreen() - a.ShowText("Hi There", 90, Color.color['black'], (20, 20)) + a.ShowScreen('white') + a.ShowTable(150, 'black', 3, (100, 100)) + # a.ShowText("Hi There", 90, 'black', (20, 20)) + pygame.display.flip() diff --git a/TABLE.py b/TABLE.py new file mode 100644 index 0000000..a67dca4 --- /dev/null +++ b/TABLE.py @@ -0,0 +1,12 @@ +class Table: + """ + Class for Table + """ + def __init__(self, table, table_size): + """ + Basic Information + :param table: list + :param table_size: Tuple + """ + self.table = table + self.table_size = table_size From e101f4eac68b61d029d27c62d8717760102063da Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 17:03:27 +0900 Subject: [PATCH 14/42] description added --- GUI.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/GUI.py b/GUI.py index e7933b5..574041e 100644 --- a/GUI.py +++ b/GUI.py @@ -29,7 +29,7 @@ class Screen(TABLE.Table): """ - Responsibility on Showing Screen + Responsibility on Displaying Screen """ def __init__(self, screen_size, table, table_size): @@ -46,7 +46,7 @@ def __init__(self, screen_size, table, table_size): def ShowText(self, word, text_size, font_color, text_position): """ - Function to show text on screen + Function to Show Text on Screen :param word: str :param text_size: int :param font_color: str @@ -58,9 +58,22 @@ def ShowText(self, word, text_size, font_color, text_position): self.screen.blit(word, text_position) def ShowScreen(self, screen_color): + """ + Function to Show Screen + :param screen_color: str + :return: none + """ self.screen.fill(color[screen_color]) def ShowTable(self, cell_size, cell_color, cell_border, position): + """ + Function to Show Table + :param cell_size: int + :param cell_color: str + :param cell_border: int + :param position: tuple + :return: none + """ for i in range(self.table_size[0]): for j in range(self.table_size[1]): adjust_position = (position[0] + j * cell_size - cell_border * j, From 580d9f6ceaf66dcc1c613e396a723ec33320b152 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 19:04:14 +0900 Subject: [PATCH 15/42] added interaction class --- GUI.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/GUI.py b/GUI.py index 574041e..771708f 100644 --- a/GUI.py +++ b/GUI.py @@ -27,6 +27,20 @@ key_l = [alphabet, number, command, direction] +class Interaction(TABLE.Table): + def __init__(self, event, table, table_size): + super().__init__(table, table_size) + self.event = event + + def MouseClick(self, mouse_position, table_position, table_length, table_size, table_border): + for i in table_size[0]: + for j in table_size[1]: + adjust_position = (table_position[0] + j*table_length - j*table_border, + table_position[1] + i*table_length - i*table_border) + if 0 < mouse_position[0] - adjust_position[0] < table_length and 0 < mouse_position[1] - adjust_position[1] < table_length: + self.table[i][j] = 1 + + class Screen(TABLE.Table): """ Responsibility on Displaying Screen @@ -65,19 +79,19 @@ def ShowScreen(self, screen_color): """ self.screen.fill(color[screen_color]) - def ShowTable(self, cell_size, cell_color, cell_border, position): + def ShowTable(self, cell_size, cell_color, cell_border, start_position): """ Function to Show Table :param cell_size: int :param cell_color: str :param cell_border: int - :param position: tuple + :param start_position: tuple :return: none """ for i in range(self.table_size[0]): for j in range(self.table_size[1]): - adjust_position = (position[0] + j * cell_size - cell_border * j, - position[1] + i * cell_size - cell_border * i) + adjust_position = (start_position[0] + j * cell_size - cell_border * j, + start_position[1] + i * cell_size - cell_border * i) pygame.draw.rect(self.screen, color[cell_color], (adjust_position[0], adjust_position[1], @@ -90,11 +104,11 @@ def ShowTable(self, cell_size, cell_color, cell_border, position): if __name__ == '__main__': - t = [[0, 0], - [0, 0], - [0, 0], - [0, 0]] - a = Screen((1000, 1000), t, (4, 2)) + t = [[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + a = Screen((1000, 1000), t, (4, 4)) while True: a.ShowScreen('white') From c84bd567604ebe62d0944192892fcf252a1d5bbd Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 19:41:01 +0900 Subject: [PATCH 16/42] add exit condition and key pressed fuction --- GUI.py | 40 ++++++++++++++++++++++++++++------------ TABLE.py | 1 + 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/GUI.py b/GUI.py index 771708f..df51053 100644 --- a/GUI.py +++ b/GUI.py @@ -28,30 +28,43 @@ class Interaction(TABLE.Table): - def __init__(self, event, table, table_size): + """ + Responsibility on Interaction with User + """ + def __init__(self, input_event, table, table_size): super().__init__(table, table_size) - self.event = event + self.input_event = input_event - def MouseClick(self, mouse_position, table_position, table_length, table_size, table_border): - for i in table_size[0]: - for j in table_size[1]: + def MouseClick(self, mouse_position, table_position, table_length, table_border): + for i in self.table_size[0]: + for j in self.table_size[1]: adjust_position = (table_position[0] + j*table_length - j*table_border, table_position[1] + i*table_length - i*table_border) - if 0 < mouse_position[0] - adjust_position[0] < table_length and 0 < mouse_position[1] - adjust_position[1] < table_length: + if 0 < mouse_position[0] - adjust_position[0] < table_length and \ + 0 < mouse_position[1] - adjust_position[1] < table_length: self.table[i][j] = 1 + def KeyboardPressed(self): + for i in key_l: + if self.input_event in i: + return i[self.input_event] + + def IsEnd(self): + if self.input_event.type() == pygame.QUIT: + sys.exit() + class Screen(TABLE.Table): """ Responsibility on Displaying Screen """ - def __init__(self, screen_size, table, table_size): + def __init__(self, screen_size: tuple[int, int], table: list[int], table_size: tuple[int, int]): """ Screen Information - :param screen_size: tuple - :param table: list - :param table_size: tuple + :param screen_size: tuple[int, int] + :param table: list[int] + :param table_size: tuple[int, int] """ super().__init__(table, table_size) pygame.init() @@ -64,7 +77,7 @@ def ShowText(self, word, text_size, font_color, text_position): :param word: str :param text_size: int :param font_color: str - :param text_position: Tuple + :param text_position: tuple[int, int] :return: none """ font = pygame.font.SysFont("notosanscjkk", text_size) @@ -85,7 +98,7 @@ def ShowTable(self, cell_size, cell_color, cell_border, start_position): :param cell_size: int :param cell_color: str :param cell_border: int - :param start_position: tuple + :param start_position: tuple[int, int] :return: none """ for i in range(self.table_size[0]): @@ -111,6 +124,9 @@ def ShowTable(self, cell_size, cell_color, cell_border, start_position): a = Screen((1000, 1000), t, (4, 4)) while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() a.ShowScreen('white') a.ShowTable(150, 'black', 3, (100, 100)) # a.ShowText("Hi There", 90, 'black', (20, 20)) diff --git a/TABLE.py b/TABLE.py index a67dca4..b5cd66a 100644 --- a/TABLE.py +++ b/TABLE.py @@ -2,6 +2,7 @@ class Table: """ Class for Table """ + def __init__(self, table, table_size): """ Basic Information From 350ec6c75878188b597df8d95a9e602dadee3873 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 19:56:27 +0900 Subject: [PATCH 17/42] added some interactions and Final Scene class --- GUI.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/GUI.py b/GUI.py index df51053..72a072a 100644 --- a/GUI.py +++ b/GUI.py @@ -31,9 +31,9 @@ class Interaction(TABLE.Table): """ Responsibility on Interaction with User """ - def __init__(self, input_event, table, table_size): + def __init__(self, input_events, table, table_size): super().__init__(table, table_size) - self.input_event = input_event + self.input_events = input_events def MouseClick(self, mouse_position, table_position, table_length, table_border): for i in self.table_size[0]: @@ -45,12 +45,16 @@ def MouseClick(self, mouse_position, table_position, table_length, table_border) self.table[i][j] = 1 def KeyboardPressed(self): - for i in key_l: - if self.input_event in i: - return i[self.input_event] - - def IsEnd(self): - if self.input_event.type() == pygame.QUIT: + for single_event in self.input_events: + self.IsEnd(single_event) + if single_event.type() == pygame.KEYDOWN: + for i in key_l: + if single_event.key in i: + return i[self.input_events] + + @staticmethod + def IsEnd(end_event): + if end_event == pygame.QUIT: sys.exit() @@ -116,6 +120,10 @@ def ShowTable(self, cell_size, cell_color, cell_border, start_position): adjust_position[1] + cell_size/6)) +class FinalScene(Interaction, Screen): + pass + + if __name__ == '__main__': t = [[0, 0, 0, 0], [0, 0, 0, 0], From 51d8760e824c6ec01883460e4c4794c3f825e086 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 20:08:11 +0900 Subject: [PATCH 18/42] type annotation (type hint) added --- GUI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GUI.py b/GUI.py index 72a072a..85720f2 100644 --- a/GUI.py +++ b/GUI.py @@ -63,11 +63,11 @@ class Screen(TABLE.Table): Responsibility on Displaying Screen """ - def __init__(self, screen_size: tuple[int, int], table: list[int], table_size: tuple[int, int]): + def __init__(self, screen_size: tuple[int, int], table: list[list[int]], table_size: tuple[int, int]): """ Screen Information :param screen_size: tuple[int, int] - :param table: list[int] + :param table: list[list[int]] :param table_size: tuple[int, int] """ super().__init__(table, table_size) From ee5e57f55fac0269c30cd8a569cdc92c8e9cd955 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Mon, 2 May 2022 20:13:30 +0900 Subject: [PATCH 19/42] test --- test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index ce47b77..28e0e87 100644 --- a/test.py +++ b/test.py @@ -1 +1,5 @@ -print("hello") \ No newline at end of file +def multiple(a: int, b: int) -> int: + return a * b + + +print(multiple(1, True)) From 3270f4a133985cb4965a8fc16f711ebbc54476b7 Mon Sep 17 00:00:00 2001 From: JunseoSong Date: Wed, 4 May 2022 14:31:34 +0900 Subject: [PATCH 20/42] =?UTF-8?q?=E3=85=81=E3=84=B4=E3=85=87=E3=84=B9?= =?UTF-8?q?=E3=85=81=E3=84=B9=E3=85=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Junseo.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Junseo.py diff --git a/Junseo.py b/Junseo.py new file mode 100644 index 0000000..4adf683 --- /dev/null +++ b/Junseo.py @@ -0,0 +1,35 @@ +def is_impli_two(a, b): #minterm 2개가 implicant인지 판별 + A8 = a // 8 + A4 = (a % 8) // 4 + A2 = (a % 4) // 2 + A1 = (a % 2) // 1 + + B8 = b // 8 + B4 = (b % 8) // 4 + B2 = (b % 4) // 2 + B1 = (b % 2) // 1 + print(A8, A4, A2, A1, B8, B4, B2, B1) + + dif = abs(A8 - B8) + abs(A4 - B4) + abs(A2 - B2) + abs(A1 - B1) + if dif == 1: + return 1 + else: + return 0 + +def get_minterm_4vari(): #변수가 4개일 때 값이 1인 minterm 받기 + minterm = [] # 1인 minterm의 list + impli = [] # implicant가 모여있는 list + + print("값이 1인 midterm을 차례대로 입력하시오(종료시 -1) :") + while True: + i = int(input()) + if i == -1: + break + elif (i < 0) or (i > 15): + print("0~16" + "5값을 다시 입력하세요") + continue + minterm.append(i) + impli.append(i) # 1개만으로 이미 implicant이므로 바로 추가한다. + + From a9bd06157169cc3889ef5461658ee965bbbf5b83 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 10 May 2022 16:06:39 +0900 Subject: [PATCH 21/42] Add decision page. We need to get mouse input. --- GUI.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/GUI.py b/GUI.py index 85720f2..da9b746 100644 --- a/GUI.py +++ b/GUI.py @@ -35,7 +35,15 @@ def __init__(self, input_events, table, table_size): super().__init__(table, table_size) self.input_events = input_events - def MouseClick(self, mouse_position, table_position, table_length, table_border): + def MouseClick(self, mouse_position: tuple[int, int], table_position, table_length: int, table_border: int): + """ + click + :param mouse_position: + :param table_position: + :param table_length: + :param table_border: + :return: + """ for i in self.table_size[0]: for j in self.table_size[1]: adjust_position = (table_position[0] + j*table_length - j*table_border, @@ -119,6 +127,23 @@ def ShowTable(self, cell_size, cell_color, cell_border, start_position): (adjust_position[0] + cell_size/3, adjust_position[1] + cell_size/6)) + def ShowDecisionPage(self, cell_size, cell_color, cell_border, start_position): + for i in range(5): + adjust_position = (start_position[0] + i * cell_size - cell_border * i - 5*cell_size/2, + start_position[1] - cell_size) + pygame.draw.rect(self.screen, color[cell_color], + (adjust_position[0], + adjust_position[1], + cell_size, + cell_size), + cell_border) + self.ShowText(i, cell_size, cell_color, + (adjust_position[0] + cell_size/3, + adjust_position[1] + cell_size/6)) + self.ShowText('Choose number of inputs', int(cell_size/2), cell_color, + (start_position[0] / 3, + start_position[1]/3)) + class FinalScene(Interaction, Screen): pass @@ -136,6 +161,7 @@ class FinalScene(Interaction, Screen): if event.type == pygame.QUIT: sys.exit() a.ShowScreen('white') - a.ShowTable(150, 'black', 3, (100, 100)) + a.ShowDecisionPage(150, 'black', 3, (a.screen_size[0] / 2, a.screen_size[1]/2)) + # a.ShowTable(150, 'black', 3, (100, 100)) # a.ShowText("Hi There", 90, 'black', (20, 20)) pygame.display.flip() From 79cc4356922ac282ca2bc86ef4d13975e8fcbda3 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 10 May 2022 16:08:13 +0900 Subject: [PATCH 22/42] We need to get mouse input. --- GUI.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GUI.py b/GUI.py index da9b746..27df0aa 100644 --- a/GUI.py +++ b/GUI.py @@ -144,6 +144,8 @@ def ShowDecisionPage(self, cell_size, cell_color, cell_border, start_position): (start_position[0] / 3, start_position[1]/3)) + def GetDecisionPage(self): + pass class FinalScene(Interaction, Screen): pass From 0a302b174c830b2032f0733c6a974be29a114b3c Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 10 May 2022 17:35:00 +0900 Subject: [PATCH 23/42] =?UTF-8?q?interaction=20=ED=8C=8C=EC=9D=BC=EC=9D=84?= =?UTF-8?q?=20=EB=B6=84=EB=A5=98=ED=96=88=EB=8D=94=EB=8B=88=20sys.exit?= =?UTF-8?q?=EC=9D=B4=20=EB=A8=B9=ED=9E=88=EC=A7=80=20=EC=95=8A=EC=9D=8C=20?= =?UTF-8?q?import=EA=B0=80=20=EB=AC=B8=EC=A0=9C=EC=9D=B8=20=EA=B2=83=20?= =?UTF-8?q?=EA=B0=99=EC=9D=80=EB=8D=B0=20=EB=AA=A8=EB=A5=B4=EA=B2=A0?= =?UTF-8?q?=EA=B3=A0=20=EB=82=98=EB=A8=B8=EC=A7=80=EB=8A=94=20=EC=9E=98=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=ED=95=A8.=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EC=A2=85=EB=A3=8C=EB=A5=BC=201=EC=88=9C=EC=9C=84?= =?UTF-8?q?=20=EB=AA=A9=ED=91=9C=EB=A1=9C=20=ED=95=B4=EC=95=BC=ED=95=A0?= =?UTF-8?q?=EB=93=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GUI.py | 94 ++++++++++++++------------------------------------ INTERACTION.py | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 68 deletions(-) create mode 100644 INTERACTION.py diff --git a/GUI.py b/GUI.py index 27df0aa..d783d7c 100644 --- a/GUI.py +++ b/GUI.py @@ -27,51 +27,12 @@ key_l = [alphabet, number, command, direction] -class Interaction(TABLE.Table): - """ - Responsibility on Interaction with User - """ - def __init__(self, input_events, table, table_size): - super().__init__(table, table_size) - self.input_events = input_events - - def MouseClick(self, mouse_position: tuple[int, int], table_position, table_length: int, table_border: int): - """ - click - :param mouse_position: - :param table_position: - :param table_length: - :param table_border: - :return: - """ - for i in self.table_size[0]: - for j in self.table_size[1]: - adjust_position = (table_position[0] + j*table_length - j*table_border, - table_position[1] + i*table_length - i*table_border) - if 0 < mouse_position[0] - adjust_position[0] < table_length and \ - 0 < mouse_position[1] - adjust_position[1] < table_length: - self.table[i][j] = 1 - - def KeyboardPressed(self): - for single_event in self.input_events: - self.IsEnd(single_event) - if single_event.type() == pygame.KEYDOWN: - for i in key_l: - if single_event.key in i: - return i[self.input_events] - - @staticmethod - def IsEnd(end_event): - if end_event == pygame.QUIT: - sys.exit() - - class Screen(TABLE.Table): """ Responsibility on Displaying Screen """ - def __init__(self, screen_size: tuple[int, int], table: list[list[int]], table_size: tuple[int, int]): + def __init__(self, screen_size, table, table_size, cell_size, cell_border): """ Screen Information :param screen_size: tuple[int, int] @@ -82,6 +43,8 @@ def __init__(self, screen_size: tuple[int, int], table: list[list[int]], table_s pygame.init() self.screen_size = screen_size self.screen = pygame.display.set_mode(screen_size) + self.cell_size = cell_size + self.cell_border = cell_border def ShowText(self, word, text_size, font_color, text_position): """ @@ -104,7 +67,7 @@ def ShowScreen(self, screen_color): """ self.screen.fill(color[screen_color]) - def ShowTable(self, cell_size, cell_color, cell_border, start_position): + def ShowTable(self, cell_color, start_position): """ Function to Show Table :param cell_size: int @@ -115,55 +78,50 @@ def ShowTable(self, cell_size, cell_color, cell_border, start_position): """ for i in range(self.table_size[0]): for j in range(self.table_size[1]): - adjust_position = (start_position[0] + j * cell_size - cell_border * j, - start_position[1] + i * cell_size - cell_border * i) + adjust_position = (start_position[0] + j * self.cell_size - self.cell_border * j, + start_position[1] + i * self.cell_size - self.cell_border * i) pygame.draw.rect(self.screen, color[cell_color], (adjust_position[0], adjust_position[1], - cell_size, - cell_size), - cell_border) - self.ShowText(self.table[i][j], cell_size, cell_color, - (adjust_position[0] + cell_size/3, - adjust_position[1] + cell_size/6)) - - def ShowDecisionPage(self, cell_size, cell_color, cell_border, start_position): + self.cell_size, + self.cell_size), + self.cell_border) + self.ShowText(self.table[i][j], self.cell_size, cell_color, + (adjust_position[0] + self.cell_size/3, + adjust_position[1] + self.cell_size/6)) + + def ShowDecisionPage(self, cell_color, start_position): for i in range(5): - adjust_position = (start_position[0] + i * cell_size - cell_border * i - 5*cell_size/2, - start_position[1] - cell_size) + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2, + start_position[1] - self.cell_size) pygame.draw.rect(self.screen, color[cell_color], (adjust_position[0], adjust_position[1], - cell_size, - cell_size), - cell_border) - self.ShowText(i, cell_size, cell_color, - (adjust_position[0] + cell_size/3, - adjust_position[1] + cell_size/6)) - self.ShowText('Choose number of inputs', int(cell_size/2), cell_color, + self.cell_size, + self.cell_size), + self.cell_border) + self.ShowText(i, self.cell_size, cell_color, + (adjust_position[0] + self.cell_size/3, + adjust_position[1] + self.cell_size/6)) + self.ShowText('Choose number of inputs', int(self.cell_size/2), cell_color, (start_position[0] / 3, start_position[1]/3)) - def GetDecisionPage(self): - pass - -class FinalScene(Interaction, Screen): - pass - if __name__ == '__main__': t = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] - a = Screen((1000, 1000), t, (4, 4)) + a = Screen((1000, 1000), t, (4, 4), 150, 3) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() a.ShowScreen('white') - a.ShowDecisionPage(150, 'black', 3, (a.screen_size[0] / 2, a.screen_size[1]/2)) + a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1]/2)) + # a.ShowTable(150, 'black', 3, (100, 100)) # a.ShowText("Hi There", 90, 'black', (20, 20)) pygame.display.flip() diff --git a/INTERACTION.py b/INTERACTION.py new file mode 100644 index 0000000..a190c6c --- /dev/null +++ b/INTERACTION.py @@ -0,0 +1,60 @@ +from GUI import Screen, pygame, sys +# import pygame +# import sys + + +class Interaction(Screen): + """ + Responsibility on Interaction with User + """ + def __init__(self, screen_size, table, table_size, cell_size, cell_border): + super().__init__(screen_size, table, table_size, cell_size, cell_border) + + def MouseClick(self, table_position): + (mouseX, mouseY) = pygame.mouse.get_pos() + for i in self.table_size[0]: + for j in self.table_size[1]: + adjust_position = (table_position[0] + j*self.cell_size - j*self.cell_border, + table_position[1] + i*self.cell_size - i*self.cell_border) + if 0 < mouseX - adjust_position[0] < self.cell_size and \ + 0 < mouseY - adjust_position[1] < self.cell_size: + self.table[i][j] = 1 + + def GetDecisionPage(self, start_position): + (mouseX, mouseY) = pygame.mouse.get_pos() + for i in range(5): + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2, + start_position[1] - self.cell_size) + if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size: + return i + return -1 + + def IsEvent(self, mode, start_position): + while True: + for input_event in pygame.event.get(): + if mode == 'number': + if input_event.type == pygame.MOUSEBUTTONDOWN: + return 'number', self.GetDecisionPage(start_position) + elif mode == 'table': + if input_event.type == pygame.MOUSEBUTTONDOWN: + self.MouseClick(start_position) + + +if __name__ == '__main__': + t = [[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + a = Interaction((1000, 1000), t, (4, 4), 150, 3) + + while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() + a.ShowScreen('white') + a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1]/2)) + decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1]/2)) + print(decision) + # a.ShowTable(150, 'black', 3, (100, 100)) + # a.ShowText("Hi There", 90, 'black', (20, 20)) + pygame.display.flip() From 2107fff809cd02f12249bfc3806a36e0e44c7a50 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 24 May 2022 18:17:55 +0900 Subject: [PATCH 24/42] =?UTF-8?q?=EC=9E=85=EB=A0=A5=EC=9D=B4=20=EC=9E=98?= =?UTF-8?q?=20=EC=95=88=EB=90=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GUI.py | 22 ++++----- INTERACTION.py | 119 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 108 insertions(+), 33 deletions(-) diff --git a/GUI.py b/GUI.py index d783d7c..9f4b037 100644 --- a/GUI.py +++ b/GUI.py @@ -67,15 +67,16 @@ def ShowScreen(self, screen_color): """ self.screen.fill(color[screen_color]) - def ShowTable(self, cell_color, start_position): + def ShowTable(self, cell_color): """ Function to Show Table - :param cell_size: int :param cell_color: str - :param cell_border: int - :param start_position: tuple[int, int] :return: none """ + # print('table screen') + start_position = (self.screen_size[0]/2 - self.table_size[1]*self.cell_size/2.0, + self.screen_size[1]/2 - self.table_size[0]*self.cell_size/2.0 - self.cell_size/2) + for i in range(self.table_size[0]): for j in range(self.table_size[1]): adjust_position = (start_position[0] + j * self.cell_size - self.cell_border * j, @@ -91,8 +92,9 @@ def ShowTable(self, cell_color, start_position): adjust_position[1] + self.cell_size/6)) def ShowDecisionPage(self, cell_color, start_position): - for i in range(5): - adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2, + # print('decision page') + for i in range(1, 5): + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 6*self.cell_size/2, start_position[1] - self.cell_size) pygame.draw.rect(self.screen, color[cell_color], (adjust_position[0], @@ -100,7 +102,7 @@ def ShowDecisionPage(self, cell_color, start_position): self.cell_size, self.cell_size), self.cell_border) - self.ShowText(i, self.cell_size, cell_color, + self.ShowText(i + 1, self.cell_size, cell_color, (adjust_position[0] + self.cell_size/3, adjust_position[1] + self.cell_size/6)) self.ShowText('Choose number of inputs', int(self.cell_size/2), cell_color, @@ -116,9 +118,9 @@ def ShowDecisionPage(self, cell_color, start_position): a = Screen((1000, 1000), t, (4, 4), 150, 3) while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - sys.exit() + # for event in pygame.event.get(): + # if event.type == pygame.QUIT: + # sys.exit() a.ShowScreen('white') a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1]/2)) diff --git a/INTERACTION.py b/INTERACTION.py index a190c6c..d0fd0fb 100644 --- a/INTERACTION.py +++ b/INTERACTION.py @@ -1,4 +1,6 @@ -from GUI import Screen, pygame, sys +from GUI import Screen, pygame, sys, color + + # import pygame # import sys @@ -7,6 +9,7 @@ class Interaction(Screen): """ Responsibility on Interaction with User """ + def __init__(self, screen_size, table, table_size, cell_size, cell_border): super().__init__(screen_size, table, table_size, cell_size, cell_border) @@ -14,47 +17,117 @@ def MouseClick(self, table_position): (mouseX, mouseY) = pygame.mouse.get_pos() for i in self.table_size[0]: for j in self.table_size[1]: - adjust_position = (table_position[0] + j*self.cell_size - j*self.cell_border, - table_position[1] + i*self.cell_size - i*self.cell_border) + adjust_position = (table_position[0] + j * self.cell_size - j * self.cell_border, + table_position[1] + i * self.cell_size - i * self.cell_border) if 0 < mouseX - adjust_position[0] < self.cell_size and \ 0 < mouseY - adjust_position[1] < self.cell_size: self.table[i][j] = 1 - def GetDecisionPage(self, start_position): + def GetDecision(self, start_position): (mouseX, mouseY) = pygame.mouse.get_pos() for i in range(5): - adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2, + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5 * self.cell_size / 2, start_position[1] - self.cell_size) if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size: - return i + return i + 1 return -1 - def IsEvent(self, mode, start_position): - while True: - for input_event in pygame.event.get(): + def IsEvent(self, mode, start_position, event_list): + # print('get event') + for input_event in event_list: + if input_event.type == pygame.MOUSEBUTTONDOWN: if mode == 'number': - if input_event.type == pygame.MOUSEBUTTONDOWN: - return 'number', self.GetDecisionPage(start_position) - elif mode == 'table': - if input_event.type == pygame.MOUSEBUTTONDOWN: - self.MouseClick(start_position) + return self.GetDecision(start_position) + if mode == 'table': + print('doing') + # return self.MouseClick(start_position) + + def BackButton(self, sc_type): + # print('show back button') + pygame.draw.rect(self.screen, color['black'], + (30, + 30, + self.cell_size / 2, + self.cell_size / 2), + self.cell_border) + pygame.draw.polygon(self.screen, color['black'], + ((30 + 10, 30 + self.cell_size / 4), + (30 + self.cell_size / 2 - 10, 30 + 10), + (30 + self.cell_size / 2 - 10, 30 + self.cell_size / 2 - 10) + )) if __name__ == '__main__': - t = [[0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0]] + t = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] a = Interaction((1000, 1000), t, (4, 4), 150, 3) + screen_type = 'decide' while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: + el = pygame.event.get() + + for end_event in el: + if end_event.type == pygame.QUIT: + print('program ended') sys.exit() a.ShowScreen('white') - a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1]/2)) - decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1]/2)) - print(decision) + + if screen_type == 'decide': + a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1] / 2)) + decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1] / 2), el) + if decision is not None: + print(decision) + if decision != -1: + if decision == 2: + a.table = [ + [0, 0], + [0, 0] + ] + a.table_size = (2, 2) + if decision == 3: + a.table = [ + [0, 0], + [0, 0], + [0, 0], + [0, 0] + ] + a.table_size = (4, 2) + if decision == 4: + a.table = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] + a.table_size = (4, 4) + if decision == 5: + a.table = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] + a.table_size = (4, 4) + screen_type = 'done' + elif screen_type == 'done': + a.BackButton(screen_type) + stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0, + a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2) + + for back_event in el: + if back_event.type == pygame.MOUSEBUTTONDOWN: + (mx, my) = pygame.mouse.get_pos() + if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: + print('in') + screen_type = 'decide' + decision = None + a.ShowTable('black') + # a.ShowTable(150, 'black', 3, (100, 100)) # a.ShowText("Hi There", 90, 'black', (20, 20)) + pygame.event.pump() pygame.display.flip() From 230071eacdfe2df5f2efb8eb3918d4cd86f163a5 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 31 May 2022 20:48:14 +0900 Subject: [PATCH 25/42] everything GOOD Ended Get some INPUTS --- GUI.py | 2 +- INTERACTION.py | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/GUI.py b/GUI.py index 9f4b037..0e2a16e 100644 --- a/GUI.py +++ b/GUI.py @@ -75,7 +75,7 @@ def ShowTable(self, cell_color): """ # print('table screen') start_position = (self.screen_size[0]/2 - self.table_size[1]*self.cell_size/2.0, - self.screen_size[1]/2 - self.table_size[0]*self.cell_size/2.0 - self.cell_size/2) + self.screen_size[1]/2 - self.table_size[0]*self.cell_size/2.0) for i in range(self.table_size[0]): for j in range(self.table_size[1]): diff --git a/INTERACTION.py b/INTERACTION.py index d0fd0fb..3e26851 100644 --- a/INTERACTION.py +++ b/INTERACTION.py @@ -25,13 +25,25 @@ def MouseClick(self, table_position): def GetDecision(self, start_position): (mouseX, mouseY) = pygame.mouse.get_pos() - for i in range(5): - adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5 * self.cell_size / 2, + for i in range(1, 5): + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 6 * self.cell_size / 2, start_position[1] - self.cell_size) if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size: return i + 1 return -1 + def GetInput(self, start_position): + (mouseX, mouseY) = pygame.mouse.get_pos() + for i in range(self.table_size[0]): + for j in range(self.table_size[1]): + adjust_position = (start_position[0] + j * self.cell_size - self.cell_border * j, + start_position[1] + i * self.cell_size - self.cell_border * i + self.cell_size/2) + if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size: + if self.table[i][j] == 1: + self.table[i][j] = 0 + elif self.table[i][j] == 0: + self.table[i][j] = 1 + def IsEvent(self, mode, start_position, event_list): # print('get event') for input_event in event_list: @@ -39,7 +51,7 @@ def IsEvent(self, mode, start_position, event_list): if mode == 'number': return self.GetDecision(start_position) if mode == 'table': - print('doing') + self.GetInput(start_position) # return self.MouseClick(start_position) def BackButton(self, sc_type): @@ -64,7 +76,7 @@ def BackButton(self, sc_type): [0, 0, 0, 0], [0, 0, 0, 0] ] - a = Interaction((1000, 1000), t, (4, 4), 150, 3) + a = Interaction((800, 800), t, (4, 4), 130, 3) screen_type = 'decide' while True: @@ -125,9 +137,8 @@ def BackButton(self, sc_type): print('in') screen_type = 'decide' decision = None + + a.IsEvent('table', stp, el) a.ShowTable('black') - # a.ShowTable(150, 'black', 3, (100, 100)) - # a.ShowText("Hi There", 90, 'black', (20, 20)) - pygame.event.pump() pygame.display.flip() From a4e5211e3a09afed48fd857c7c15af7c181e22c4 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 31 May 2022 21:14:30 +0900 Subject: [PATCH 26/42] example for 2 by 2 --- 2by2.py | 32 ++++++++++++++++++++++++++++++++ INTERACTION.py | 17 ++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 2by2.py diff --git a/2by2.py b/2by2.py new file mode 100644 index 0000000..4f8293c --- /dev/null +++ b/2by2.py @@ -0,0 +1,32 @@ +# t 라는 list가 입력되었다고 간주 +# 2 * 2 list임 + +def get_2by2(t): + did = [['yet', 'yet'], + ['yet', 'yet']] + ans = [] + + for i in range(2): + for j in range(2): + if t[i][j] == 1 and did[i][j] == 'yet': + did[i][j] = 'done' + small_ans = [[i, j]] + + # 상하좌우 + if t[i - 1][j] == 1: + small_ans.append([i - 1, j]) + did[i-1][j] = 'done' + if t[i + 1][j] == 1: + small_ans.append([i + 1, j]) + did[i+1][j] = 'done' + if t[i][j - 1] == 1: + small_ans.append([i, j-1]) + did[i][j - 1] = 'done' + if t[i][j + 1] == 1: + small_ans.append([i, j+1]) + did[i][j + 1] = 'done' + + ans.append(small_ans) + + return ans + diff --git a/INTERACTION.py b/INTERACTION.py index 3e26851..bc246e5 100644 --- a/INTERACTION.py +++ b/INTERACTION.py @@ -118,10 +118,18 @@ def BackButton(self, sc_type): a.table_size = (4, 4) if decision == 5: a.table = [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0] + [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ], + [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] ] a.table_size = (4, 4) screen_type = 'done' @@ -134,7 +142,6 @@ def BackButton(self, sc_type): if back_event.type == pygame.MOUSEBUTTONDOWN: (mx, my) = pygame.mouse.get_pos() if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: - print('in') screen_type = 'decide' decision = None From 4018cff45c6b301b08a7145db778921fe22dc71e Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 21:20:00 +0900 Subject: [PATCH 27/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/APTP2022.iml | 2 +- .idea/misc.xml | 2 +- sukyoung.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 sukyoung.py diff --git a/.idea/APTP2022.iml b/.idea/APTP2022.iml index 8279fbb..8101941 100644 --- a/.idea/APTP2022.iml +++ b/.idea/APTP2022.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 2e5173c..35a08cf 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/sukyoung.py b/sukyoung.py new file mode 100644 index 0000000..ecbeaa6 --- /dev/null +++ b/sukyoung.py @@ -0,0 +1,81 @@ +#사용자가 어떤 table을 줬다. +#table=[[1,0], +# [1,1]] +#implicant=0 +# +#for i in range(len(table)): +# for j in range(len(table[i])): + # if table[i][j]==1: +# if table[i][j+1]==1: #오른쪽 것도 1이면 + # + # else: + # break + +ans=[] +table=input().split() #수정하기 + +if table==[[0,0], + [0,0]]: + ans=[] + +elif table==[[0,0], + [0,1]]: + ans=[[table[1][1]]] + +elif table==[[0,0], + [1,0]]: + ans=[[table[1][0]]] + +elif table==[[0,0], + [1,1]]: + ans=[[table[1][0],table[1][1]]] + +elif table==[[0,1], + [0,0]]: + ans=[[table[0][1]]] + +elif table==[[0,1], + [0,1]]: + ans=[ [table[0][1],table[1][1]] ] + +elif table==[[0,1], + [1,1]]: + ans=[ [table[0][1],table[1][1]], [table[1][0],table[1][1]] ] + +elif table==[[0,1], + [1,0]]: + ans=[ [table[0][1]], [table[1][0]] ] + +elif table==[[1,0], + [0,0]]: + ans=[[table[0][0]]] + +elif table==[[1,0], + [0,1]]: + ans=[ [table[0][0]], [table[1][1]] ] + +elif table==[[1,0], + [1,0]]: + ans=[ [table[0][0],table[0][1]] ] + +elif table==[[1,0], + [1,1]]: + ans=[ [table[0][0],table[1][0]], [table[1][0],table[1][1]] ] + +elif table==[[1,1], + [0,0]]: + ans=[ [table[0][0],table[0][1]] ] + +elif table==[[1,1], + [0,1]]: + ans=[ [table[0][0],table[0][1]], [table[0][1],table[1][1]] ] + +elif table==[[1,1], + [1,0]]: + ans=[ [table[0][0],table[0][1]], [table[0][0],table[1][0]] ] + +elif table==[[1,1], + [1,1]]: + list=[ [table[0][0],table[0][1],table[1][0],table[1][1]] ] + +print(ans) \ No newline at end of file From 3645a5bd6d48bddc60d9ccbbdef7b9bcccf38dd2 Mon Sep 17 00:00:00 2001 From: kimgahyeon Date: Tue, 31 May 2022 21:22:31 +0900 Subject: [PATCH 28/42] . --- .idea/APTP2022.iml | 2 +- .idea/misc.xml | 2 +- kmap_5.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 kmap_5.py diff --git a/.idea/APTP2022.iml b/.idea/APTP2022.iml index 8101941..9a323b0 100644 --- a/.idea/APTP2022.iml +++ b/.idea/APTP2022.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 35a08cf..dc9ea49 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/kmap_5.py b/kmap_5.py new file mode 100644 index 0000000..6d2531b --- /dev/null +++ b/kmap_5.py @@ -0,0 +1,37 @@ +imp = + +for i in range(2): + for j in range(4): + for k in range(4): + if arr[i][j][k] == 1: + if arr[i+1][j][k] == 1: + + if arr[i-1][j][k] == 1: + + if arr[i][j+1][k] == 1: + + if arr[i][j-1][k] == 1: + + if arr[i][j][k+1] == 1: + + + + + +""" +# 길이,0:가로/1:세로,좌표 +n = int(input()) +for i in range(n): + l, d, x, y = map(int, input().split()) + for j in range(l):#격자판 좌표 원점은 1,1 / 리스트 원점은 0,0 // d가 0이면 가로로 증가 1이면 세로로 증가 + if d == 0: + m[x-1][y-1+j] = 1 + else: + m[x-1+j][y-1] = 1 + +#격자판 출력 +for i in range(h): + for j in range(w): + print(m[i][j], end=' ') + print() +""" \ No newline at end of file From d89b1e681f1e89f3e4a2f2becdce3183b0d0a23b Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 31 May 2022 21:28:10 +0900 Subject: [PATCH 29/42] update example --- 2by2.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/2by2.py b/2by2.py index 4f8293c..e6f6d5f 100644 --- a/2by2.py +++ b/2by2.py @@ -13,20 +13,26 @@ def get_2by2(t): small_ans = [[i, j]] # 상하좌우 - if t[i - 1][j] == 1: - small_ans.append([i - 1, j]) - did[i-1][j] = 'done' - if t[i + 1][j] == 1: - small_ans.append([i + 1, j]) - did[i+1][j] = 'done' - if t[i][j - 1] == 1: - small_ans.append([i, j-1]) - did[i][j - 1] = 'done' - if t[i][j + 1] == 1: - small_ans.append([i, j+1]) - did[i][j + 1] = 'done' + if t[(i-1+2) % 2][j] == 1: + if [(i-1+2) % 2, j] not in small_ans: + small_ans.append([(i-1+2) % 2, j]) + did[(i-1+2) % 2][j] = 'done' + if t[(i+1) % 2][j] == 1: + if [(i+1) % 2, j] not in small_ans: + small_ans.append([(i+1) % 2, j]) + did[(i+1) % 2][j] = 'done' + if t[i][(j-1+2) % 2] == 1: + if [i, (j-1+2) % 2] not in small_ans: + small_ans.append([i, (j-1+2) % 2]) + did[i][(j-1+2) % 2] = 'done' + if t[i][(j+1) % 2] == 1: + if [i, (j+1) % 2] not in small_ans: + small_ans.append([i, (j+1) % 2]) + did[i][(j+1) % 2] = 'done' ans.append(small_ans) return ans + +print(get_2by2([[1, 0], [1, 0]])) \ No newline at end of file From a7c98778a2adf3260f1d680ace8f86954db948d0 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 31 May 2022 21:35:58 +0900 Subject: [PATCH 30/42] REALLY done --- .idea/APTP2022.iml | 2 +- .idea/misc.xml | 2 +- 2by2.py | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.idea/APTP2022.iml b/.idea/APTP2022.iml index 9a323b0..74d515a 100644 --- a/.idea/APTP2022.iml +++ b/.idea/APTP2022.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dc9ea49..2e5173c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/2by2.py b/2by2.py index e6f6d5f..da8ad4f 100644 --- a/2by2.py +++ b/2by2.py @@ -30,9 +30,16 @@ def get_2by2(t): small_ans.append([i, (j+1) % 2]) did[i][(j+1) % 2] = 'done' - ans.append(small_ans) + if len(small_ans) & (len(small_ans) - 1) == 0: + ans.append(small_ans) + else: + while len(small_ans) & (len(small_ans) - 1) != 0: + index = small_ans.pop() + did[index[0]][index[1]] = 'yet' + if small_ans is not []: + ans.append(small_ans) return ans -print(get_2by2([[1, 0], [1, 0]])) \ No newline at end of file +print(get_2by2([[1, 1], [1, 0]])) From 4f6ccc60a25f65d535fbf988aa0563215d634937 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Tue, 31 May 2022 21:56:09 +0900 Subject: [PATCH 31/42] open source --- 2by2.py | 2 +- LAST_RESORT.py | 155 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 LAST_RESORT.py diff --git a/2by2.py b/2by2.py index da8ad4f..78f9958 100644 --- a/2by2.py +++ b/2by2.py @@ -42,4 +42,4 @@ def get_2by2(t): return ans -print(get_2by2([[1, 1], [1, 0]])) +print(get_2by2([[1, 1], [1, 1]])) diff --git a/LAST_RESORT.py b/LAST_RESORT.py new file mode 100644 index 0000000..3552f4c --- /dev/null +++ b/LAST_RESORT.py @@ -0,0 +1,155 @@ +# Quine McCluskey algorithm for minimizing logical expressions +# Author: Suman Adhikari + +def mul(x,y): # Multiply 2 minterms + res = [] + for i in x: + if i+"'" in y or (len(i)==2 and i[0] in y): + return [] + else: + res.append(i) + for i in y: + if i not in res: + res.append(i) + return res + +def multiply(x,y): # Multiply 2 expressions + res = [] + for i in x: + for j in y: + tmp = mul(i,j) + res.append(tmp) if len(tmp) != 0 else None + return res + +def refine(my_list,dc_list): # Removes don't care terms from a given list and returns refined list + res = [] + for i in my_list: + if int(i) not in dc_list: + res.append(i) + return res + +def findEPI(x): # Function to find essential prime implicants from prime implicants chart + res = [] + for i in x: + if len(x[i]) == 1: + res.append(x[i][0]) if x[i][0] not in res else None + return res + +def findVariables(x): # Function to find variables in a meanterm. For example, the minterm --01 has C' and D as variables + var_list = [] + for i in range(len(x)): + if x[i] == '0': + var_list.append(chr(i+65)+"'") + elif x[i] == '1': + var_list.append(chr(i+65)) + return var_list + +def flatten(x): # Flattens a list + flattened_items = [] + for i in x: + flattened_items.extend(x[i]) + return flattened_items + +def findminterms(a): #Function for finding out which minterms are merged. For example, 10-1 is obtained by merging 9(1001) and 11(1011) + gaps = a.count('-') + if gaps == 0: + return [str(int(a,2))] + x = [bin(i)[2:].zfill(gaps) for i in range(pow(2,gaps))] + temp = [] + for i in range(pow(2,gaps)): + temp2,ind = a[:],-1 + for j in x[0]: + if ind != -1: + ind = ind+temp2[ind+1:].find('-')+1 + else: + ind = temp2[ind+1:].find('-') + temp2 = temp2[:ind]+j+temp2[ind+1:] + temp.append(str(int(temp2,2))) + x.pop(0) + return temp + +def compare(a,b): # Function for checking if 2 minterms differ by 1 bit only + c = 0 + for i in range(len(a)): + if a[i] != b[i]: + mismatch_index = i + c += 1 + if c>1: + return (False,None) + return (True,mismatch_index) + +def removeTerms(_chart,terms): # Removes minterms which are already covered from chart + for i in terms: + for j in findminterms(i): + try: + del _chart[j] + except KeyError: + pass + +mt = [int(i) for i in input("Enter the minterms: ").strip().split()] +dc = [int(i) for i in input("Enter the don't cares(If any): ").strip().split()] +mt.sort() +minterms = mt+dc +minterms.sort() +size = len(bin(minterms[-1]))-2 +groups,all_pi = {},set() + +# Primary grouping starts +for minterm in minterms: + try: + groups[bin(minterm).count('1')].append(bin(minterm)[2:].zfill(size)) + except KeyError: + groups[bin(minterm).count('1')] = [bin(minterm)[2:].zfill(size)] +# Primary grouping ends + +#Primary group printing starts +print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s"%('='*50)) +for i in sorted(groups.keys()): + print("%5d:"%i) # Prints group number + for j in groups[i]: + print("\t\t %-20d%s"%(int(j,2),j)) # Prints minterm and its binary representation + print('-'*50) +#Primary group printing ends + +# Process for creating tables and finding prime implicants starts +while True: + tmp = groups.copy() + groups,m,marked,should_stop = {},0,set(),True + l = sorted(list(tmp.keys())) + for i in range(len(l)-1): + for j in tmp[l[i]]: # Loop which iterates through current group elements + for k in tmp[l[i+1]]: # Loop which iterates through next group elements + res = compare(j,k) # Compare the minterms + if res[0]: # If the minterms differ by 1 bit only + try: + groups[m].append(j[:res[1]]+'-'+j[res[1]+1:]) if j[:res[1]]+'-'+j[res[1]+1:] not in groups[m] else None # Put a '-' in the changing bit and add it to corresponding group + except KeyError: + groups[m] = [j[:res[1]]+'-'+j[res[1]+1:]] # If the group doesn't exist, create the group at first and then put a '-' in the changing bit and add it to the newly created group + should_stop = False + marked.add(j) # Mark element j + marked.add(k) # Mark element k + m += 1 + local_unmarked = set(flatten(tmp)).difference(marked) # Unmarked elements of each table + all_pi = all_pi.union(local_unmarked) # Adding Prime Implicants to global list + print("Unmarked elements(Prime Implicants) of this table:",None if len(local_unmarked)==0 else ', '.join(local_unmarked)) # Printing Prime Implicants of current table + if should_stop: # If the minterms cannot be combined further + print('--==-=-=-=-=-=123123123123123123123') + print(all_pi) + print('329875904238720398534523452849357092435') + + print("\n\nAll Prime Implicants: ",None if len(all_pi)==0 else ', '.join(all_pi)) # Print all prime implicants + break + # Printing of all the next groups starts + print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s"%('='*50)) + for i in sorted(groups.keys()): + print("%5d:"%i) # Prints group number + for j in groups[i]: + print("\t\t%-24s%s"%(','.join(findminterms(j)),j)) # Prints minterms and its binary representation + print('-'*50) + # Printing of all the next groups ends +# Process for creating tables and finding prime implicants ends + + +# Printing and processing of Prime Implicant chart starts +sz = len(str(mt[-1])) # The number of digits of the largest minterm +chart = {} From 0b370d0a9b92d346046fdff8e681288c6a815aab Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 21:58:46 +0900 Subject: [PATCH 32/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- "3\352\260\234\354\247\234\353\246\254.py" | 30 ++++ sukyoung.py | 153 ++++++++++----------- 3 files changed, 103 insertions(+), 82 deletions(-) create mode 100644 "3\352\260\234\354\247\234\353\246\254.py" diff --git a/.idea/misc.xml b/.idea/misc.xml index 2e5173c..35a08cf 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git "a/3\352\260\234\354\247\234\353\246\254.py" "b/3\352\260\234\354\247\234\353\246\254.py" new file mode 100644 index 0000000..eb263dd --- /dev/null +++ "b/3\352\260\234\354\247\234\353\246\254.py" @@ -0,0 +1,30 @@ +def get_3by3(t): + did = [['yet', 'yet'], + ['yet', 'yet'], + ['yet', 'yet'], + ['yet', 'yet']] + ans = [] + + for i in range(4): + for j in range(2): + if t[i][j] == 1 and did[i][j] == 'yet': + did[i][j] = 'done' + small_ans = [[i, j]] + + # 상하좌우 + if t[i - 1][j] == 1: + small_ans.append([i - 1, j]) + did[i-1][j] = 'done' + if t[i + 1][j] == 1: + small_ans.append([i + 1, j]) + did[i+1][j] = 'done' + if t[i][j - 1] == 1: + small_ans.append([i, j-1]) + did[i][j - 1] = 'done' + if t[i][j + 1] == 1: + small_ans.append([i, j+1]) + did[i][j + 1] = 'done' + + ans.append(small_ans) + + return ans diff --git a/sukyoung.py b/sukyoung.py index ecbeaa6..5ebe750 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -1,81 +1,72 @@ -#사용자가 어떤 table을 줬다. -#table=[[1,0], -# [1,1]] -#implicant=0 -# -#for i in range(len(table)): -# for j in range(len(table[i])): - # if table[i][j]==1: -# if table[i][j+1]==1: #오른쪽 것도 1이면 - # - # else: - # break - -ans=[] -table=input().split() #수정하기 - -if table==[[0,0], - [0,0]]: - ans=[] - -elif table==[[0,0], - [0,1]]: - ans=[[table[1][1]]] - -elif table==[[0,0], - [1,0]]: - ans=[[table[1][0]]] - -elif table==[[0,0], - [1,1]]: - ans=[[table[1][0],table[1][1]]] - -elif table==[[0,1], - [0,0]]: - ans=[[table[0][1]]] - -elif table==[[0,1], - [0,1]]: - ans=[ [table[0][1],table[1][1]] ] - -elif table==[[0,1], - [1,1]]: - ans=[ [table[0][1],table[1][1]], [table[1][0],table[1][1]] ] - -elif table==[[0,1], - [1,0]]: - ans=[ [table[0][1]], [table[1][0]] ] - -elif table==[[1,0], - [0,0]]: - ans=[[table[0][0]]] - -elif table==[[1,0], - [0,1]]: - ans=[ [table[0][0]], [table[1][1]] ] - -elif table==[[1,0], - [1,0]]: - ans=[ [table[0][0],table[0][1]] ] - -elif table==[[1,0], - [1,1]]: - ans=[ [table[0][0],table[1][0]], [table[1][0],table[1][1]] ] - -elif table==[[1,1], - [0,0]]: - ans=[ [table[0][0],table[0][1]] ] - -elif table==[[1,1], - [0,1]]: - ans=[ [table[0][0],table[0][1]], [table[0][1],table[1][1]] ] - -elif table==[[1,1], - [1,0]]: - ans=[ [table[0][0],table[0][1]], [table[0][0],table[1][0]] ] - -elif table==[[1,1], - [1,1]]: - list=[ [table[0][0],table[0][1],table[1][0],table[1][1]] ] - -print(ans) \ No newline at end of file +def get_2by2(table): + ans = [] + + if table == [[0, 0], + [0, 0]]: + ans = [] + + elif table == [[0, 0], + [0, 1]]: + ans = [[table[1][1]]] + + elif table == [[0, 0], + [1, 0]]: + ans = [[table[1][0]]] + + elif table == [[0, 0], + [1, 1]]: + ans = [[table[1][0], table[1][1]]] + + elif table == [[0, 1], + [0, 0]]: + ans = [[table[0][1]]] + + elif table == [[0, 1], + [0, 1]]: + ans = [[table[0][1], table[1][1]]] + + elif table == [[0, 1], + [1, 1]]: + ans = [[table[0][1], table[1][1]], [table[1][0], table[1][1]]] + + elif table == [[0, 1], + [1, 0]]: + ans = [[table[0][1]], [table[1][0]]] + + elif table == [[1, 0], + [0, 0]]: + ans = [[table[0][0]]] + + elif table == [[1, 0], + [0, 1]]: + ans = [[table[0][0]], [table[1][1]]] + + elif table == [[1, 0], + [1, 0]]: + ans = [[table[0][0], table[0][1]]] + + elif table == [[1, 0], + [1, 1]]: + ans = [[table[0][0], table[1][0]], [table[1][0], table[1][1]]] + + elif table == [[1, 1], + [0, 0]]: + ans = [[table[0][0], table[0][1]]] + + elif table == [[1, 1], + [0, 1]]: + ans = [[table[0][0], table[0][1]], [table[0][1], table[1][1]]] + + elif table == [[1, 1], + [1, 0]]: + ans = [[table[0][0], table[0][1]], [table[0][0], table[1][0]]] + + elif table == [[1, 1], + [1, 1]]: + ans = [[table[0][0], table[0][1], table[1][0], table[1][1]]] + + return ans + +print(get_2by2([[0,1],[1,1]])) + + From 9af8dcaccec2202b60d86e060110f04eb19c11c4 Mon Sep 17 00:00:00 2001 From: JeongyunBAE Date: Tue, 31 May 2022 22:01:14 +0900 Subject: [PATCH 33/42] K_map_complete_2_3_4_var.py --- .idea/misc.xml | 4 - jeongyun.py | 596 +++++++++++++++++++++++++++++++++++++++++++++++++ kmap_3 | 0 3 files changed, 596 insertions(+), 4 deletions(-) delete mode 100644 .idea/misc.xml create mode 100644 jeongyun.py create mode 100644 kmap_3 diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 35a08cf..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/jeongyun.py b/jeongyun.py new file mode 100644 index 0000000..2681ae9 --- /dev/null +++ b/jeongyun.py @@ -0,0 +1,596 @@ +# K_Map for 2 inputs. +def inp2_k_map(mt, nip): + for i in range(50): print("-", end='') + print() + prnt = input("Enter Variables with single space(eg:A B) : ").split(" ") + for i in range(len(mt)): + mt[i] = '0b' + bin(mt[i])[2:].lstrip('0') + op = '' + ans = [[0, 0], [0, 0]] + ansmx = [[0, 0], [0, 0]] + flag = 0 + temp = [] + for i in range(2): + for j in range(2): + p = '0b' + (bin(i)[2:] + bin(j)[2:]).lstrip('0') + if p in mt: + ans[i][j] = 1 + for i in range(50): print("-", end='') + print() + print("The kmap plotted : ") + if nip == 1: + for each in ans: print(*each) + elif nip == 2: + for i in range(2): + for j in range(2): + if ans[i][j] == 1: + ansmx[i][j] = 0 + else: + ansmx[i][j] = 1 + for each in ansmx: print(*each) + if ans == [[1, 1], [1, 1]]: + flag = 1 + op = '1' + + if flag == 0: + for i in range(2): + if ans[i] == [1, 1]: + if nip == 1: + op = 'A ' if i == 1 else "A' " + elif nip == 2: + op = "(A') " if i == 1 else "(A) " + temp.extend([(i, 0), (i, 1)]) + + if flag == 0: + if ans[0][0] == 1 and ans[1][0] == 1: + if nip == 1: + op = op + "B' " + elif nip == 2: + op = op + "(B) " + temp.extend([(0, 0), (1, 0)]) + elif ans[0][1] == 1 and ans[1][1] == 1: + if nip == 1: + op = op + "B " + elif nip == 2: + op = op + "(B') " + temp.extend([(0, 1), (1, 1)]) + if nip == 1: + vr = ["A'B' ", "A'B ", "AB' ", "AB "] + elif nip == 2: + vr = ["(A+B) ", "(A+B') ", "(A'+B) ", "(A'+B') "] + + if flag == 0: + for i in range(2): + for j in range(2): + if ans[i][j] == 1 and (i, j) not in temp: + op = op + vr[int('0b' + bin(i)[2:] + bin(j)[2:], 2)] + op = op.rstrip(" ") + if nip == 1: + op = op.replace(" ", "+") + op = op.replace("A", prnt[0]) + op = op.replace("B", prnt[1]) + for i in range(50): print("*", end='') + print() + print("The simplified equation is :", op) + for i in range(50): print("*", end='') + print() + + +# K_Map for 4 inputs. +def inp4_k_map(mt, nip): + import copy + for _ in range(50): print("-", end='') + print() + pr_v = input("Enter variables single space(eg:A B C D) : ").split(" ") + an = [] + anmx = [] + (tmp, flag) = (0, 0) + op = '' + for i in range(4): + an.append([0] * 4) + anmx.append([0] * 4) + + for i in range(4): + for j in range(4): + if i < 2: + bi = '0' + bin(i)[2:] + else: + bi = bin(i)[2:] + if j < 2: + bj = '0' + bin(j)[2:] + else: + bj = bin(j)[2:] + p = int('0b' + bi + bj, 2) + if p in mt: + an[i][j] = 1 + for i in range(4): + (an[i][2], an[i][3]) = (an[i][3], an[i][2]) + for i in range(4): + (an[2][i], an[3][i]) = (an[3][i], an[2][i]) + + for _ in range(50): print("-", end='') + print() + print("The K-Map plotted : ") + if nip == 1: + for each in an: + print(*each) + elif nip == 2: + for i in range(4): + for j in range(4): + if an[i][j] == 1: + anmx[i][j] = 0 + else: + anmx[i][j] = 1 + for each in anmx: print(*each) + + octa = [] + qrd = [] + qrd_ref = [] + qrd_rep = [] + dul = [] + sngl = [] + if nip == 1: + octa_val = [["C' ", "D ", "C ", "D' "], ["A' ", "B ", "A ", "B' "]] # 0 for vert and 1 for horz + qrd_val = [["C'D' ", "C'D ", "CD ", "CD' "], ["A'B' ", "A'B ", "AB ", "AB' "]] # 0 for vert and 1 for horz + qrd_val_4 = [["A'C' ", "A'D ", "A'C ", "A'D' "], ["BC' ", "BD ", "BC ", "BD' "], ["AC' ", "AD ", "AC ", "AD' "], + ["B'C' ", "B'D ", "B'C ", "B'D' "]] + dul_vert = [["A'C'D' ", "A'C'D ", "A'CD ", "A'CD' "], ["BC'D' ", "BC'D ", "BCD ", "BCD' "], + ["AC'D' ", "AC'D ", "ACD ", "ACD' "], ["B'C'D' ", "B'C'D ", "B'CD ", "B'CD' "]] + dul_horz = [["A'B'C' ", "A'B'D ", "A'B'C ", "A'B'D' "], ["A'BC' ", "A'BD ", "A'BC ", "A'BD' "], + ["ABC' ", "ABD ", "ABC ", "ABD' "], ["AB'C' ", "AB'D ", "AB'C ", "AB'D' "]] + sngl_val = [["A'B'C'D' ", "A'B'C'D ", "A'B'CD ", "A'B'CD' "], ["A'BC'D' ", "A'BC'D ", "A'BCD ", "A'BCD' "], + ["ABC'D' ", "ABC'D ", "ABCD ", "ABCD' "], ["AB'C'D' ", "AB'C'D ", "AB'CD ", "AB'CD' "]] + elif nip == 2: + octa_val = [["(C) ", "(D') ", "(C') ", "(D) "], ["(A) ", "(B') ", "(A') ", "(B) "]] # 0 for vert and 1 for horz + qrd_val = [["(C+D) ", "(C+D') ", "(C'+D') ", "(C'+D) "], + ["(A+B) ", "(A+B') ", "(A'+B') ", "(A'+B) "]] # 0 for vert and 1 for horz + qrd_val_4 = [["(A+C) ", "(A+D') ", "(A+C') ", "(A+D) "], ["(B'+C) ", "(B'+D') ", "(B'+C') ", "(B'+D) "], + ["(A'+C) ", "(A'+D') ", "(A'+C') ", "(A'+D) "], ["(B+C) ", "(B+D') ", "(B+C') ", "(B+D) "]] + dul_vert = [["(A+C+D) ", "(A+C+D') ", "(A+C'+D') ", "(A+C'+D) "], + ["(B'+C+D) ", "(B'+C+D') ", "(B'+C'+D') ", "(B'+C'+D) "], + ["(A'+C+D) ", "(A'+C+D') ", "(A'+C'+D') ", "(A'+C'+D) "], + ["(B+C+D) ", "(B+C+D') ", "(B+C'+D') ", "(B+C'+D) "]] + dul_horz = [["(A+B+C) ", "(A+B+D') ", "(A+B+C') ", "(A+B+D) "], + ["(A+B'+C) ", "(A+B'+D') ", "(A+B'+C') ", "(A+B'+D) "], + ["(A'+B'+C) ", "(A'+B'+D') ", "(A'+B'+C') ", "(A'+B'+D) "], + ["(A'+B+C) ", "(A'+B+D') ", "(A'+B+C') ", "(A'+B+D) "]] + sngl_val = [["(A+B+C+D) ", "(A+B+C+D') ", "(A+B+C'+D') ", "(A+B+C'+D) "], + ["(A+B'+C+D) ", "(A+B'+C+D') ", "(A+B'+C'+D') ", "(A+B'+C'+D) "], + ["(A'+B'+C+D) ", "(A'+B'+C+D') ", "(A'+B'+C'+D') ", "(A'+B'+C'+D) "], + ["(A'+B+C+D) ", "(A'+B+C+D') ", "(A'+B+C'+D') ", "(A'+B+C'+D) "]] + + if an == [[1] * 4, [1] * 4, [1] * 4, [1] * 4]: + op = '1' + else: + for i in range(-1, 3): + if an[i][0] == 1 and an[i][1] == 1 and an[i][2] == 1 and an[i][-1] == 1 and an[i + 1][0] == 1 and an[i + 1][ + 1] == 1 and an[i + 1][2] == 1 and an[i + 1][-1] == 1: + op = op + octa_val[1][i] + octa.append([(i, 0), (i, 1), (i, 2), (i, -1)]) + if i < 2: + octa.append([(i + 1, 0), (i + 1, 1), (i + 1, 2), (i + 1, -1)]) + else: + octa.append([(-1, 0), (-1, 1), (-1, 2), (-1, -1)]) + if i < 2: + octa.append([(i, 0), (i + 1, 0), (i, 1), (i + 1, 1)]) + octa.append([(i, 1), (i + 1, 1), (i, 2), (i + 1, 2)]) + octa.append([(i, 2), (i + 1, 2), (i, -1), (i + 1, -1)]) + octa.append([(i, -1), (i + 1, -1), (i, 0), (i + 1, 0)]) + else: + octa.append([(i, 0), (-1, 0), (i, 1), (-1, 1)]) + octa.append([(i, 1), (-1, 1), (i, 2), (-1, 2)]) + octa.append([(i, 2), (-1, 2), (i, -1), (-1, -1)]) + octa.append([(i, -1), (-1, -1), (i, 0), (-1, 0)]) + + for i in range(-1, 3): + if an[0][i] == 1 and an[1][i] == 1 and an[2][i] == 1 and an[-1][i] == 1 and an[0][i + 1] == 1 and an[1][ + i + 1] == 1 and an[2][i + 1] == 1 and an[-1][i + 1] == 1: + op = op + octa_val[0][i] + octa.append([(0, i), (1, i), (2, i), (-1, i)]) + if i < 2: + octa.append([(0, i + 1), (1, i + 1), (2, i + 1), (-1, i + 1)]) + else: + octa.append([(0, -1), (1, -1), (2, -1), (-1, -1)]) + if i < 2: + octa.append([(0, i), (1, i), (0, i + 1), (1, i + 1)]) + octa.append([(1, i), (2, i), (1, i + 1), (2, i + 1)]) + octa.append([(2, i), (-1, i), (2, i + 1), (-1, i + 1)]) + octa.append([(-1, i), (0, i), (-1, i + 1), (0, i + 1)]) + else: + octa.append([(0, i), (1, i), (0, -1), (1, -1)]) + octa.append([(1, i), (2, i), (1, -1), (2, -1)]) + octa.append([(2, i), (-1, i), (2, -1), (-1, -1)]) + octa.append([(-1, i), (0, i), (-1, -1), (0, -1)]) + + for i in range(-1, 3): + if an[i][0] == 1 and an[i][1] == 1 and an[i][2] == 1 and an[i][-1] == 1: + qrd_ref.append([(i, 0), (i, 1), (i, 2), (i, -1)]) + if an[0][i] == 1 and an[1][i] == 1 and an[2][i] == 1 and an[-1][i] == 1: + qrd_ref.append([(0, i), (1, i), (2, i), (-1, i)]) + + for i in range(-1, 3): + for j in range(-1, 3): + if an[i][j] == 1 and an[i][j + 1] == 1 and an[i + 1][j] == 1 and an[i + 1][j + 1] == 1: + if i == 2 and j == 2: + temp = [(i, j), (-1, j), (i, -1), (-1, -1)] + elif i == 2 and j < 2: + temp = [(i, j), (-1, j), (i, j + 1), (-1, j + 1)] + elif j == 2 and i < 2: + temp = [(i, j), (i + 1, j), (i, -1), (i + 1, -1)] + else: + temp = [(i, j), (i + 1, j), (i, j + 1), (i + 1, j + 1)] + qrd_ref.append(temp) + + for i in range(-1, 3): + if an[i][0] == 1 and an[i][1] == 1 and an[i][2] == 1 and an[i][-1] == 1: + if [(i, 0), (i, 1), (i, 2), (i, -1)] not in octa: + op = op + qrd_val[1][i] + qrd.append([(i, 0), (i, 1)]) + qrd.append([(i, 1), (i, 2)]) + qrd.append([(i, 2), (i, -1)]) + qrd.append([(i, -1), (i, 0)]) + + for i in range(-1, 3): + if an[0][i] == 1 and an[1][i] == 1 and an[2][i] == 1 and an[-1][i] == 1: + if [(0, i), (1, i), (2, i), (-1, i)] not in octa: + op = op + qrd_val[0][i] + qrd.append([(0, i), (1, i)]) + qrd.append([(1, i), (2, i)]) + qrd.append([(2, i), (-1, i)]) + qrd.append([(-1, i), (0, i)]) + + for i in range(-1, 3): + for j in range(-1, 3): + if an[i][j] == 1 and an[i][j + 1] == 1 and an[i + 1][j] == 1 and an[i + 1][j + 1] == 1: + if i == 2 and j == 2: + temp = [(i, j), (-1, j), (i, -1), (-1, -1)] + elif i == 2 and j < 2: + temp = [(i, j), (-1, j), (i, j + 1), (-1, j + 1)] + elif j == 2 and i < 2: + temp = [(i, j), (i + 1, j), (i, -1), (i + 1, -1)] + else: + temp = [(i, j), (i + 1, j), (i, j + 1), (i + 1, j + 1)] + if temp not in octa: + op = op + qrd_val_4[i][j] + if i < 2 and j < 2: + qrd.append([(i, j), (i, j + 1)]) + qrd.append([(i + 1, j), (i + 1, j + 1)]) + qrd.append([(i, j), (i + 1, j)]) + qrd.append([(i, j + 1), (i + 1, j + 1)]) + if j == 2 and i < 2: + qrd.append([(i, j), (i, -1)]) + qrd.append([(i + 1, j), (i + 1, -1)]) + qrd.append([(i, j), (i + 1, j)]) + qrd.append([(i, -1), (i + 1, -1)]) + if j < 2 and i == 2: + qrd.append([(i, j), (i, j + 1)]) + qrd.append([(-1, j), (-1, j + 1)]) + qrd.append([(i, j), (-1, j)]) + qrd.append([(i, j + 1), (-1, j + 1)]) + if i == 2 and j == 2: + qrd.append([(i, j), (i, -1)]) + qrd.append([(-1, j), (-1, -1)]) + qrd.append([(i, j), (-1, j)]) + qrd.append([(i, -1), (-1, -1)]) + + for i in range(-1, 3): + for j in range(-1, 3): + if an[i][j] == 1 and an[i][j + 1] == 1: + if j == 2: + temp = [(i, j), (i, -1)] + else: + temp = [(i, j), (i, j + 1)] + if temp not in qrd: + op = op + dul_horz[i][j] + if j == 2: + dul.append([(i, j), (i, -1)]) + else: + dul.append([(i, j), (i, j + 1)]) + if an[i][j] == 1 and an[i + 1][j] == 1: + if i == 2: + temp = [(i, j), (-1, j)] + else: + temp = [(i, j), (i + 1, j)] + if temp not in qrd: + op = op + dul_vert[i][j] + if i == 2: + dul.append([(i, j), (-1, j)]) + else: + dul.append([(i, j), (i + 1, j)]) + + for each in octa: + sngl.extend(each) + for each in qrd: + sngl.extend(each) + for each in dul: + sngl.extend(each) + for i in range(-1, 3): + for j in range(-1, 3): + if an[i][j] == 1: + if (i, j) not in sngl: + op = op + sngl_val[i][j] + + op = op.strip() + opl = op.split(" ") + for i in range(len(opl)): + opl[i] = opl[i] + " " + + dulref = copy.deepcopy(dul) + + for each in dul: + (d1, d2) = (each[0], each[1]) + (cntd1, cntd2) = (0, 0) + for each in dulref: + if d1 in each: + cntd1 += 1 + if d2 in each: + cntd2 += 1 + for each in qrd_ref: + if d1 in each: + cntd1 += 1 + if d2 in each: + cntd2 += 1 + if cntd1 > 1 and cntd2 > 1: + try: + if d1[0] == d2[0]: + opl.remove(dul_horz[d1[0]][d1[1]]) + if d1[1] == d2[1]: + opl.remove(dul_vert[d1[0]][d1[1]]) + dulref.remove([(d1[0], d1[1]), (d2[0], d2[1])]) + except ValueError: + continue + + for each in qrd_ref: + (d1, d2, d3, d4) = (each[0], each[1], each[2], each[3]) + (d1cnt, d2cnt, d3cnt, d4cnt) = (0, 0, 0, 0) + for each1 in dul: + if d1 in each1: + d1cnt += 1 + if d2 in each1: + d2cnt += 1 + if d3 in each1: + d3cnt += 1 + if d4 in each1: + d4cnt += 1 + for each2 in qrd_ref: + if each != each2: + if d1 in each2: + d1cnt += 1 + if d2 in each2: + d2cnt += 1 + if d3 in each2: + d3cnt += 1 + if d4 in each2: + d4cnt += 1 + if d1cnt > 0 and d2cnt > 0 and d3cnt > 0 and d4cnt > 0: + try: + if d1[0] != d2[0] and d1[1] != d3[1]: + opl.remove(qrd_val_4[d1[0]][d1[1]]) + except ValueError: + continue + + for each in qrd_ref: + (d1, d2, d3, d4) = (each[0], each[1], each[2], each[3]) + (d1cnt, d2cnt, d3cnt, d4cnt) = (0, 0, 0, 0) + for each1 in qrd_ref: + if each1 != each: + if d1 in each1: + d1cnt += 1 + if d2 in each1: + d2cnt += 1 + if d3 in each1: + d3cnt += 1 + if d4 in each1: + d4cnt += 1 + if d1cnt > 0 and d2cnt > 0 and d3cnt > 0 and d4cnt > 0: + try: + if d1[0] == d2[0] == d3[0] == d4[0]: + opl.remove(qrd_val[1][d1[0]]) + elif d1[1] == d2[1] == d3[1] == d4[1]: + opl.remove(qrd_val[0][d1[1]]) + except ValueError: + continue + + op = ''.join(opl) + for _ in range(50): print("*", end='') + print() + op = op.strip(" ") + if nip == 1: + op = op.replace(" ", " + ") + op = op.replace("A", pr_v[0]) + op = op.replace("B", pr_v[1]) + op = op.replace("C", pr_v[2]) + op = op.replace("D", pr_v[3]) + print("Simplified equation is :", op) + + for _ in range(50): print("*", end='') + print() + + +# K_Map for 3 inputs. +def inp3_k_map(mt, nip): + for i in range(50): print("-", end='') + print() + var_re = input("Enter variables with single space(eg:A B C) : ").split(" ") + ansg = [[0, 0, 0, 0], [0, 0, 0, 0]] + ansgmx = [[0, 0, 0, 0], [0, 0, 0, 0]] + op = '' + flag = 0 + qrd = [] + dul = [] + sngl = [] + if nip == 1: + qrd_var_2_2 = ["B' ", "C ", "B ", "C' "] + qrd_var_1_4 = ["A' ", "A "] + dul_vert = ["B'C' ", "B'C ", "BC ", "BC' "] + dul_horz = [["A'B' ", "A'C ", "A'B ", "A'C' "], ["AB' ", "AC ", "AB ", "AC'"]] + sngl_val = [["A'B'C' ", "A'B'C ", "A'BC ", "A'BC' "], ["AB'C' ", "AB'C ", "ABC ", "ABC' "]] + elif nip == 2: + qrd_var_2_2 = ["(B) ", "(C') ", "(B') ", "(C) "] + qrd_var_1_4 = ["(A) ", "(A') "] + dul_vert = ["(B+C) ", "(B+C') ", "(B'+C') ", "(B'+C) "] + dul_horz = [["(A+B) ", "(A+C') ", "(A+B') ", "(A+C) "], ["(A'+B) ", "(A'+C') ", "(A'+B') ", "(A'+C) "]] + sngl_val = [["(A+B+C) ", "(A+B+C') ", "(A+B'+C') ", "(A+B'+C) "], + ["(A'+B+C) ", "(A'+B+C') ", "(A'+B'+C') ", "(A'+B'+C) "]] + for i in range(2): + for j in range(4): + p = int('0b' + bin(i)[2:] + bin(j)[2:], 2) + if (i == 1) and (j == 0 or j == 1): + p = int('0b' + bin(i)[2:] + '0' + bin(j)[2:], 2) + if p in mt: + ansg[i][j] = 1 + + for i in range(2): + (ansg[i][2], ansg[i][3]) = (ansg[i][3], ansg[i][2]) + for i in range(50): print("-", end='') + print() + print("K-Map plotted : ") + if nip == 1: + for each in ansg: print(*each) + elif nip == 2: + for i in range(2): + for j in range(4): + if ansg[i][j] == 1: + ansgmx[i][j] = 0 + else: + ansgmx[i][j] = 1 + for each in ansgmx: print(*each) + + if ansg == [[1] * 4, [1] * 4]: + op = op + '1' + flag = 1 + if flag == 0: + for j in range(-1, 3): + if ansg[0][j] == 1 and ansg[-1][j] == 1 and ansg[0][j + 1] == 1 and ansg[-1][j + 1] == 1: + qrd.append([(0, j), (-1, j)]) + if j < 2: + qrd.append([(0, j + 1), (-1, j + 1)]) + qrd.append([(0, j), (0, j + 1)]) + qrd.append([(-1, j), (-1, j + 1)]) + else: + qrd.append([(0, -1), (-1, -1)]) + qrd.append([(0, j), (0, -1)]) + qrd.append([(-1, j), (-1, -1)]) + op = op + qrd_var_2_2[j] + if flag == 0: + for i in range(-1, 1): + if ansg[i] == [1, 1, 1, 1]: + qrd.append([(i, -1), (i, 0)]) + qrd.append([(i, 0), (i, 1)]) + qrd.append([(i, 1), (i, 2)]) + qrd.append([(i, 2), (i, -1)]) + op = op + qrd_var_1_4[i] + if flag == 0: + for j in range(-1, 3): + if ansg[0][j] == 1 and ansg[1][j] == 1: + temp = 0 + if [(0, j), (-1, j)] in qrd: + temp = 1 + elif [(-1, j), (0, j)] in qrd: + temp = 1 + if temp == 0: + dul.append([(0, j), (-1, j)]) + op = op + dul_vert[j] + + if flag == 0: + for i in range(-1, 1): + for j in range(-1, 3): + if ansg[i][j] == 1 and ansg[i][j + 1] == 1: + temp = 0 + if j == 2: + if [(i, j), (i, -1)] in qrd: + temp = 1 + elif [(i, -1), (i, j)] in qrd: + temp = 1 + else: + if [(i, j), (i, j + 1)] in qrd: + temp = 1 + elif [(i, j + 1), (i, j)] in qrd: + temp = 1 + if temp == 0: + if j == 2: + dul.append([(i, 2), (i, -1)]) + else: + dul.append([(i, j), (i, j + 1)]) + op = op + dul_horz[i][j] + + op = op.rstrip(" ") + opl = op.split(" ") + for i in range(len(opl)): + opl[i] = opl[i] + " " + + for each in dul: + d1cnt = 0 + d2cnt = 0 + (d1, d2) = (each[0], each[1]) + for each1 in dul: + if d1 in each1: + d1cnt += 1 + if d2 in each1: + d2cnt += 1 + if d1cnt > 1 and d2cnt > 1: + (d1i, d1j) = d1 + (d2i, d2j) = d2 + if d1i == d2i: + p = dul_horz[d1i][d1j] + opl.remove(p) + else: + p = dul_vert[d1j] + opl.remove(p) + dul.remove([d1, d2]) + op = "".join(opl) + + for _ in qrd: + for each in _: + sngl.append(each) + for _ in dul: + for each in _: + sngl.append(each) + + if flag == 0: + for i in range(-1, 1): + for j in range(-1, 3): + if ansg[i][j] == 1: + if (i, j) not in sngl: + op = op + sngl_val[i][j] + + op = op.rstrip(" ") + if nip == 1: + op = op.replace(' ', ' + ') + + op = op.replace("A", var_re[0]) + op = op.replace("B", var_re[1]) + op = op.replace("C", var_re[2]) + for i in range(50): print("*", end='') + print() + print("The simplified equation is :", op) + for i in range(50): print("*", end='') + print() + + +# main +ask = 'y' +while ask == 'y': + for _ in range(50): print("-", end='') + print() + nfinp = int(input("Enter no of Inputs(2,3,4) : ")) + mimastr = input("Enter 'SOP' for SOP(Minterms) or 'POS' for POS(Maxterms) : ").lower() + if mimastr == 'pos': + mima = 2 + elif mimastr == 'sop': + mima = 1 + if mima == 1: + mt = list(map(int, input("Enter Minterms : ").split())) + else: + mt = list(map(int, input("Enter Maxterms : ").split())) + if nfinp == 2: + inp2_k_map(mt, mima) + elif nfinp == 3: + inp3_k_map(mt, mima) + elif nfinp == 4: + inp4_k_map(mt, mima) + else: + print("You committed some mistake, please check the inputs next time.") + ask = input("Enter 'y' for another K-Map or 'n' to exit : ").lower() + for i in range(25): print("--", end='') + print() \ No newline at end of file diff --git a/kmap_3 b/kmap_3 new file mode 100644 index 0000000..e69de29 From 046e64ab3a76cbb35909af5ab705d302e79522bd Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 22:12:38 +0900 Subject: [PATCH 34/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sukyoung.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/sukyoung.py b/sukyoung.py index 5ebe750..aec83f9 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -7,66 +7,67 @@ def get_2by2(table): elif table == [[0, 0], [0, 1]]: - ans = [[table[1][1]]] + ans = [[1, 1]] elif table == [[0, 0], [1, 0]]: - ans = [[table[1][0]]] + ans = [[1, 0]] elif table == [[0, 0], [1, 1]]: - ans = [[table[1][0], table[1][1]]] + ans = [[1, 0], [1, 1]] elif table == [[0, 1], [0, 0]]: - ans = [[table[0][1]]] + ans = [[0, 1]] elif table == [[0, 1], [0, 1]]: - ans = [[table[0][1], table[1][1]]] + ans = [[0, 1], [1, 1]] elif table == [[0, 1], [1, 1]]: - ans = [[table[0][1], table[1][1]], [table[1][0], table[1][1]]] + ans = [[[0, 1], [1, 1]], [[1, 0], [1, 1]]] elif table == [[0, 1], [1, 0]]: - ans = [[table[0][1]], [table[1][0]]] + ans = [[[0, 1]], [[1, 0]]] elif table == [[1, 0], [0, 0]]: - ans = [[table[0][0]]] + ans = [[0, 0]] elif table == [[1, 0], [0, 1]]: - ans = [[table[0][0]], [table[1][1]]] + ans = [[[0, 0]], [[1, 1]]] elif table == [[1, 0], [1, 0]]: - ans = [[table[0][0], table[0][1]]] + ans = [[0, 0], [1, 0]] elif table == [[1, 0], [1, 1]]: - ans = [[table[0][0], table[1][0]], [table[1][0], table[1][1]]] + ans = [[[0, 0], [1, 0]], [[1, 0], [1, 1]]] elif table == [[1, 1], [0, 0]]: - ans = [[table[0][0], table[0][1]]] + ans = [[0, 0], [0, 1]] elif table == [[1, 1], [0, 1]]: - ans = [[table[0][0], table[0][1]], [table[0][1], table[1][1]]] + ans = [[[0, 0], [0, 1]], [[0, 1], [1, 1]]] elif table == [[1, 1], [1, 0]]: - ans = [[table[0][0], table[0][1]], [table[0][0], table[1][0]]] + ans = [[0, 0], [0, 1], [1, 0], [1, 1]] elif table == [[1, 1], [1, 1]]: - ans = [[table[0][0], table[0][1], table[1][0], table[1][1]]] + ans = [[0, 0], [0, 1], [1, 0], [1, 1]] return ans -print(get_2by2([[0,1],[1,1]])) +print(get_2by2([[0,1], + [0,1]])) From a981f4765950145e966ede1d2eddc439ca6b7835 Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 22:14:36 +0900 Subject: [PATCH 35/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sukyoung.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sukyoung.py b/sukyoung.py index aec83f9..b718e3d 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -67,6 +67,7 @@ def get_2by2(table): return ans + print(get_2by2([[0,1], [0,1]])) From d52d642207df8317bb30b2960ab16c035d335a16 Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 22:17:29 +0900 Subject: [PATCH 36/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sukyoung.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sukyoung.py b/sukyoung.py index b718e3d..3e9afc3 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -3,27 +3,27 @@ def get_2by2(table): if table == [[0, 0], [0, 0]]: - ans = [] + ans = [[[]]] elif table == [[0, 0], [0, 1]]: - ans = [[1, 1]] + ans = [[[1, 1]]] elif table == [[0, 0], [1, 0]]: - ans = [[1, 0]] + ans = [[[1, 0]]] elif table == [[0, 0], [1, 1]]: - ans = [[1, 0], [1, 1]] + ans = [[[1, 0], [1, 1]]] elif table == [[0, 1], [0, 0]]: - ans = [[0, 1]] + ans = [[[0, 1]]] elif table == [[0, 1], [0, 1]]: - ans = [[0, 1], [1, 1]] + ans = [[[0, 1], [1, 1]]] elif table == [[0, 1], [1, 1]]: @@ -35,7 +35,7 @@ def get_2by2(table): elif table == [[1, 0], [0, 0]]: - ans = [[0, 0]] + ans = [[[0, 0]]] elif table == [[1, 0], [0, 1]]: @@ -43,7 +43,7 @@ def get_2by2(table): elif table == [[1, 0], [1, 0]]: - ans = [[0, 0], [1, 0]] + ans = [[[0, 0], [1, 0]]] elif table == [[1, 0], [1, 1]]: @@ -51,7 +51,7 @@ def get_2by2(table): elif table == [[1, 1], [0, 0]]: - ans = [[0, 0], [0, 1]] + ans = [[[0, 0], [0, 1]]] elif table == [[1, 1], [0, 1]]: @@ -59,11 +59,11 @@ def get_2by2(table): elif table == [[1, 1], [1, 0]]: - ans = [[0, 0], [0, 1], [1, 0], [1, 1]] + ans = [[[0, 0], [0, 1]], [[0, 0], [0, 1]]] elif table == [[1, 1], [1, 1]]: - ans = [[0, 0], [0, 1], [1, 0], [1, 1]] + ans = [[[0, 0], [0, 1], [1, 0], [1, 1]]] return ans From 171974144ca5c4d5063a7551885c072a6accdf06 Mon Sep 17 00:00:00 2001 From: quartz0516 Date: Tue, 31 May 2022 22:19:51 +0900 Subject: [PATCH 37/42] =?UTF-8?q?=EB=85=B8=EA=B0=80=EB=8B=A4=20=ED=96=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sukyoung.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sukyoung.py b/sukyoung.py index 3e9afc3..618d464 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -59,7 +59,7 @@ def get_2by2(table): elif table == [[1, 1], [1, 0]]: - ans = [[[0, 0], [0, 1]], [[0, 0], [0, 1]]] + ans = [[[0, 0], [0, 1]], [[0, 0], [1, 0]]] elif table == [[1, 1], [1, 1]]: @@ -68,7 +68,7 @@ def get_2by2(table): return ans -print(get_2by2([[0,1], - [0,1]])) +print(get_2by2([[0,0], + [0,0]])) From 94ddbc26e101618f51c43fda019b547473198e34 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Wed, 1 Jun 2022 18:09:12 +0900 Subject: [PATCH 38/42] Almost end --- GUI.py | 4 +- INTERACTION.py | 34 +++-- LAST_RESORT.py | 332 +++++++++++++++++++++++++++++++++++++++---------- sukyoung.py | 36 +++--- 4 files changed, 309 insertions(+), 97 deletions(-) diff --git a/GUI.py b/GUI.py index 0e2a16e..bf9e1cd 100644 --- a/GUI.py +++ b/GUI.py @@ -93,8 +93,8 @@ def ShowTable(self, cell_color): def ShowDecisionPage(self, cell_color, start_position): # print('decision page') - for i in range(1, 5): - adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 6*self.cell_size/2, + for i in range(1, 4): + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2, start_position[1] - self.cell_size) pygame.draw.rect(self.screen, color[cell_color], (adjust_position[0], diff --git a/INTERACTION.py b/INTERACTION.py index bc246e5..18be7fe 100644 --- a/INTERACTION.py +++ b/INTERACTION.py @@ -1,10 +1,6 @@ from GUI import Screen, pygame, sys, color -# import pygame -# import sys - - class Interaction(Screen): """ Responsibility on Interaction with User @@ -25,8 +21,8 @@ def MouseClick(self, table_position): def GetDecision(self, start_position): (mouseX, mouseY) = pygame.mouse.get_pos() - for i in range(1, 5): - adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 6 * self.cell_size / 2, + for i in range(1, 4): + adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5 * self.cell_size / 2, start_position[1] - self.cell_size) if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size: return i + 1 @@ -54,7 +50,7 @@ def IsEvent(self, mode, start_position, event_list): self.GetInput(start_position) # return self.MouseClick(start_position) - def BackButton(self, sc_type): + def BackButton(self): # print('show back button') pygame.draw.rect(self.screen, color['black'], (30, @@ -68,6 +64,23 @@ def BackButton(self, sc_type): (30 + self.cell_size / 2 - 10, 30 + self.cell_size / 2 - 10) )) + def AnswerButton(self, event_list_ans): + pygame.draw.rect(self.screen, color['black'], + (self.screen_size[0] - 230, + self.screen_size[1] - 100, + 190, + 60), + self.cell_border) + self.ShowText("Answer", 60, 'black', (self.screen_size[0] - 230 + 10, self.screen_size[1] - 100 + 10)) + + for ans_event in event_list_ans: + if ans_event.type == pygame.MOUSEBUTTONDOWN: + (mouseX, mouseY) = pygame.mouse.get_pos() + if 0 < mouseX - (self.screen_size[0] - 230) < 190 and 0 < mouseY - (self.screen_size[1] - 100) < 60: + return True + + return False + if __name__ == '__main__': t = [ @@ -134,7 +147,12 @@ def BackButton(self, sc_type): a.table_size = (4, 4) screen_type = 'done' elif screen_type == 'done': - a.BackButton(screen_type) + a.BackButton() + input_done = a.AnswerButton(el) + if input_done: + # TODO: SHOW ANSWER + pass + stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0, a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2) diff --git a/LAST_RESORT.py b/LAST_RESORT.py index 3552f4c..fc3ea12 100644 --- a/LAST_RESORT.py +++ b/LAST_RESORT.py @@ -1,5 +1,5 @@ -# Quine McCluskey algorithm for minimizing logical expressions -# Author: Suman Adhikari + +from INTERACTION import Interaction, pygame, sys def mul(x,y): # Multiply 2 minterms res = [] @@ -86,70 +86,266 @@ def removeTerms(_chart,terms): # Removes minterms which are already covered from except KeyError: pass -mt = [int(i) for i in input("Enter the minterms: ").strip().split()] -dc = [int(i) for i in input("Enter the don't cares(If any): ").strip().split()] -mt.sort() -minterms = mt+dc -minterms.sort() -size = len(bin(minterms[-1]))-2 -groups,all_pi = {},set() - -# Primary grouping starts -for minterm in minterms: - try: - groups[bin(minterm).count('1')].append(bin(minterm)[2:].zfill(size)) - except KeyError: - groups[bin(minterm).count('1')] = [bin(minterm)[2:].zfill(size)] -# Primary grouping ends - -#Primary group printing starts -print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s"%('='*50)) -for i in sorted(groups.keys()): - print("%5d:"%i) # Prints group number - for j in groups[i]: - print("\t\t %-20d%s"%(int(j,2),j)) # Prints minterm and its binary representation - print('-'*50) -#Primary group printing ends - -# Process for creating tables and finding prime implicants starts + +####################################### + + +t = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] +] +a = Interaction((800, 800), t, (4, 4), 130, 3) +screen_type = 'decide' + while True: - tmp = groups.copy() - groups,m,marked,should_stop = {},0,set(),True - l = sorted(list(tmp.keys())) - for i in range(len(l)-1): - for j in tmp[l[i]]: # Loop which iterates through current group elements - for k in tmp[l[i+1]]: # Loop which iterates through next group elements - res = compare(j,k) # Compare the minterms - if res[0]: # If the minterms differ by 1 bit only - try: - groups[m].append(j[:res[1]]+'-'+j[res[1]+1:]) if j[:res[1]]+'-'+j[res[1]+1:] not in groups[m] else None # Put a '-' in the changing bit and add it to corresponding group - except KeyError: - groups[m] = [j[:res[1]]+'-'+j[res[1]+1:]] # If the group doesn't exist, create the group at first and then put a '-' in the changing bit and add it to the newly created group - should_stop = False - marked.add(j) # Mark element j - marked.add(k) # Mark element k - m += 1 - local_unmarked = set(flatten(tmp)).difference(marked) # Unmarked elements of each table - all_pi = all_pi.union(local_unmarked) # Adding Prime Implicants to global list - print("Unmarked elements(Prime Implicants) of this table:",None if len(local_unmarked)==0 else ', '.join(local_unmarked)) # Printing Prime Implicants of current table - if should_stop: # If the minterms cannot be combined further - print('--==-=-=-=-=-=123123123123123123123') - print(all_pi) - print('329875904238720398534523452849357092435') - - print("\n\nAll Prime Implicants: ",None if len(all_pi)==0 else ', '.join(all_pi)) # Print all prime implicants - break - # Printing of all the next groups starts - print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s"%('='*50)) - for i in sorted(groups.keys()): - print("%5d:"%i) # Prints group number - for j in groups[i]: - print("\t\t%-24s%s"%(','.join(findminterms(j)),j)) # Prints minterms and its binary representation - print('-'*50) - # Printing of all the next groups ends -# Process for creating tables and finding prime implicants ends - - -# Printing and processing of Prime Implicant chart starts -sz = len(str(mt[-1])) # The number of digits of the largest minterm -chart = {} + el = pygame.event.get() + + for end_event in el: + if end_event.type == pygame.QUIT: + print('program ended') + sys.exit() + a.ShowScreen('white') + + decision = 0 + if screen_type == 'decide': + a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1] / 2)) + decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1] / 2), el) + if decision is not None: + print(decision) + if decision != -1: + if decision == 2: + a.table = [ + [0, 0], + [0, 0] + ] + a.table_size = (2, 2) + if decision == 3: + a.table = [ + [0, 0], + [0, 0], + [0, 0], + [0, 0] + ] + a.table_size = (4, 2) + if decision == 4: + a.table = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] + a.table_size = (4, 4) + if decision == 5: + a.table = [ + [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ], + [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0] + ] + ] + a.table_size = (4, 4) + screen_type = 'done' + elif screen_type == 'done': + a.BackButton() + input_done = a.AnswerButton(el) + if input_done: + screen_type = 'answer' + continue + + stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0, + a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2) + + for back_event in el: + if back_event.type == pygame.MOUSEBUTTONDOWN: + (mx, my) = pygame.mouse.get_pos() + if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: + screen_type = 'decide' + decision = None + + a.IsEvent('table', stp, el) + a.ShowTable('black') + + elif screen_type == 'answer': + a.BackButton() + + for back_event in el: + if back_event.type == pygame.MOUSEBUTTONDOWN: + (mx, my) = pygame.mouse.get_pos() + if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: + screen_type = 'done' + + if a.table_size == (2, 2): + from sukyoung import get_2by2 + ans = get_2by2(a.table) + qwer = 0 + for asdf in ans: + a.ShowText(asdf, 50, 'black', (100, 100 + qwer * 40)) + qwer += 1 + print(ans) + continue + + mt = [] + + for i in range(a.table_size[0]): + for j in range(a.table_size[1]): + if a.table[i][j] == 1: + if i == 0 and j == 0: + mt.append(0) + if i == 0 and j == 1: + mt.append(4) + if i == 0 and j == 2: + mt.append(12) + if i == 0 and j == 3: + mt.append(8) + if i == 1 and j == 0: + mt.append(1) + if i == 1 and j == 1: + mt.append(5) + if i == 1 and j == 2: + mt.append(13) + if i == 1 and j == 3: + mt.append(9) + if i == 2 and j == 0: + mt.append(3) + if i == 2 and j == 1: + mt.append(7) + if i == 2 and j == 2: + mt.append(15) + if i == 2 and j == 3: + mt.append(11) + if i == 3 and j == 0: + mt.append(2) + if i == 3 and j == 1: + mt.append(6) + if i == 3 and j == 2: + mt.append(14) + if i == 3 and j == 3: + mt.append(10) + + dc = [] + mt.sort() + minterms = mt + dc + minterms.sort() + size = len(bin(minterms[-1])) - 2 + groups, all_pi = {}, set() + + # Primary grouping starts + for minterm in minterms: + try: + groups[bin(minterm).count('1')].append(bin(minterm)[2:].zfill(size)) + except KeyError: + groups[bin(minterm).count('1')] = [bin(minterm)[2:].zfill(size)] + # Primary grouping ends + + # Primary group printing starts + # print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s" % ('=' * 50)) + # for i in sorted(groups.keys()): + # print("%5d:" % i) # Prints group number + # for j in groups[i]: + # print("\t\t %-20d%s" % (int(j, 2), j)) # Prints minterm and its binary representation + # print('-' * 50) + # Primary group printing ends + + # Process for creating tables and finding prime implicants starts + while True: + tmp = groups.copy() + groups, m, marked, should_stop = {}, 0, set(), True + l = sorted(list(tmp.keys())) + for i in range(len(l) - 1): + for j in tmp[l[i]]: # Loop which iterates through current group elements + for k in tmp[l[i + 1]]: # Loop which iterates through next group elements + res = compare(j, k) # Compare the minterms + if res[0]: # If the minterms differ by 1 bit only + try: + groups[m].append(j[:res[1]] + '-' + j[res[1] + 1:]) if j[:res[1]] + '-' + j[res[ + 1] + 1:] not in \ + groups[ + m] else None # Put a '-' in the changing bit and add it to corresponding group + except KeyError: + groups[m] = [j[:res[1]] + '-' + j[res[ + 1] + 1:]] # If the group doesn't exist, create the group at first and then put a '-' in the changing bit and add it to the newly created group + should_stop = False + marked.add(j) # Mark element j + marked.add(k) # Mark element k + m += 1 + local_unmarked = set(flatten(tmp)).difference(marked) # Unmarked elements of each table + all_pi = all_pi.union(local_unmarked) # Adding Prime Implicants to global list + # print("Unmarked elements(Prime Implicants) of this table:", None if len(local_unmarked) == 0 else ', '.join( + # local_unmarked)) # Printing Prime Implicants of current table + if should_stop: # If the minterms cannot be combined further + # print('--==-=-=-=-=-=123123123123123123123') + print(all_pi) + + i = 0 + for answers in all_pi: + a.ShowText(answers, 50, 'black', (100, 150 + 50 * i)) + i += 1 + + # print('329875904238720398534523452849357092435') + + # print("\n\nAll Prime Implicants: ", + # None if len(all_pi) == 0 else ', '.join(all_pi)) # Print all prime implicants + break + # Printing of all the next groups starts + # print("\n\n\n\nGroup No.\tMinterms\tBinary of Minterms\n%s" % ('=' * 50)) + # for i in sorted(groups.keys()): + # print("%5d:" % i) # Prints group number + # for j in groups[i]: + # print( + # "\t\t%-24s%s" % (','.join(findminterms(j)), j)) # Prints minterms and its binary representation + # print('-' * 50) + # Printing of all the next groups ends + # Process for creating tables and finding prime implicants ends + + sz = len(str(mt[-1])) # The number of digits of the largest minterm + chart = {} + # print('\n\n\nPrime Implicants chart:\n\n Minterms |%s\n%s' % ( + # ' '.join((' ' * (sz - len(str(i)))) + str(i) for i in mt), '=' * (len(mt) * (sz + 1) + 16))) + for i in all_pi: + merged_minterms, y = findminterms(i), 0 + # print("%-16s|" % ','.join(merged_minterms), end='') + for j in refine(merged_minterms, dc): + x = mt.index(int(j)) * (sz + 1) # The position where we should put 'X' + # print(' ' * abs(x - y) + ' ' * (sz - 1) + 'X', end='') + y = x + sz + try: + chart[j].append(i) if i not in chart[j] else None # Add minterm in chart + except KeyError: + chart[j] = [i] + # print('\n' + '-' * (len(mt) * (sz + 1) + 16)) + # Printing and processing of Prime Implicant chart ends + + EPI = findEPI(chart) # Finding essential prime implicants + print("\nEssential Prime Implicants: " + ', '.join(str(i) for i in EPI)) + removeTerms(chart, EPI) # Remove EPI related columns from chart + + if (len(chart) == 0): # If no minterms remain after removing EPI related columns + final_result = [findVariables(i) for i in EPI] # Final result with only EPIs + else: # Else follow Petrick's method for further simplification + P = [[findVariables(j) for j in chart[i]] for i in chart] + while len(P) > 1: # Keep multiplying until we get the SOP form of P + P[1] = multiply(P[0], P[1]) + P.pop(0) + final_result = [min(P[0], key=len)] # Choosing the term with minimum variables from P + final_result.extend(findVariables(i) for i in EPI) # Adding the EPIs to final solution + print('\n\nSolution: F = ' + ' + '.join(''.join(i) for i in final_result)) + final_answer = 'Solution:' + ' + '.join(''.join(i) for i in final_result) + a.ShowText(final_answer, 50, 'black', (100, 100)) + + pygame.display.flip() + + + +############################### + + + diff --git a/sukyoung.py b/sukyoung.py index 618d464..5ebe750 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -3,72 +3,70 @@ def get_2by2(table): if table == [[0, 0], [0, 0]]: - ans = [[[]]] + ans = [] elif table == [[0, 0], [0, 1]]: - ans = [[[1, 1]]] + ans = [[table[1][1]]] elif table == [[0, 0], [1, 0]]: - ans = [[[1, 0]]] + ans = [[table[1][0]]] elif table == [[0, 0], [1, 1]]: - ans = [[[1, 0], [1, 1]]] + ans = [[table[1][0], table[1][1]]] elif table == [[0, 1], [0, 0]]: - ans = [[[0, 1]]] + ans = [[table[0][1]]] elif table == [[0, 1], [0, 1]]: - ans = [[[0, 1], [1, 1]]] + ans = [[table[0][1], table[1][1]]] elif table == [[0, 1], [1, 1]]: - ans = [[[0, 1], [1, 1]], [[1, 0], [1, 1]]] + ans = [[table[0][1], table[1][1]], [table[1][0], table[1][1]]] elif table == [[0, 1], [1, 0]]: - ans = [[[0, 1]], [[1, 0]]] + ans = [[table[0][1]], [table[1][0]]] elif table == [[1, 0], [0, 0]]: - ans = [[[0, 0]]] + ans = [[table[0][0]]] elif table == [[1, 0], [0, 1]]: - ans = [[[0, 0]], [[1, 1]]] + ans = [[table[0][0]], [table[1][1]]] elif table == [[1, 0], [1, 0]]: - ans = [[[0, 0], [1, 0]]] + ans = [[table[0][0], table[0][1]]] elif table == [[1, 0], [1, 1]]: - ans = [[[0, 0], [1, 0]], [[1, 0], [1, 1]]] + ans = [[table[0][0], table[1][0]], [table[1][0], table[1][1]]] elif table == [[1, 1], [0, 0]]: - ans = [[[0, 0], [0, 1]]] + ans = [[table[0][0], table[0][1]]] elif table == [[1, 1], [0, 1]]: - ans = [[[0, 0], [0, 1]], [[0, 1], [1, 1]]] + ans = [[table[0][0], table[0][1]], [table[0][1], table[1][1]]] elif table == [[1, 1], [1, 0]]: - ans = [[[0, 0], [0, 1]], [[0, 0], [1, 0]]] + ans = [[table[0][0], table[0][1]], [table[0][0], table[1][0]]] elif table == [[1, 1], [1, 1]]: - ans = [[[0, 0], [0, 1], [1, 0], [1, 1]]] + ans = [[table[0][0], table[0][1], table[1][0], table[1][1]]] return ans - -print(get_2by2([[0,0], - [0,0]])) +print(get_2by2([[0,1],[1,1]])) From 52cbff306aa58c900bed53cc43202690232ed7ee Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Wed, 1 Jun 2022 18:11:23 +0900 Subject: [PATCH 39/42] project almost end --- INTERACTION.py | 169 ++++++++++++++++++++++++------------------------- LAST_RESORT.py | 8 +-- 2 files changed, 88 insertions(+), 89 deletions(-) diff --git a/INTERACTION.py b/INTERACTION.py index 18be7fe..79678ca 100644 --- a/INTERACTION.py +++ b/INTERACTION.py @@ -82,88 +82,87 @@ def AnswerButton(self, event_list_ans): return False -if __name__ == '__main__': - t = [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0] - ] - a = Interaction((800, 800), t, (4, 4), 130, 3) - screen_type = 'decide' - - while True: - el = pygame.event.get() - - for end_event in el: - if end_event.type == pygame.QUIT: - print('program ended') - sys.exit() - a.ShowScreen('white') - - if screen_type == 'decide': - a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1] / 2)) - decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1] / 2), el) - if decision is not None: - print(decision) - if decision != -1: - if decision == 2: - a.table = [ - [0, 0], - [0, 0] - ] - a.table_size = (2, 2) - if decision == 3: - a.table = [ - [0, 0], - [0, 0], - [0, 0], - [0, 0] - ] - a.table_size = (4, 2) - if decision == 4: - a.table = [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0] - ] - a.table_size = (4, 4) - if decision == 5: - a.table = [ - [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0] - ], - [ - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 0, 0] - ] - ] - a.table_size = (4, 4) - screen_type = 'done' - elif screen_type == 'done': - a.BackButton() - input_done = a.AnswerButton(el) - if input_done: - # TODO: SHOW ANSWER - pass - - stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0, - a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2) - - for back_event in el: - if back_event.type == pygame.MOUSEBUTTONDOWN: - (mx, my) = pygame.mouse.get_pos() - if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: - screen_type = 'decide' - decision = None - - a.IsEvent('table', stp, el) - a.ShowTable('black') - - pygame.display.flip() +# if __name__ == '__main__': +# t = [ +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0] +# ] +# a = Interaction((800, 800), t, (4, 4), 130, 3) +# screen_type = 'decide' +# +# while True: +# el = pygame.event.get() +# +# for end_event in el: +# if end_event.type == pygame.QUIT: +# print('program ended') +# sys.exit() +# a.ShowScreen('white') +# +# if screen_type == 'decide': +# a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1] / 2)) +# decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1] / 2), el) +# if decision is not None: +# print(decision) +# if decision != -1: +# if decision == 2: +# a.table = [ +# [0, 0], +# [0, 0] +# ] +# a.table_size = (2, 2) +# if decision == 3: +# a.table = [ +# [0, 0], +# [0, 0], +# [0, 0], +# [0, 0] +# ] +# a.table_size = (4, 2) +# if decision == 4: +# a.table = [ +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0] +# ] +# a.table_size = (4, 4) +# if decision == 5: +# a.table = [ +# [ +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0] +# ], +# [ +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0], +# [0, 0, 0, 0] +# ] +# ] +# a.table_size = (4, 4) +# screen_type = 'done' +# elif screen_type == 'done': +# a.BackButton() +# input_done = a.AnswerButton(el) +# if input_done: +# pass +# +# stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0, +# a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2) +# +# for back_event in el: +# if back_event.type == pygame.MOUSEBUTTONDOWN: +# (mx, my) = pygame.mouse.get_pos() +# if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2: +# screen_type = 'decide' +# decision = None +# +# a.IsEvent('table', stp, el) +# a.ShowTable('black') +# +# pygame.display.flip() diff --git a/LAST_RESORT.py b/LAST_RESORT.py index fc3ea12..3296b69 100644 --- a/LAST_RESORT.py +++ b/LAST_RESORT.py @@ -285,10 +285,10 @@ def removeTerms(_chart,terms): # Removes minterms which are already covered from # print('--==-=-=-=-=-=123123123123123123123') print(all_pi) - i = 0 - for answers in all_pi: - a.ShowText(answers, 50, 'black', (100, 150 + 50 * i)) - i += 1 + # i = 0 + # for answers in all_pi: + # a.ShowText(answers, 50, 'black', (100, 150 + 50 * i)) + # i += 1 # print('329875904238720398534523452849357092435') From a81f240fea41b15b7ee975e439198f521e95e7e9 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Wed, 1 Jun 2022 18:24:00 +0900 Subject: [PATCH 40/42] ENDO --- sukyoung.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sukyoung.py b/sukyoung.py index 5ebe750..2ffe44c 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -7,7 +7,7 @@ def get_2by2(table): elif table == [[0, 0], [0, 1]]: - ans = [[table[1][1]]] + ans = [[[1, 1]]] elif table == [[0, 0], [1, 0]]: From fb88f67d30a88a46e47c315498cc7479c34c5117 Mon Sep 17 00:00:00 2001 From: DeokyongKim Date: Wed, 1 Jun 2022 18:27:33 +0900 Subject: [PATCH 41/42] really ended --- sukyoung.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sukyoung.py b/sukyoung.py index 2ffe44c..b7997e6 100644 --- a/sukyoung.py +++ b/sukyoung.py @@ -1,3 +1,6 @@ +# Wrong implement +# I just make my mind to GIVE UP with 2 by 2 problem + def get_2by2(table): ans = [] From 261f9f754aff31f6e6289140ce054e78e0ae21cb Mon Sep 17 00:00:00 2001 From: DeokyongKim <42801399+DeokyongKim@users.noreply.github.com> Date: Sun, 12 Jun 2022 22:29:55 +0900 Subject: [PATCH 42/42] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c9c59e5..cb22ac6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ###### Asterisk Python Team Project 2022 구성원: 김덕용 | 김가현 | 송준서 | 배정윤 | 윤석영 +2022.05.04 ~ 2022.06.02 + ## 1. 주제 Implicant 탐색 프로그램