[Episode 3] Beginners tried Numeron AI with python

0th 1st 2nd 3rd Final story

About this article

Finally we will create the AI part. Thank you> <

Confirmation of AI flow

As mentioned in Part 1, computers will basically select the "hand with the smallest number of worst candidates".

Required programs

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.

List of numbers from 012 to 789

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)

List of all combinations of EAT and BITE

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]]

List of candidates

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".

Function to find the worst candidate number in a call

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:

Creating a list of com call candidates

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

[Episode 2] Beginners tried Numeron AI with python
[Episode 3] Beginners tried Numeron AI with python
[Episode 0] Beginners tried Numeron AI with python
[Episode 1] Beginners tried Numeron AI with python
[Final story] Beginners tried Numeron AI with python
3. 3. AI programming with Python
I tried fp-growth with python
I tried scraping with Python
Make Puyo Puyo AI with Python
Mayungo's Python Learning Episode 1: I tried printing with print
I tried gRPC with Python
I tried scraping with python
[Ipdb] Web development beginners tried to summarize debugging with Python
Mayungo's Python Learning Episode 3: I tried to print numbers with print
I tried web scraping with python.
I tried running prolog with python 3.8.2.
python beginners tried to find out
I tried SMTP communication with Python
I tried to solve the ant book beginner's edition with python
[Pandas] I tried to analyze sales data with Python [For beginners]
Mayungo's Python Learning Episode 7: I tried printing with if, elif, else
INSERT into MySQL with Python [For beginners]
I tried scraping Yahoo News with Python
I tried sending an email with python.
I tried non-photorealistic rendering with Python + opencv
I tried a functional language with Python
I tried recursion with Python ② (Fibonacci sequence)
[Python] Read images with OpenCV (for beginners)
Mayungo's Python Learning Episode 8: I tried input
WebApi creation with Python (CRUD creation) For beginners
How Python beginners get started with Python with Progete
Build AI / machine learning environment with Python
[For beginners] Try web scraping with Python
#I tried something like Vlookup with Python # 2
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
Mayungo's Python Learning Episode 2: I tried to put out characters with variables
I refactored "I tried to make Othello AI when programming beginners studied python"
I tried to predict next year with AI
I tried hundreds of millions of SQLite with python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Causal reasoning and causal search with Python (for beginners)
I tried "differentiating" the image with Python + OpenCV
Scraping with Python
Python with Go
Mayungo's Python Learning Episode 5: I tried to do four arithmetic operations with numbers
Python beginners tried to code some energy drinks
Twilio with Python
I tried L-Chika with Raspberry Pi 4 (Python edition)
Integrate with Python
Play with 2016-Python
I tried Jacobian and partial differential with python
I tried to get CloudWatch data with Python
I tried using mecab with python2.7, ruby2.3, php7
AES256 with python
~ Tips for Python beginners from Pythonista with love ① ~
I tried function synthesis and curry with python
Tested with Python
I tried to output LLVM IR with Python
Machine learning beginners tried to make a horse racing prediction model with python