mirror of
https://github.com/Rushilwiz/AI.git
synced 2025-04-03 19:40:16 -04:00
finished unit 3 and started 4
This commit is contained in:
parent
8801b72631
commit
1c80cd1ee0
|
@ -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:
|
||||
|
|
93
Unit 4/Lab_A_self_check.py
Normal file
93
Unit 4/Lab_A_self_check.py
Normal file
|
@ -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.
|
||||
|
||||
'''
|
1
Unit 4/Umaretiya_r_U4_A.txt
Normal file
1
Unit 4/Umaretiya_r_U4_A.txt
Normal file
|
@ -0,0 +1 @@
|
|||
A
|
Loading…
Reference in New Issue
Block a user