from turtle import * from random import random,randint,choice def trait(x, y, a, d): penup() goto(x, y) pendown() setheading(a) forward(d) def grille(nb): case = min(H,L) // nb H_m, L_m = -nb * case / 2, -nb * case /2 for i in range(1,nb): trait(L_m, H_m + case * i, 0, nb * case) trait(L_m + case * i, H_m, 90, nb * case) return case, H_m, L_m def cercle(x,y,r,c): penup() color(c) goto(x,y - r) setheading(0) pendown() circle(int(r)) def croix(x,y,r,c): for i in [-1,1]: penup() color(c) goto(x - r, y + i * r) pendown() goto(x + r, y - i * r) def pion(x,y,r,t1,t2): if t1 != t2: if t1 == 1: cercle(x,y,r,"white") elif t1 == 2: croix(x,y,r,"white") if t2 == 1: cercle(x,y,r,"black") elif t2 == 2: croix(x,y,r,"black") speed(0) hideturtle() L,H = 320, 222 taille = 3 jeu = [0 for _ in range(taille * taille)] case, H_m, L_m = grille(taille) r = case / 2.3 while True: for c in range(taille): for l in range(taille): x, y, n = case * (c - (taille - 1) / 2), case * (l - (taille - 1) / 2), taille * c + l v = choice([0,1,2]) pion(x,y,r,jeu[n],v) jeu[n] = v