Ant's IA

Ant’s IA
Hi,
viewing a documentarie about ants, I wondered how they were clever and so did a .blend




And the video :

IA :
they know where the home is ( left down )
they put on floor something saying I have food ( red cases ) - less and less with time -
ants prefer to be on place with food traces ( blue )

trying to put my ants in a labyrinthe


Hey, this is a really cool and creative use of Blender! It’ll be fun to see what you do with this; I’ve got some appreciation for ants, too.

Thanks :slight_smile:

For now I had no time to put them , but sure I will put searches here

find the V03 ( without labyrinthe, b2.65+ ) here : ants ( it’s about 50Mo :slight_smile: )

find the V08 ( optimized - 3Mo - with labyrinthe but a changed IA which doesn’t work ) here : antsinlaby

here is the code usuable for the labyrinthe :

import bpy
import random
import sys
import time
#sys.setrecursionlimit(2000)
print(sys.getrecursionlimit())
print(dir(sys))
time.sleep(5)
Tx=30   
Ty=30
#!!!!!! !!!!!!!!! Tx*Ty<=sys.getrecursionlimit()
    
class cellule(object):
    def __init__(self):
        self.etat=False #pas relie au lab principal
        self.mur_droit=False #ferme        
        self.mur_bas=False #ferme        
global cellules
cellules=[ [cellule()  for i in range(Ty) ] for j in range(Tx)]
#print(cellules)
init=[random.randint(0,Tx-1),random.randint(0,Ty-1)]
init=[0,0]
cellules[init[0]][init[1]].etat=True
#print(init)
def case_suivante(init):
    global cellules
    cases_autorisees=[0,0]
    print(init)
    for a in range(2):
        for b in range(2):
            print( a,b,cellules[a][b].etat )
    x=init[0]
    y=init[1]

    while (len ( cases_autorisees )>0):
        cases_autorisees=[] 
        for i in range(2):
            xx=x+2*i-1
            if xx>=0 and xx<Tx and cellules[xx][y].etat==False:
                cases_autorisees.append( [xx,y] )
            yy=y+2*i-1
            if yy>=0 and yy<Ty and cellules[x][yy].etat==False:
                cases_autorisees.append( [x,yy] )
        print(x,y,cases_autorisees,len ( cases_autorisees ))
    
        print('ttt',x,y,cases_autorisees,len ( cases_autorisees ))
    
        if len(cases_autorisees)>0:
            t=random.choice(cases_autorisees)
            print('choix',t)        
            xx=t[0]
            yy=t[1]       
            cellules[xx][yy].etat=True
            if xx==x:
                if yy==y+1:
                    cellules[x][y].mur_bas=True
                    print('rr')
                else:
                    cellules[x][y-1].mur_bas=True    
                    print('aa')
            else:
                if xx==x+1:
                    print('bb')
                    cellules[x][y].mur_droit=True
                else:
                    print('cc')
                    cellules[x-1][y].mur_droit=True
            case_suivante([xx,yy])
            #del cases_autorisees[ cases_autorisees.index( [xx,yy])  ]
case_suivante(init)    
    
######### AFFICHAGE
for i in range(Tx):
    bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
    o=bpy.data.scenes['Scene'].objects['Cube']
    o.scale*=0.5
    o.scale[1]*=0.1
    o.location=[i+0.5,0,0]
    o.name='mb_'+str(i)+':'+str(-1)
for j in range(Ty):
    bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
    o=bpy.data.scenes['Scene'].objects['Cube']
    o.scale*=0.5
    o.scale[0]*=0.1
    o.location=[-1+1,-j-0.5,0]
    o.name='md_'+str(-1)+':'+str(j)
for i in range(Tx):    
    for j in range(Ty):
    
    if cellules[i][j].mur_droit==False:
        bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
        o=bpy.data.scenes['Scene'].objects['Cube']
        o.scale*=0.5
        o.scale[0]*=0.1
        o.location=[i+1,-j-0.5,0]
        o.name='md_'+str(i)+':'+str(j)
        
    if cellules[i][j].mur_bas==False:
        bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
        o=bpy.data.scenes['Scene'].objects['Cube']
        o.scale*=0.5
        o.scale[1]*=0.1
        o.location=[i+0.5,-1-j,0]
        o.name='mb_'+str(i)+':'+str(j)    
        


Few results
pretty good but only when I search the good values of the constants which are differents with these four images in one.


It’s difficult to see the labyrinthe but in each case almost all the square are in the shortest way from the point in the left down to the middle or in the right up corner.