From 503050189c713891868ae042cd3e56be35c1375d Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Tue, 4 Jan 2022 10:03:48 -0500 Subject: [PATCH 01/26] Create High_IQ.py --- 48_High_IQ/python/High_IQ.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 48_High_IQ/python/High_IQ.py diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/48_High_IQ/python/High_IQ.py @@ -0,0 +1 @@ + From 1af79b629847eed36a8a9543eee258f96d30cec8 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Tue, 4 Jan 2022 12:00:29 -0500 Subject: [PATCH 02/26] Started python function layout Totally not doing this through github.com --- 48_High_IQ/python/High_IQ.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 8b137891..237454b3 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -1 +1,13 @@ +def print_instructions(): + print("This is where you will find instructions") + +def play_game(): + print("Lets play a game") + +def main(): + if input("Do you want instrunctions?").lower().startswith("y"): + print_instructions() + +if __name__ == "__main__": + main() From acbf1387821409934888b544d16a7566d3078045 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Tue, 4 Jan 2022 13:59:37 -0500 Subject: [PATCH 03/26] Added Instructions --- 48_High_IQ/python/High_IQ.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 237454b3..90dd756a 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -1,12 +1,39 @@ def print_instructions(): - print("This is where you will find instructions") - + print("\n" * 3) + print("HERE IS THE BOARD:\n") + print("\n") + print(" ! ! !\n") + print(" 13 14 15\n") + print("\n") + print(" ! ! !\n") + print(" 22 23 24\n") + print("\n") + print("! ! ! ! ! ! !\n") + print("29 30 31 32 33 34 35\n") + print("\n") + print("! ! ! ! ! ! !\n") + print("38 39 40 41 42 43 44\n") + print("\n") + print("! ! ! ! ! ! !\n") + print("47 48 49 50 51 52 53\n") + print("\n") + print(" ! ! !\n") + print(" 58 59 60\n") + print("\n") + print(" ! ! !\n") + print(" 67 68 69\n") + print("\n") + print("TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD\n") + print("WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG\n") + print("NUMBERS. OK, LET'S BEGIN.\n") + + def play_game(): print("Lets play a game") def main(): - if input("Do you want instrunctions?").lower().startswith("y"): + if input("Do you want instrunctions?\n").lower().startswith("y"): print_instructions() if __name__ == "__main__": From 907482d042f23ea803887932df61f644672bb60c Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Tue, 4 Jan 2022 14:05:39 -0500 Subject: [PATCH 04/26] no change --- 48_High_IQ/python/High_IQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 90dd756a..f7bc9669 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -31,10 +31,10 @@ def print_instructions(): def play_game(): print("Lets play a game") - + def main(): if input("Do you want instrunctions?\n").lower().startswith("y"): print_instructions() - + if __name__ == "__main__": main() From bd705d8fc556e62161eb0ea4dd06aee667100e93 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Tue, 4 Jan 2022 14:30:50 -0500 Subject: [PATCH 05/26] So the board was wrong... --- 48_High_IQ/python/High_IQ.py | 97 +++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index f7bc9669..18d48456 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -1,40 +1,57 @@ - -def print_instructions(): - print("\n" * 3) - print("HERE IS THE BOARD:\n") - print("\n") - print(" ! ! !\n") - print(" 13 14 15\n") - print("\n") - print(" ! ! !\n") - print(" 22 23 24\n") - print("\n") - print("! ! ! ! ! ! !\n") - print("29 30 31 32 33 34 35\n") - print("\n") - print("! ! ! ! ! ! !\n") - print("38 39 40 41 42 43 44\n") - print("\n") - print("! ! ! ! ! ! !\n") - print("47 48 49 50 51 52 53\n") - print("\n") - print(" ! ! !\n") - print(" 58 59 60\n") - print("\n") - print(" ! ! !\n") - print(" 67 68 69\n") - print("\n") - print("TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD\n") - print("WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG\n") - print("NUMBERS. OK, LET'S BEGIN.\n") - - -def play_game(): - print("Lets play a game") - -def main(): - if input("Do you want instrunctions?\n").lower().startswith("y"): - print_instructions() - -if __name__ == "__main__": - main() + +def new_board(): + board = {} + for i in [13, 14, 15, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 58, 59, 60, 67, 68]: + board[i] = "X" + board[41] = "_" + return board + + +def print_instructions(): + print("\n" * 3) + print("HERE IS THE BOARD:\n") + # print("\n") + # print(" ! ! !\n") + # print(" 13 14 15\n") + # print("\n") + # print(" ! ! !\n") + # print(" 22 23 24\n") + # print("\n") + # print("! ! ! ! ! ! ! ! !\n") + # print("29 30 31 32 33 34 35 36 37\n") + # print("\n") + # print("! ! ! ! ! ! !\n") + # print("38 39 40 41 42 43 44\n") + # print("\n") + # print("! ! ! ! ! ! !\n") + # print("47 48 49 50 51 52 53\n") + # print("\n") + # print(" ! ! !\n") + # print(" 58 59 60\n") + # print("\n") + # print(" ! ! !\n") + # print(" 67 68 69\n") + # print("\n") + print("TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD\n") + print("WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG\n") + print("NUMBERS. OK, LET'S BEGIN.\n") + +def print_board(board): + print(" " * 3 + board[13] + board[14] + board[15] + " " * 3) + print(" " * 3 + board[22] + board[23] + board[24] + " " * 3) + print(board[29] + board[30] + board[31] + board[32] + board[33] + board[34] + board[35]) + print(board[38] + board[39] + board[40] + board[41] + board[42] + board[43] + board[44]) + print(board[47] + board[48] + board[49] + board[50] + board[51] + board[52] + board[53]) + +def play_game(): + print("Lets play a game") + board = new_board() + print_board(board) + +def main(): + if input("Do you want instrunctions?\n").lower().startswith("y"): + print_instructions() + play_game() + +if __name__ == "__main__": + main() From ff77118f5ffe1fe5837acd6b86d0de96462ad9e9 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 08:36:05 -0500 Subject: [PATCH 06/26] Finished print_board(board) method --- 48_High_IQ/python/High_IQ.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 18d48456..83443466 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -42,7 +42,9 @@ def print_board(board): print(board[29] + board[30] + board[31] + board[32] + board[33] + board[34] + board[35]) print(board[38] + board[39] + board[40] + board[41] + board[42] + board[43] + board[44]) print(board[47] + board[48] + board[49] + board[50] + board[51] + board[52] + board[53]) - + print(" " * 3 + board[58] + board[59] + board[60] + " " * 3) + print(" " * 3 + board[67] + board[68] + board[69] + " " * 3) + def play_game(): print("Lets play a game") board = new_board() From dcd4e4077c65ea18cb2a5ab4f473687beedc6c13 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 08:37:28 -0500 Subject: [PATCH 07/26] Uncommented board-positions guide --- 48_High_IQ/python/High_IQ.py | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 83443466..3f19a4f5 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -10,28 +10,28 @@ def new_board(): def print_instructions(): print("\n" * 3) print("HERE IS THE BOARD:\n") - # print("\n") - # print(" ! ! !\n") - # print(" 13 14 15\n") - # print("\n") - # print(" ! ! !\n") - # print(" 22 23 24\n") - # print("\n") - # print("! ! ! ! ! ! ! ! !\n") - # print("29 30 31 32 33 34 35 36 37\n") - # print("\n") - # print("! ! ! ! ! ! !\n") - # print("38 39 40 41 42 43 44\n") - # print("\n") - # print("! ! ! ! ! ! !\n") - # print("47 48 49 50 51 52 53\n") - # print("\n") - # print(" ! ! !\n") - # print(" 58 59 60\n") - # print("\n") - # print(" ! ! !\n") - # print(" 67 68 69\n") - # print("\n") + print("\n") + print(" ! ! !\n") + print(" 13 14 15\n") + print("\n") + print(" ! ! !\n") + print(" 22 23 24\n") + print("\n") + print("! ! ! ! ! ! ! ! !\n") + print("29 30 31 32 33 34 35 36 37\n") + print("\n") + print("! ! ! ! ! ! !\n") + print("38 39 40 41 42 43 44\n") + print("\n") + print("! ! ! ! ! ! !\n") + print("47 48 49 50 51 52 53\n") + print("\n") + print(" ! ! !\n") + print(" 58 59 60\n") + print("\n") + print(" ! ! !\n") + print(" 67 68 69\n") + print("\n") print("TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD\n") print("WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG\n") print("NUMBERS. OK, LET'S BEGIN.\n") From c67c51130a18ce7fda1d817c56ed55881a8dfae3 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 08:40:45 -0500 Subject: [PATCH 08/26] No longer asks before printing instructions --- 48_High_IQ/python/High_IQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 3f19a4f5..0f03dc04 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -51,8 +51,8 @@ def play_game(): print_board(board) def main(): - if input("Do you want instrunctions?\n").lower().startswith("y"): - print_instructions() +# if input("Do you want instrunctions?\n").lower().startswith("y"): + print_instructions() play_game() if __name__ == "__main__": From 319be6c0349a2298cec6997e8b20e0c19da8178a Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 08:43:12 -0500 Subject: [PATCH 09/26] Update High_IQ.py --- 48_High_IQ/python/High_IQ.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 0f03dc04..9561bbae 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -52,6 +52,8 @@ def play_game(): def main(): # if input("Do you want instrunctions?\n").lower().startswith("y"): + print("\t" * 33 + "H-I-Q") + print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") print_instructions() play_game() From d661df87865e2023ded3708c5a303eba9d6ce812 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 08:46:27 -0500 Subject: [PATCH 10/26] Removed trailing spaces --- 48_High_IQ/python/High_IQ.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 9561bbae..df1ffdbd 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -37,13 +37,13 @@ def print_instructions(): print("NUMBERS. OK, LET'S BEGIN.\n") def print_board(board): - print(" " * 3 + board[13] + board[14] + board[15] + " " * 3) - print(" " * 3 + board[22] + board[23] + board[24] + " " * 3) + print(" " * 3 + board[13] + board[14] + board[15]) + print(" " * 3 + board[22] + board[23] + board[24]) print(board[29] + board[30] + board[31] + board[32] + board[33] + board[34] + board[35]) print(board[38] + board[39] + board[40] + board[41] + board[42] + board[43] + board[44]) print(board[47] + board[48] + board[49] + board[50] + board[51] + board[52] + board[53]) - print(" " * 3 + board[58] + board[59] + board[60] + " " * 3) - print(" " * 3 + board[67] + board[68] + board[69] + " " * 3) + print(" " * 3 + board[58] + board[59] + board[60]) + print(" " * 3 + board[67] + board[68] + board[69]) def play_game(): print("Lets play a game") From 2ac967e6e4ec80edfbedf90f89942bf025b9154e Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 09:54:18 -0500 Subject: [PATCH 11/26] Added is_game_finished I have absolutely no idea if it works.. --- 48_High_IQ/python/High_IQ.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index df1ffdbd..d80b95a4 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -56,6 +56,18 @@ def main(): print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") print_instructions() play_game() + +def is_game_finished(board): + for pos in board.keys(): + if board[pos] == "X": + for space in [1,9]: + nextToPeg = ((pos + space) in board) and board[pos + space] + hasMovableSpace = (not ((pos - space) in board and board[pos - space])) or (not ((pos + space * 2) in board and board[pos + space * 2])) + if nextToPeg and hasMovableSpace: + return False + + return True + if __name__ == "__main__": main() From df1898230af900c990aec5035f150f662da6423c Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 09:55:01 -0500 Subject: [PATCH 12/26] Forgot board isn't booleans Maybe I should make it booleans? --- 48_High_IQ/python/High_IQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index d80b95a4..52aff04c 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -61,8 +61,8 @@ def is_game_finished(board): for pos in board.keys(): if board[pos] == "X": for space in [1,9]: - nextToPeg = ((pos + space) in board) and board[pos + space] - hasMovableSpace = (not ((pos - space) in board and board[pos - space])) or (not ((pos + space * 2) in board and board[pos + space * 2])) + nextToPeg = ((pos + space) in board) and board[pos + space] == "X" + hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "X")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "X")) if nextToPeg and hasMovableSpace: return False From 8b2d691e70044441278878353367a7b0839eea95 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 6 Jan 2022 13:58:12 -0500 Subject: [PATCH 13/26] Formatted Board into single string --- 48_High_IQ/python/High_IQ.py | 82 +++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 52aff04c..1f32e300 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -1,54 +1,58 @@ def new_board(): board = {} - for i in [13, 14, 15, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 58, 59, 60, 67, 68]: - board[i] = "X" - board[41] = "_" + for i in [13, 14, 15, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 58, 59, 60, 67, 68, 69]: + board[i] = "!" + board[41] = "O" return board def print_instructions(): - print("\n" * 3) - print("HERE IS THE BOARD:\n") - print("\n") - print(" ! ! !\n") - print(" 13 14 15\n") - print("\n") - print(" ! ! !\n") - print(" 22 23 24\n") - print("\n") - print("! ! ! ! ! ! ! ! !\n") - print("29 30 31 32 33 34 35 36 37\n") - print("\n") - print("! ! ! ! ! ! !\n") - print("38 39 40 41 42 43 44\n") - print("\n") - print("! ! ! ! ! ! !\n") - print("47 48 49 50 51 52 53\n") - print("\n") - print(" ! ! !\n") - print(" 58 59 60\n") - print("\n") - print(" ! ! !\n") - print(" 67 68 69\n") - print("\n") - print("TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD\n") - print("WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG\n") - print("NUMBERS. OK, LET'S BEGIN.\n") + print(""" +HERE IS THE BOARD: + + ! ! ! + 13 14 15 + + ! ! ! + 22 23 24 + +! ! ! ! ! ! ! +29 30 31 32 33 34 35 + +! ! ! ! ! ! ! +38 39 40 41 42 43 44 + +! ! ! ! ! ! ! +47 48 49 50 51 52 53 + + ! ! ! + 58 59 60 + + ! ! ! + 67 68 69 + +TO SAVE TYPING TIME, A COMPRESSED VERSION OF THE GAME BOARD +WILL BE USED DURING PLAY. REFER TO THE ABOVE ONE FOR PEG +NUMBERS. OK, LET'S BEGIN. + """) def print_board(board): - print(" " * 3 + board[13] + board[14] + board[15]) - print(" " * 3 + board[22] + board[23] + board[24]) + print(" " * 2 + board[13] + board[14] + board[15]) + print(" " * 2 + board[22] + board[23] + board[24]) print(board[29] + board[30] + board[31] + board[32] + board[33] + board[34] + board[35]) print(board[38] + board[39] + board[40] + board[41] + board[42] + board[43] + board[44]) print(board[47] + board[48] + board[49] + board[50] + board[51] + board[52] + board[53]) - print(" " * 3 + board[58] + board[59] + board[60]) - print(" " * 3 + board[67] + board[68] + board[69]) - + print(" " * 2 + board[58] + board[59] + board[60]) + print(" " * 2 + board[67] + board[68] + board[69]) + def play_game(): print("Lets play a game") board = new_board() - print_board(board) + + while not is_game_finished(board): + print_board(board) + def main(): # if input("Do you want instrunctions?\n").lower().startswith("y"): @@ -56,7 +60,7 @@ def main(): print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") print_instructions() play_game() - + def is_game_finished(board): for pos in board.keys(): if board[pos] == "X": @@ -65,9 +69,9 @@ def is_game_finished(board): hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "X")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "X")) if nextToPeg and hasMovableSpace: return False - + return True - + if __name__ == "__main__": main() From daf35273f0758c7ab838c355d4279423b0703e41 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Wed, 12 Jan 2022 13:07:07 -0500 Subject: [PATCH 14/26] Fixed formatting of tabs into spaces --- 48_High_IQ/python/High_IQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 1f32e300..cbb5960b 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -56,8 +56,8 @@ def play_game(): def main(): # if input("Do you want instrunctions?\n").lower().startswith("y"): - print("\t" * 33 + "H-I-Q") - print("\t" * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") + print(" " * 33 + "H-I-Q") + print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") print_instructions() play_game() From 712edfa232218d89f69e695c04650798963acf0b Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Wed, 12 Jan 2022 13:22:32 -0500 Subject: [PATCH 15/26] Update High_IQ.py --- 48_High_IQ/python/High_IQ.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index cbb5960b..b2e71b6c 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -47,12 +47,30 @@ def print_board(board): print(" " * 2 + board[67] + board[68] + board[69]) def play_game(): - print("Lets play a game") board = new_board() while not is_game_finished(board): print_board(board) + while not move(board): + print("ILLEGAL MOVE! TRY AGAIN") +def move(board): + try: + start = int(input("MOVE WHICH PIECE? ")) + if not (board[start] == "'!'): + return False + + end = int(input("TO WHERE? ")) + if not (board[end] == 'O'): + return False + difference = abs(end - start) + if difference != 2 and difference != 18: + return False + center = (end + start) / 2 + + except: + return False + return True def main(): # if input("Do you want instrunctions?\n").lower().startswith("y"): From 6d2855680b298ce51f16c62c059f7f21714974f1 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 08:36:27 -0500 Subject: [PATCH 16/26] Finished Move script (if it is correct) --- 48_High_IQ/python/High_IQ.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index b2e71b6c..548d984d 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -67,10 +67,15 @@ def move(board): if difference != 2 and difference != 18: return False center = (end + start) / 2 + if not board[center] == '!': + return False + board[start] = 'O' + board[center] = 'O' + board[end] = '!' + return True except: return False - return True def main(): # if input("Do you want instrunctions?\n").lower().startswith("y"): From daec93c14d7e9c0530aea985c19e05b420b749d1 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 08:41:13 -0500 Subject: [PATCH 17/26] Simplified / Shortened move script --- 48_High_IQ/python/High_IQ.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 548d984d..0f39b9d4 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -61,19 +61,14 @@ def move(board): return False end = int(input("TO WHERE? ")) - if not (board[end] == 'O'): - return False difference = abs(end - start) - if difference != 2 and difference != 18: - return False center = (end + start) / 2 - if not board[center] == '!': - return False - board[start] = 'O' - board[center] = 'O' - board[end] = '!' - return True + if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': + board[start] = 'O' + board[center] = 'O' + board[end] == '!' + return True except: return False From b7d9d0d88d14d35d3fb96a8577a8fddccb6813cc Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 08:45:48 -0500 Subject: [PATCH 18/26] Added Post-Game prints --- 48_High_IQ/python/High_IQ.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 0f39b9d4..57473922 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -53,6 +53,17 @@ def play_game(): print_board(board) while not move(board): print("ILLEGAL MOVE! TRY AGAIN") + + peg_count = 0 + for key in board.keys(): + if board[key] == '!': + peg_count += 1 + + print("YOU HAD " + str(peg_count) + " PEGS REMAINING") + + if peg_count == 1: + print("BRAVO! YOU MADE A PERFECT SCORE!") + print("SAVE THIS PAPER AS A RECORD OF YOUR ACCOMPLISHMENT!") def move(board): try: From 3ec94a28880d7e838996afb8ff37523cba91e807 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 08:47:41 -0500 Subject: [PATCH 19/26] Removed Commented Line --- 48_High_IQ/python/High_IQ.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 57473922..1c69abda 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -84,7 +84,6 @@ def move(board): return False def main(): -# if input("Do you want instrunctions?\n").lower().startswith("y"): print(" " * 33 + "H-I-Q") print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY") print_instructions() @@ -94,8 +93,8 @@ def is_game_finished(board): for pos in board.keys(): if board[pos] == "X": for space in [1,9]: - nextToPeg = ((pos + space) in board) and board[pos + space] == "X" - hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "X")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "X")) + nextToPeg = ((pos + space) in board) and board[pos + space] == "!" + hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "!")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "!")) if nextToPeg and hasMovableSpace: return False From e5da1590071f557c730f18c242e4e22dae029f62 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 09:07:33 -0500 Subject: [PATCH 20/26] Removed extra quotation mark --- 48_High_IQ/python/High_IQ.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 1c69abda..e8cca71d 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -68,7 +68,7 @@ def play_game(): def move(board): try: start = int(input("MOVE WHICH PIECE? ")) - if not (board[start] == "'!'): + if not (board[start] == '!'): return False end = int(input("TO WHERE? ")) @@ -97,7 +97,6 @@ def is_game_finished(board): hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "!")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "!")) if nextToPeg and hasMovableSpace: return False - return True From 3e9a67a5767a6827f6cef2834afc89370d19e795 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 09:14:39 -0500 Subject: [PATCH 21/26] Replaced double quotes with single quotes --- 48_High_IQ/python/High_IQ.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index e8cca71d..69cc6210 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -2,8 +2,8 @@ def new_board(): board = {} for i in [13, 14, 15, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 58, 59, 60, 67, 68, 69]: - board[i] = "!" - board[41] = "O" + board[i] = '!' + board[41] = 'O' return board @@ -91,10 +91,10 @@ def main(): def is_game_finished(board): for pos in board.keys(): - if board[pos] == "X": + if board[pos] == 'X': for space in [1,9]: - nextToPeg = ((pos + space) in board) and board[pos + space] == "!" - hasMovableSpace = (not ((pos - space) in board and board[pos - space] == "!")) or (not ((pos + space * 2) in board and board[pos + space * 2] == "!")) + nextToPeg = ((pos + space) in board) and board[pos + space] == '!' + hasMovableSpace = (not ((pos - space) in board and board[pos - space] == '!')) or (not ((pos + space * 2) in board and board[pos + space * 2] == '!')) if nextToPeg and hasMovableSpace: return False return True From 452d8b5da9ae87fd7ff631c375dd4da0c89c5c01 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 11:29:05 -0500 Subject: [PATCH 22/26] Commented and fixed error --- 48_High_IQ/python/High_IQ.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 69cc6210..a91f3699 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -1,5 +1,6 @@ def new_board(): + # Using a dictionary in python to store the board, since we are not including all numbers within a given range. board = {} for i in [13, 14, 15, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 58, 59, 60, 67, 68, 69]: board[i] = '!' @@ -38,6 +39,7 @@ NUMBERS. OK, LET'S BEGIN. """) def print_board(board): + """Prints the boards using indexes in the passed parameter""" print(" " * 2 + board[13] + board[14] + board[15]) print(" " * 2 + board[22] + board[23] + board[24]) print(board[29] + board[30] + board[31] + board[32] + board[33] + board[34] + board[35]) @@ -47,13 +49,16 @@ def print_board(board): print(" " * 2 + board[67] + board[68] + board[69]) def play_game(): + # Create new board board = new_board() + # Main game loop while not is_game_finished(board): print_board(board) while not move(board): print("ILLEGAL MOVE! TRY AGAIN") + # Check peg count and print the user's score peg_count = 0 for key in board.keys(): if board[key] == '!': @@ -66,20 +71,29 @@ def play_game(): print("SAVE THIS PAPER AS A RECORD OF YOUR ACCOMPLISHMENT!") def move(board): + """Queries the user to move. Returns false if the user puts in an invalid input or move, returns true if the move was successful""" try: + # Ask for the "start" location start = int(input("MOVE WHICH PIECE? ")) + # Verify that the location has a peg if not (board[start] == '!'): return False + # Ask for the "end" location end = int(input("TO WHERE? ")) + + # difference and center difference = abs(end - start) center = (end + start) / 2 + # Execute the move if the difference is correct, there is a peg in the center and no peg at the end if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': board[start] = 'O' board[center] = 'O' board[end] == '!' return True + else: + return False except: return False @@ -90,10 +104,13 @@ def main(): play_game() def is_game_finished(board): + # Checks all locations and whether or not a move is possible at that location. for pos in board.keys(): if board[pos] == 'X': for space in [1,9]: + # Checks if the next location has a peg nextToPeg = ((pos + space) in board) and board[pos + space] == '!' + # Checks both going forward (+ location) or backwards (-location) hasMovableSpace = (not ((pos - space) in board and board[pos - space] == '!')) or (not ((pos + space * 2) in board and board[pos + space * 2] == '!')) if nextToPeg and hasMovableSpace: return False From 489995ac1711485d64e7811e2b003c1ac4fb0218 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 12:27:53 -0500 Subject: [PATCH 23/26] Using tests instead of try catches --- 48_High_IQ/python/High_IQ.py | 70 +++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index a91f3699..2455049f 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -72,30 +72,60 @@ def play_game(): def move(board): """Queries the user to move. Returns false if the user puts in an invalid input or move, returns true if the move was successful""" - try: - # Ask for the "start" location - start = int(input("MOVE WHICH PIECE? ")) - # Verify that the location has a peg - if not (board[start] == '!'): - return False + # try: + # # Ask for the "start" location + # start = int(input("MOVE WHICH PIECE? ")) + # # Verify that the location has a peg + # if not (board[start] == '!'): + # return False - # Ask for the "end" location - end = int(input("TO WHERE? ")) + # # Ask for the "end" location + # end = int(input("TO WHERE? ")) - # difference and center - difference = abs(end - start) - center = (end + start) / 2 + # # difference and center + # difference = abs(end - start) + # center = (end + start) / 2 - # Execute the move if the difference is correct, there is a peg in the center and no peg at the end - if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': - board[start] = 'O' - board[center] = 'O' - board[end] == '!' - return True - else: - return False - except: + # # Execute the move if the difference is correct, there is a peg in the center and no peg at the end + # if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': + # board[start] = 'O' + # board[center] = 'O' + # board[end] == '!' + # return True + # else: + # return False + # except: + # return False + start_input = input("MOVE WHICH PIECE? ") + + if not start_input.isdigit(): return False + + start = int(start_input) + + if start not in board or board[start] != '!': + return False + + end_input = input("TO WHERE? ") + + if not end_input.isdigit(): + return False + + end = int(end_input) + + if end not in board or board[end] != '0': + return False + + difference = abs(start - end) + center = (end + start) / 2 + if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': + board[start] = 'O' + board[center] = 'O' + board[end] == '!' + return True + else: + return False + def main(): print(" " * 33 + "H-I-Q") From 6b612edfafd43ffcc2f548332d8c4241e42eccc6 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Jan 2022 16:59:25 -0500 Subject: [PATCH 24/26] Fixed Bug --- 48_High_IQ/python/High_IQ.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index 2455049f..cd5a996d 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -136,7 +136,7 @@ def main(): def is_game_finished(board): # Checks all locations and whether or not a move is possible at that location. for pos in board.keys(): - if board[pos] == 'X': + if board[pos] == '!': for space in [1,9]: # Checks if the next location has a peg nextToPeg = ((pos + space) in board) and board[pos + space] == '!' From f89180b83ae52b2d6c9b7f57a2917e7c64a1eb4b Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Jan 2022 17:01:43 -0500 Subject: [PATCH 25/26] Move code now properly works --- 48_High_IQ/python/High_IQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index cd5a996d..fe61e9ba 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -113,7 +113,7 @@ def move(board): end = int(end_input) - if end not in board or board[end] != '0': + if end not in board or board[end] != 'O': return False difference = abs(start - end) @@ -121,7 +121,7 @@ def move(board): if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': board[start] = 'O' board[center] = 'O' - board[end] == '!' + board[end] = '!' return True else: return False From 51ea729612ebd4c335a2adb181957dd45d49ccc4 Mon Sep 17 00:00:00 2001 From: Thomas Kwashnak Date: Thu, 13 Jan 2022 17:16:45 -0500 Subject: [PATCH 26/26] Misc final steps Removed commented code Added to README.md --- 48_High_IQ/python/High_IQ.py | 24 ------------------------ 48_High_IQ/python/README.md | 2 ++ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/48_High_IQ/python/High_IQ.py b/48_High_IQ/python/High_IQ.py index fe61e9ba..4e14ddc1 100644 --- a/48_High_IQ/python/High_IQ.py +++ b/48_High_IQ/python/High_IQ.py @@ -72,30 +72,6 @@ def play_game(): def move(board): """Queries the user to move. Returns false if the user puts in an invalid input or move, returns true if the move was successful""" - # try: - # # Ask for the "start" location - # start = int(input("MOVE WHICH PIECE? ")) - # # Verify that the location has a peg - # if not (board[start] == '!'): - # return False - - # # Ask for the "end" location - # end = int(input("TO WHERE? ")) - - # # difference and center - # difference = abs(end - start) - # center = (end + start) / 2 - - # # Execute the move if the difference is correct, there is a peg in the center and no peg at the end - # if (difference == 2 or difference == 18) and board[end] == 'O' and board[center] == '!': - # board[start] = 'O' - # board[center] = 'O' - # board[end] == '!' - # return True - # else: - # return False - # except: - # return False start_input = input("MOVE WHICH PIECE? ") if not start_input.isdigit(): diff --git a/48_High_IQ/python/README.md b/48_High_IQ/python/README.md index 781945ec..a0738c90 100644 --- a/48_High_IQ/python/README.md +++ b/48_High_IQ/python/README.md @@ -1,3 +1,5 @@ Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) Conversion to [Python](https://www.python.org/about/) + +[Implementation](./High_IQ.py) by [Thomas Kwashnak](https://github.com/LittleTealeaf) \ No newline at end of file