diff --git a/Unit 3/othello_submission.py b/Unit 3/othello_submission.py index 8a68d20..49e6621 100644 --- a/Unit 3/othello_submission.py +++ b/Unit 3/othello_submission.py @@ -188,7 +188,7 @@ INSULTS = [ class Strategy: def __init__(self): - #self.logging = True + self.logging = True self.white = "o" self.black = "x" self.directions = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]] @@ -254,10 +254,10 @@ class Strategy: if search_depth % 2 == 0: v = -9999999999 - result = 0 + result = -123456789 for move, flipped in self.find_moves(board, color).items(): max_val, max_state = self.alphabeta(self.make_move(board, color, move, flipped), self.opposite_color[color], search_depth - 1, alpha, beta, move) - if v < max_val: + if v < max_val or result == -123456789: v = max_val result = move if v > beta: @@ -266,10 +266,10 @@ class Strategy: return v, result else: v = 9999999999 - result = 0 + result = -123456789 for move, flipped in self.find_moves(board, color).items(): min_val, min_state = self.alphabeta(self.make_move(board, color, move, flipped), self.opposite_color[color], search_depth - 1, alpha, beta, move) - if v > min_val: + if v > min_val or result == -123456789: v = min_val result = move if v < alpha: diff --git a/Unit 4/Lab_A_self_check.py b/Unit 4/Lab_A_self_check.py new file mode 100644 index 0000000..056fc17 --- /dev/null +++ b/Unit 4/Lab_A_self_check.py @@ -0,0 +1,93 @@ +# Nicole Kim, 2/9/2019, edited on 2/1/2021 +import re + +def num_30(str): + # Current test checks if the string is '0' + pattern = "^10[01]$|^0$" #notice that python does not want / / + match = re.match(pattern, str) + print ("string is either 0, 100, or 101: ", match != None) + +def num_31(str): + # Current test checks if the string is '0' + pattern = "^[01]*$" + print ("string is a binary string:", re.match(pattern, str) != None) + +# Pre-condition: input is a binary string, so you do not need to check if it's a binary or not. +def num_32(str): + pattern = '^.*0$' + print ("string is an even binary number:", re.match(pattern, str) != None) + +def num_33(str): + # Current test searches words with 'a' + pattern = "\w*[aeiou]\w*[aeiou]\w*" + # Notice that python does not support /i in the pattern. + # Use re.I for case insensitive when you match(exact same) or search(has one or more) + print ("there's a word at least two vowels:", re.search(pattern, str, re.I) != None) + +def num_34(str): + pattern = "^1[10]*0$" + print ("even binary integer string:", re.match(pattern, str) != None) + +def num_35(str): + pattern = "^[10]*110[10]*$" + print ("binary string including 110:", re.match(pattern, str) != None) + +def num_36(str): + pattern = ".{2,4}$" + print ("length at least two, but at most four:", re.match(pattern, str, re.DOTALL) != None) + +def num_37(str): + pattern = "^\d{3}[- ]*\d{2}[- ]*\d{4}$" + print ("valid social security number:", re.match(pattern, str) != None) + +def num_38(str): + # When you read multiline input such as "I\nAM\nSAM." + # str = str.replace('\\n', '\n') # If you need this... + pattern = "^\w*d\w*" + + # When you want to use /im options: + d_search = re.search(pattern, str, re.I | re.MULTILINE) + print ("first word with d on a line:", d_search != None) + +def num_39(str): + pattern = "^1[10]*1$|^0[10]*0$" + print ("There's same number of 01 substrings as 10 substrings: ", re.match(pattern, str) != None) + +while(True): + input_num = input("Choose the exercise # (30 - 39 or -1 to terminate):") + if input_num == '-1': exit("Good bye") + input_str = input("Input string: ") + try: + eval("num_" + input_num)(input_str) + except: + pass + print() + +''' Sample Output +Choose the exercise # (30 - 39 or -1 to terminate):30 +Input string: 100 +string is either 0, 100, or 101: True + +Choose the exercise # (30 - 39 or -1 to terminate):30 +Input string: 1000 +string is either 0, 100, or 101: False + +Choose the exercise # (30 - 39 or -1 to terminate):39 +Input string: 101 +There's same number of 01 substrings as 10 substrings: True + +Choose the exercise # (30 - 39 or -1 to terminate):39 +Input string: 100 +There's same number of 01 substrings as 10 substrings: False + +Choose the exercise # (30 - 39 or -1 to terminate):39 +Input string: 0 +There's same number of 01 substrings as 10 substrings: True + +Choose the exercise # (31 - 40 or -1 to terminate):-1 +Good bye + + ----jGRASP wedge2: exit code for process is 1. + ----jGRASP: operation complete. + +''' \ No newline at end of file diff --git a/Unit 4/Umaretiya_r_U4_A.txt b/Unit 4/Umaretiya_r_U4_A.txt new file mode 100644 index 0000000..8c7e5a6 --- /dev/null +++ b/Unit 4/Umaretiya_r_U4_A.txt @@ -0,0 +1 @@ +A \ No newline at end of file