Finally we will create the AI part. Thank you> <
As mentioned in Part 1, computers will basically select the "hand with the smallest number of worst candidates".
The goal is a function that finds the "worst candidate number". How to find the worst candidate, but you need a list of numbers that satisfy the results of your calls so far. Also, it would be useful to have a list with 720 numbers from 012 to 789. And it would be fun to prepare a list that contains all the combinations of EAT and BITE, so I will create these three lists and functions first.
I implemented it as follows
def change(a,b,c):
return [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]]
ALL=[]
for i in range(0,10):
for j in range(i+1,10):
for k in range(j+1,10):
ALL+=change(i,j,k)
To briefly explain the flow Create a function that returns a list of 3! Sorts from 3 numbers I made all the combinations so that the numbers are not covered by for, for, for. Please let me know if there is a better implementation (leave it to others)
Since the number is small, I will write it honestly
EB=[[3,0],[2,1],[2,0],[1,2],[1,1],[1,0],[0,3],[0,2],[0,1],[0,0]]
Next, we will define a function that collects numbers that satisfy the results of EAT and BITE so far. The first move is the same as ALL, so at first
KOUHO=ALL
Let's copy it. And every time I know EAT, BITE
def CHECK(CALL,EAT,BITE,KOUHO):
X=len(KOUHO)
group=[]
for i in range(X):
if NUMERON(CALL,KOUHO[i])==[EAT,BITE]:
group.append(KOUHO[i])
return group
KOUHO
KOUHO=CHECK(CALL,EAT,BITE,KOUHO)
You can update it with.
Now you are ready to find the "worst number of candidates".
def BAD(CALL,KOUHO):
CHECK_LIST=[0]*10
for i in range(10):
EAT=EB[i][0]
BITE=EB[i][1]
CHECK_LIST[i]=len(CHECK(CALL,EAT,BITE,KOUHO))
return max(CHECK_LIST)
Therefore, all you have to do is search from [0,1,2] to [7,8,9]. So the list of com calls can be written as:
def CALL_LIST(KOUHO):
LIST=[]
EATLIST=[]
cnt=1000
for i in range(720):
if BAD(ALL[i],KOUHO)<cnt:
cnt=BAD(ALL[i],KOUHO)
LIST=[]
EATLIST=[]
if len(CHECK(ALL[i],3,0,KOUHO))>=1:
EATLIST.append(ALL[i])
else:
LIST.append(ALL[i])
elif BAD(ALL[i],KOUHO)==cnt:
if len(CHECK(ALL[i],3,0,KOUHO))>=1:
EATLIST.append(ALL[i])
else:
LIST.append(ALL[i])
if len(EATLIST)==0:
return LIST
else:
return EATLIST
If you try and confirm in the situation that the remaining candidates are [1,2,3], [1,3,2], [2,4,1]
print(CALL_LIST([[1,2,3],[1,3,2],[2,4,1]]))
#[[1, 2, 3], [1, 3, 2]]
Returned. Sounds correct.
Now that you have the brains of com, let's create a battle environment !!
Recommended Posts