Beispiel #1
0
def dessin_Gobies_init():
    """
    Dessine l'ensemble des gobies de la table (à ne faire qu'une fois). Dans
    l'état les éléments de la liste sont en unité turtle centré donc on applique
    juste ECHELLE.
    """
    for i in range(0, 24):
        dessin_Cercle(convert_CMOtoCTC(LISTEGOBI[i][0], "x"),
                      convert_CMOtoCTC(LISTEGOBI[i][1], "y"), LISTEGOBI[i][2])
def prise_gobi():
    """
    Cette fonction va vérifier en fonction de la position des pinces si un gobi
    est pris.
    Un gobi est pris si la pince est vide et à la même position qu'un gobi.

    On appelle avec STATE_PINCE1 et STATE_PINCE2 qui sont de base à None donc
    ETATP1 et ETATP2 aussi.
    """
    global STATE_PINCE1, STATE_PINCE2
    if STATE_PINCE1 is None:
        prise = False
        compt = 0
        # on sort du while si compt = 24 ou si on est sur la position d'un gobi
        # pince1.xcor() est en CTC on applique ECHELLE à LISTEGOBI[compt][0]
        # et LISTEGOBI[compt][1]
        # On considère qu'une pince est sur postion d'un gobi si elle se trouve
        while not prise and compt < len(LISTEGOBI):
            if (abs(
                    convert_CMOtoCTC(LISTEGOBI[compt][0], "x") - pince1.xcor())
                    <= LONGUER_ACCEPTATION_PINCES * ECHELLE and abs(
                        convert_CMOtoCTC(LISTEGOBI[compt][1], "y") -
                        pince1.ycor()) <=
                    LONGUER_ACCEPTATION_PINCES * ECHELLE):
                prise = True
            else:
                compt = compt + 1
        # Si prise = true alors la pince se trouve sur un gobi
        if prise:
            STATE_PINCE1 = LISTEGOBI[compt]
            # La pince prend la couleur du gobi
            pince1.fillcolor(STATE_PINCE1[2])
            # On efface le gobi avec la couleur du fond
            init_board.dessin_Cercle(
                convert_CMOtoCTC(LISTEGOBI[compt][0], "x"),
                convert_CMOtoCTC(LISTEGOBI[compt][1], "y"), AQA)
            del LISTEGOBI[compt]
    if STATE_PINCE2 is None:
        prise = False
        compt = 0
        while not prise and compt < len(LISTEGOBI):
            if (abs(
                    convert_CMOtoCTC(LISTEGOBI[compt][0], "x") - pince2.xcor())
                    <= LONGUER_ACCEPTATION_PINCES * ECHELLE and abs(
                        convert_CMOtoCTC(LISTEGOBI[compt][1], "y") -
                        pince2.ycor()) <=
                    LONGUER_ACCEPTATION_PINCES * ECHELLE):
                prise = True
            else:
                compt = compt + 1
        if prise:
            STATE_PINCE2 = LISTEGOBI[compt]
            pince2.fillcolor(STATE_PINCE2[2])
            init_board.dessin_Cercle(
                convert_CMOtoCTC(LISTEGOBI[compt][0], "x"),
                convert_CMOtoCTC(LISTEGOBI[compt][1], "y"), AQA)
            del LISTEGOBI[compt]
def init_robot():
    """
    Une fonction à n'utiliser d'une fois pour inintialiser le robot et les
    pinces.
    """
    Robotik.shape("square")
    Robotik.shapesize(2.4, 2.4, 1)
    Robotik.penup()
    Robotik.fillcolor(BOTCOLOR)

    pince1.shapesize(1, 1, 1)
    pince1.penup()
    pince1.fillcolor("white")
    pince1.shape("circle")

    pince2.shapesize(1, 1, 1)
    pince2.penup()
    pince2.fillcolor("white")
    pince2.shape("circle")

    Robotik.goto(convert_CMOtoCTC(ORIGINtBx, "x"),
                 convert_CMOtoCTC(ORIGINtBy, "y"))
    calculer_pos_pinces()
Beispiel #4
0
def drawboard():
    """
    Fonction à utiliser une seule fois pour dessiner l'ensemble de la table au
    début de de la simulation.
    """
    turtle.colormode(0xFF)  # Set les couleurs en version RGB 255
    # Règle la vitesse et la taille de la tortue de dessin
    # Par définition il exite un objet nommé "turtle" qui nous sert uniquement
    # au dessin sur la table
    turtle.speed(100)
    turtle.shapesize(0.1, 0.1, 0.1)
    turtle.penup()

    # coordonnées turtle centrée = CTC
    # coordonnées mm centrée = CMC
    # coordonnées mm offset = CMO

    # dessiner le cadre
    dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(2000, "y"),
                        3000 * ECHELLE, 2000 * ECHELLE, AQA)
    # dessiner la zone de jeu1
    dessin_Zone(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(1070, "y"),
                400 * ECHELLE, 540 * ECHELLE, BLE)
    # dessiner la zone de jeu2
    dessin_Zone(convert_CMOtoCTC(2600, "x"), convert_CMOtoCTC(1070, "y"),
                400 * ECHELLE, 540 * ECHELLE, YL)
    # dessiner la zone de jeu jaune bas
    dessin_Zone(convert_CMOtoCTC(1150, "x"), convert_CMOtoCTC(2000, "y"),
                100 * ECHELLE, 300 * ECHELLE, YL)
    # dessiner la zone de jeu bleu bas
    dessin_Zone(convert_CMOtoCTC(1750, "x"), convert_CMOtoCTC(2000, "y"),
                100 * ECHELLE, 300 * ECHELLE, BLE)
    # dessiner les rochers
    dessin_Zone(convert_CMOtoCTC(889, "x"), convert_CMOtoCTC(2000, "y"),
                22 * ECHELLE, 150 * ECHELLE, BLC)
    dessin_Zone(convert_CMOtoCTC(2089, "x"), convert_CMOtoCTC(2000, "y"),
                22 * ECHELLE, 150 * ECHELLE, BLC)
    dessin_Zone(convert_CMOtoCTC(1489, "x"), convert_CMOtoCTC(2000, "y"),
                22 * ECHELLE, 300 * ECHELLE, BLC)

    # dessiner les zones de couleurs des bases
    dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(530, "y"),
                        400 * ECHELLE, 30 * ECHELLE, GR)
    dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(1100, "y"),
                        400 * ECHELLE, 30 * ECHELLE, RD)
    dessin_Zone_Couleur(convert_CMOtoCTC(2600,
                                         "x"), convert_CMOtoCTC(530, "y"),
                        400 * ECHELLE, 30 * ECHELLE, RD)
    dessin_Zone_Couleur(convert_CMOtoCTC(2600,
                                         "x"), convert_CMOtoCTC(1100, "y"),
                        400 * ECHELLE, 30 * ECHELLE, GR)

    # dessiner les zones de couleurs des bases rochers
    dessin_Zone_Couleur(convert_CMOtoCTC(1050,
                                         "x"), convert_CMOtoCTC(2000, "y"),
                        100 * ECHELLE, 300 * ECHELLE, GR)
    dessin_Zone_Couleur(convert_CMOtoCTC(1250,
                                         "x"), convert_CMOtoCTC(2000, "y"),
                        100 * ECHELLE, 300 * ECHELLE, RD)
    dessin_Zone_Couleur(convert_CMOtoCTC(1650,
                                         "x"), convert_CMOtoCTC(2000, "y"),
                        100 * ECHELLE, 300 * ECHELLE, GR)
    dessin_Zone_Couleur(convert_CMOtoCTC(1850,
                                         "x"), convert_CMOtoCTC(2000, "y"),
                        100 * ECHELLE, 300 * ECHELLE, RD)

    dessin_Zone(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(2000, "y"),
                3000 * ECHELLE, 2000 * ECHELLE, BLC)
    dessin_Gobies_init()
    turtle.title("Simulation de la coupe")
    turtle.home()  # Retourne en 0;0 CTC
def goto(xTarget, yTarget, tt=Robotik):
    """
    Cette fonction permet de donner une postion CMO et Robotik s'y rend.
    xTarget et yTarget sont les coordonnées du point visé
    Robot permet de séléctioner quel élément du robot on met en point de repère.
    """
    delta = 2 * ENTRAX * math.cos(math.pi / 6)
    angleEnPlus = 17
    eI = 93.45  # Distance entre pinc et point voulu après rotation

    xTarget = convert_CMOtoCTC(xTarget, "x")
    yTarget = convert_CMOtoCTC(yTarget, "y")
    """
    if tt == pince1:
        if Robotik.xcor() > xTarget:
            # The target is 'left' to Robotik
            xTarget = xTarget - ENTRAX*ECHELLE
        elif Robotik.xcor() < xTarget:
            # The target is 'right' to Robotik
            xTarget = xTarget + ENTRAX*ECHELLE
    elif tt == pince2:
        if Robotik.xcor() > yTarget:
            # The target is 'left' to Robotik
            yTarget = yTarget - ENTRAX*ECHELLE
        elif Robotik.xcor() < yTarget:
            # The target is 'right' to Robotik
            yTarget = xTarget + ENTRAX*ECHELLE
    else:
        pass
    """

    #Distanc absolue entre les coordonnés selon y
    distX = abs(xTarget - Robotik.xcor())
    #Distanc absolue entre les coordonnés selon y
    distY = abs(yTarget - Robotik.ycor())
    #Distanc absolue réduite à 15% entre les coordonnés selon x
    # distXRed = (distX-((15*distX)/100))
    phi = int((180 * math.atan(distY / distX)) / math.pi)
    # phiRed = (180*(math.atan(distY/distXRed)))/math.pi

    print("*")
    print(xTarget)
    print(yTarget)
    print(Robotik.xcor())
    print(Robotik.ycor())
    print(distX)
    print(distY)
    print(phi)
    print("*")

    if Robotik.xcor() > xTarget:
        # The target is 'left' to Robotik
        if Robotik.ycor() > yTarget:
            # The target is 'left-down' to Robotik
            rotate_target(int(180 + phi))
            avancer(math.sqrt(distX * distX + distY * distY) / ECHELLE - delta)
            if tt == pince1:
                rotate(RGH, angleEnPlus)
                avancer(eI)
            elif tt == pince2:
                rotate(LFT, angleEnPlus)
                avancer(eI)
            else:
                avancer(delta)
        elif Robotik.ycor() < yTarget:
            # The target is 'left-up' to Robotik
            rotate_target(int(180 - phi))
            avancer(math.sqrt(distX * distX + distY * distY) / ECHELLE - delta)
            if tt == pince1:
                rotate(RGH, angleEnPlus)
                avancer(eI)
            elif tt == pince2:
                rotate(LFT, angleEnPlus)
                avancer(eI)
            else:
                avancer(delta)
        else:
            # The target and Robotik are on the same y value
            rotate_target(int(180))
            avancer(int(abs(xTarget - Robotik.xcor())))

    elif Robotik.xcor() < xTarget:
        # The target is 'right' to Robotik
        if Robotik.ycor() > yTarget:
            # The target is 'right-down' to Robotik
            rotate_target(int(360 - phi))
            avancer(math.sqrt(distX * distX + distY * distY) / ECHELLE - delta)
            if tt == pince1:
                rotate(RGH, angleEnPlus)
                avancer(eI)
            elif tt == pince2:
                rotate(LFT, angleEnPlus)
                avancer(eI)
            else:
                avancer(delta)
        elif Robotik.ycor() < yTarget:
            # The target is 'right-up' to Robotik
            rotate_target(int(phi))
            avancer(math.sqrt(distX * distX + distY * distY) / ECHELLE - delta)
            if tt == pince1:
                rotate(RGH, angleEnPlus)
                avancer(eI)
            elif tt == pince2:
                rotate(LFT, angleEnPlus)
                avancer(eI)
            else:
                avancer(delta)
        else:
            # The target and Robotik are on the same y value
            rotate_target(0)
            avancer(int(abs(xTarget - Robotik.xcor())))

    else:
        # The target and Robotik are on the same x value
        if Robotik.ycor() > yTarget:
            # The target is 'under' Robotik
            rotate(RGH, 90)
            avancer(int(abs(yTarget - Robotik.ycor())))
        elif Robotik.ycor() < yTarget:
            # The target is 'above' Robotik
            rotate(LFT, 90)
            avancer(int(abs(yTarget - Robotik.ycor())))
        else:
            return (1)  # Robotik is on the rigth place