Facebook
From Sexy Echidna, 2 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 115
  1. map = [["*","*","*"],["*","*","*"],["*","*","*"]]
  2.  
  3. def ShowMap(list):
  4.     print("  1 2 3")
  5.     row = 1
  6.     for wiersz in list:
  7.         print(row, end=" ")
  8.         for element in wiersz:
  9.             print(element, end=" ")
  10.         print()
  11.         row += 1
  12.  
  13. def Winner(list):
  14.     for x in range(0,3):
  15.         if map[x][0] == map[x][1] and map[x][1] == map[x][2] and (map[x][2] == "X" or map[x][2] == "O"):
  16.             return True
  17.     for y in range(0,3):
  18.         if map[0][x] == map[1][x] and map[1][x] == map[2][x] and (map[2][x] == "X" or map[2][x] == "O"):
  19.             return True
  20.     if map[0][0] == map[1][1] and map[1][1] == map[2][2] and (map[2][2] == "X" or map[2][2] == "O"):
  21.             return True
  22.     if map[0][2] == map[1][1] and map[1][1] == map[2][0] and (map[2][0] == "X" or map[2][0] == "O"):
  23.             return True
  24.     return False
  25.  
  26. def Draw(list):
  27.     if not Winner(list):
  28.         for wiersz in list:
  29.             for element in wiersz:
  30.                 if element == "*":
  31.                     return False
  32.         return True
  33.     else:
  34.         return False
  35.  
  36. cross_play  = False
  37.  
  38. begin = input("Jezeli ma zaczac krzyzyk wpisz X, jeżeli kółko wpisz O: ")
  39. if begin == "X" or begin == "X":
  40.     cross_play = True
  41.  
  42. while(not Draw(map) and not Winner(map)):
  43.     ShowMap(map)
  44.     x, y = [int(x) for x in input("Podaj wspolrzedne, gdzie chcesz postawic znak:").split()]
  45.     if map[x-1][y-1] == "*":
  46.         if cross_play:
  47.             map[x-1][y-1] = "X"
  48.             cross_play = False
  49.         else:
  50.             map[x-1][y-1] = "O"
  51.             cross_play = True
  52.  
  53. if Winner(map):
  54.     if cross_play:
  55.         ShowMap(map)
  56.         print("Kolko wygralo!")
  57.     else:
  58.         ShowMap(map)
  59.         print("Krzyzyk wygral!")
  60. else:
  61.     ShowMap(map)
  62.     print("Mamy remis!")