morpion.py

Created by johnnyboulayq

Created on November 15, 2024

8.33 KB


import math
import kandinsky
import ion
import random
import turtle
import time
A1 = 0 #1=IA\J2 | 2=Joueur
A2 = 0 #1=IA\J2 | 2=Joueur
A3 = 0 #1=IA\J2 | 2=Joueur
B1 = 0 #1=IA\J2 | 2=Joueur
B2 = 0 #1=IA\J2 | 2=Joueur
B3 = 0 #1=IA\J2 | 2=Joueur
C1 = 0 #1=IA\J2 | 2=Joueur
C2 = 0 #1=IA\J2 | 2=Joueur
C3 = 0 #1=IA\J2 | 2=Joueur
TURN = random.randrange(1,2)
BOT = random.randrange(1,9)
# 320x225
kandinsky.fill_rect(0,0,115,225,kandinsky.color(200,200,200))
kandinsky.fill_rect(115,0,5,225,kandinsky.color(150,150,150))
kandinsky.draw_string("MORPION",25,10)
kandinsky.draw_string("Bienvenue\n\n\n\n\t\t\t\t[EXE] - Jouer",180,10)
while ion.keydown(ion.KEY_EXE): #evite que le script en dessous s'execute des le lancement si EXE est appuier
  GAMEMODE = 0
while not ion.keydown(ion.KEY_EXE):
  GAMEMODE = 0
while GAMEMODE == 0:
  kandinsky.draw_string("Bienvenue\n\n\n\n\t\t\t [SHIFT]            \n\t\t\t Joueur VS IA\n\n\t\t\t [ALPHA]\n\t\t\t 2 Joueurs",180,10)
  if ion.keydown(ion.KEY_SHIFT):
    GAMEMODE = 1
  
  if ion.keydown(ion.KEY_ALPHA):
    GAMEMODE = 2
  
kandinsky.fill_rect(130,0,250,225,'white')
kandinsky.fill_rect(190,30,1,165,'gray')
kandinsky.fill_rect(250,30,1,165,'gray')
kandinsky.fill_rect(130,80,175,1,'gray')
kandinsky.fill_rect(130,140,175,1,'gray')
while True:
  if A1 == 0:
    kandinsky.draw_string("7",155,45,kandinsky.color(200,200,200))
  elif A1 == 1:
    kandinsky.draw_string("O",155,45)
  else:
    kandinsky.draw_string("X",155,45)

  if A2 == 0:
    kandinsky.draw_string("8",215,45,kandinsky.color(200,200,200))
  elif A2 == 1:
    kandinsky.draw_string("O",215,45)
  else:
    kandinsky.draw_string("X",215,45)

  if A3 == 0:
    kandinsky.draw_string("9",275,45,kandinsky.color(200,200,200))
  elif A3 == 1:
    kandinsky.draw_string("O",275,45)
  else:
    kandinsky.draw_string("X",275,45)

  if B1 == 0:
    kandinsky.draw_string("4",155,100,kandinsky.color(200,200,200))
  elif B1 == 1:
    kandinsky.draw_string("O",155,100)
  else:
    kandinsky.draw_string("X",155,100)
  
  if B2 == 0:
    kandinsky.draw_string("5",215,100,kandinsky.color(200,200,200))
  elif B2 == 1:
    kandinsky.draw_string("O",215,100)
  else:
    kandinsky.draw_string("X",215,100)
  
  if B3 == 0:
    kandinsky.draw_string("6",275,100,kandinsky.color(200,200,200))
  elif B3 == 1:
    kandinsky.draw_string("O",275,100)
  else:
    kandinsky.draw_string("X",275,100)

  if C1 == 0:
    kandinsky.draw_string("1",155,160,kandinsky.color(200,200,200))
  elif C1 == 1:
    kandinsky.draw_string("O",155,160)
  else:
    kandinsky.draw_string("X",155,160)
  
  if C2 == 0:
    kandinsky.draw_string("2",215,160,kandinsky.color(200,200,200))
  elif C2 == 1:
    kandinsky.draw_string("O",215,160)
  else:
    kandinsky.draw_string("X",215,160)
  
  if C3 == 0:
    kandinsky.draw_string("3",275,160,kandinsky.color(200,200,200))
  elif C3 == 1:
    kandinsky.draw_string("O",275,160)
  else:
    kandinsky.draw_string("X",275,160)
  
  if GAMEMODE == 1:
      
    if TURN == 1:
      if ion.keydown(ion.KEY_EXE):
        kandinsky.fill_rect(0,0,115,225,kandinsky.color(200,200,200))
        A1 = 0 #1=IA\J2 | 2=Joueur
        A2 = 0 #1=IA\J2 | 2=Joueur
        A3 = 0 #1=IA\J2 | 2=Joueur
        B1 = 0 #1=IA\J2 | 2=Joueur
        B2 = 0 #1=IA\J2 | 2=Joueur
        B3 = 0 #1=IA\J2 | 2=Joueur
        C1 = 0 #1=IA\J2 | 2=Joueur
        C2 = 0 #1=IA\J2 | 2=Joueur
        C3 = 0 #1=IA\J2 | 2=Joueur
        TURN = random.randrange(1,2)
      else:
        kandinsky.draw_string("   [EXE]   \n  debloque \n     IA    ",0,150)
      
      kandinsky.draw_string("MORPION",25,10)
      kandinsky.draw_string("Joueur",25,100)
      kandinsky.draw_string("  IA  ",25,115,'green')      
      BOT = random.randrange(1,9)
      time.sleep(0.5)
      if BOT == 9:
        if A1 == 0:
          A1 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 8:
        if A2 == 0:
          A2 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 7:
        if A3 == 0:
          A3 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 6:
        if B1 == 0:
          B1 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 5:
        if B2 == 0:
          B2 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 4:
        if B3 == 0:
          B3 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 3:
        if C1 == 0:
          C1 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 2:
        if C2 == 0:
          C2 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      if BOT == 1:
        if C3 == 0:
          C3 = 2
          TURN = 2
        else:
          BOT = random.randrange(1,9)
      
      
      kandinsky.fill_rect(0,0,115,225,kandinsky.color(200,200,200))
    else:
      kandinsky.draw_string("MORPION",25,10)
      kandinsky.draw_string("Joueur",25,100,'green')
      kandinsky.draw_string("  IA  ",25,115)      
      if ion.keydown(ion.KEY_ONE) and C1 == 0:
        C1 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_TWO) and C2 == 0:
        C2 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_THREE) and C3 == 0:
        C3 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_FOUR) and B1 == 0:
        B1 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_FIVE) and B2 == 0:
        B2 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_SIX) and B3 == 0:
        B3 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_SEVEN) and A1 == 0:
        A1 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_EIGHT) and A2 == 0:
        A2 = 1
        TURN = 1
        
      if ion.keydown(ion.KEY_NINE) and A3 == 0:
        A3 = 1
        TURN = 1
        
  else:
    if TURN == 1:
      kandinsky.draw_string("MORPION",25,10)
      kandinsky.draw_string("Joueur 1",25,100,'green')
      kandinsky.draw_string("Joueur 2",25,115)      
      if ion.keydown(ion.KEY_ONE) and C1 == 0:
        C1 = 1
        TURN = 2
        
      if ion.keydown(ion.KEY_TWO) and C2 == 0:
        C2 = 1
        TURN = 2
      
      if ion.keydown(ion.KEY_THREE) and C3 == 0:
        C3 = 1
        TURN = 2
        
      if ion.keydown(ion.KEY_FOUR) and B1 == 0:
        B1 = 1
        TURN = 2
      
      if ion.keydown(ion.KEY_FIVE) and B2 == 0:
        B2 = 1
        TURN = 2
        
      if ion.keydown(ion.KEY_SIX) and B3 == 0:
        B3 = 1
        TURN = 2
        
      if ion.keydown(ion.KEY_SEVEN) and A1 == 0:
        A1 = 1
        TURN = 2
      
      if ion.keydown(ion.KEY_EIGHT) and A2 == 0:
        A2 = 1
        TURN = 2
        
      if ion.keydown(ion.KEY_NINE) and A3 == 0:
        A3 = 1
        TURN = 2

    elif TURN == 2:
      kandinsky.draw_string("Joueur 1",25,100)
      kandinsky.draw_string("Joueur 2",25,115,'green')
      
      if ion.keydown(ion.KEY_ONE) and C1 == 0:
        C1 = 2
        TURN = 1
        
      if ion.keydown(ion.KEY_TWO) and C2 == 0:
        C2 = 2
        TURN = 1
        
      if ion.keydown(ion.KEY_THREE) and C3 == 0:
        C3 = 2
        TURN = 1
        
      if ion.keydown(ion.KEY_FOUR) and B1 == 0:
        B1 = 2
        TURN = 1
      
      if ion.keydown(ion.KEY_FIVE) and B2 == 0:
        B2 = 2
        TURN = 1
        
      if ion.keydown(ion.KEY_SIX) and B3 == 0:
        B3 = 2
        TURN = 1
      
      if ion.keydown(ion.KEY_SEVEN) and A1 == 0:
        A1 = 2
        TURN = 1
      
      if ion.keydown(ion.KEY_EIGHT) and A2 == 0:
        A2 = 2
        TURN = 1
      
      if ion.keydown(ion.KEY_NINE) and A3 == 0:
        A3 = 2
        TURN = 1
    
      
  if not A1 == 0 and not A2 == 0 and not A3 == 0 and not B1 == 0 and not B2 == 0 and not B3 == 0 and not C1 == 0 and not C2 == 0 and not C3 == 0:
    kandinsky.draw_string("\t[EXE]\n\tReset",0,140)
    if ion.keydown(ion.KEY_EXE):
      A1 = 0 #1=IA\J2 | 2=Joueur
      A2 = 0 #1=IA\J2 | 2=Joueur
      A3 = 0 #1=IA\J2 | 2=Joueur
      B1 = 0 #1=IA\J2 | 2=Joueur
      B2 = 0 #1=IA\J2 | 2=Joueur
      B3 = 0 #1=IA\J2 | 2=Joueur
      C1 = 0 #1=IA\J2 | 2=Joueur
      C2 = 0 #1=IA\J2 | 2=Joueur
      C3 = 0 #1=IA\J2 | 2=Joueur
      TURN = random.randrange(1,2)
      kandinsky.fill_rect(0,0,115,225,kandinsky.color(200,200,200))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.