|
|
|
@ -1,7 +1,12 @@
|
|
|
|
|
#Jupyter je lepsi
|
|
|
|
|
import numpy as np
|
|
|
|
|
# ^-- ok
|
|
|
|
|
import numpy as np # podle me zbytecny jelikoz jsi stejne nepouzil vsechny moznosti numpy
|
|
|
|
|
# jako treba ten matrix rotation
|
|
|
|
|
# takhle je tvuj kod jenom dependent na jeste jedny veci, coz je
|
|
|
|
|
# zbytecny; musis si uvedomit ze kdybys tohle nekomu posilal,
|
|
|
|
|
# tak ten clovek musi mit nejenom python ale i numpy
|
|
|
|
|
ikonky = [" "," X "," O "]
|
|
|
|
|
def render(board):
|
|
|
|
|
def render(board): # board jako argument - super
|
|
|
|
|
text = "+---+---+---+\n"
|
|
|
|
|
for row in board:
|
|
|
|
|
text += "|"
|
|
|
|
@ -17,10 +22,10 @@ def render(board):
|
|
|
|
|
| 6 | 7 | 8 |
|
|
|
|
|
+---+---+---+""")
|
|
|
|
|
|
|
|
|
|
def compare3(a,b,c):
|
|
|
|
|
def compare3(a,b,c): # obecne vyjadreni, nice
|
|
|
|
|
return a == b and b == c and a != 0
|
|
|
|
|
|
|
|
|
|
def check(board, move):
|
|
|
|
|
def check(board, move): # elegantni reseni, ale jde to i snadneji :D
|
|
|
|
|
#print(board, move)
|
|
|
|
|
end = False
|
|
|
|
|
#kontrola řádku
|
|
|
|
@ -37,8 +42,8 @@ def inputMove():
|
|
|
|
|
x = ""
|
|
|
|
|
OK = False
|
|
|
|
|
while not OK:
|
|
|
|
|
x = input("Zadejte tah od 0 do 8 \n > ")
|
|
|
|
|
OK = x.isnumeric()
|
|
|
|
|
x = input("Zadejte tah od 0 do 8 \n > ") # eeh, input ve funkci - vedlejsi efekt
|
|
|
|
|
OK = x.isnumeric() # nice, hezky reseni problemu vstupu
|
|
|
|
|
if OK:
|
|
|
|
|
OK = int(x) >= 0 and int(x) <= 8
|
|
|
|
|
if OK:
|
|
|
|
@ -47,27 +52,29 @@ def inputMove():
|
|
|
|
|
OK = move((X, Y),1)
|
|
|
|
|
|
|
|
|
|
def move(move,player):
|
|
|
|
|
global board
|
|
|
|
|
global lastMove
|
|
|
|
|
OK = board[move] == 0
|
|
|
|
|
global board # fuj fuj
|
|
|
|
|
global lastMove # bleh
|
|
|
|
|
OK = board[move] == 0 # chytry ze sis to zapsal do promenny
|
|
|
|
|
# diky tomu neprovadis stejny vypocet dvakrat
|
|
|
|
|
if OK:
|
|
|
|
|
board[move] = player
|
|
|
|
|
lastMove = move
|
|
|
|
|
return OK
|
|
|
|
|
return OK # vyuzivas return hodnot - nice
|
|
|
|
|
|
|
|
|
|
from random import randint
|
|
|
|
|
def AImove():
|
|
|
|
|
#vim ze to neni minmax
|
|
|
|
|
#^-- to ne no, ale je to zajimavy ozvlastneni programu
|
|
|
|
|
while not move((randint(0,2),randint(0,2)), 2):
|
|
|
|
|
continue
|
|
|
|
|
return move
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#LUKÁŠ - Tyhle module-level globaly by neměly fungovat, jsi si jistý, že jsi nahrál správný kód?
|
|
|
|
|
#hra
|
|
|
|
|
global board
|
|
|
|
|
# LUKÁŠ - Tyhle module-level globaly by neměly fungovat, jsi si jistý, že jsi nahrál správný kód?
|
|
|
|
|
# hra
|
|
|
|
|
global board # wtf vlasto
|
|
|
|
|
board = np.zeros((3, 3), dtype=np.int)
|
|
|
|
|
global lastMove
|
|
|
|
|
global lastMove # wut; sice to nechazi chybu ale melo by
|
|
|
|
|
lastMove = (0,0)
|
|
|
|
|
player = 1
|
|
|
|
|
render(board)
|
|
|
|
@ -77,9 +84,14 @@ while (not check(board, lastMove)[0]) and check(board, lastMove)[1]:
|
|
|
|
|
else:
|
|
|
|
|
AImove()
|
|
|
|
|
render(board)
|
|
|
|
|
player = (player%2)+1 #Hraje další hráč; 1 => 2; 2 => 1
|
|
|
|
|
player = (player%2)+1 # Hraje další hráč; 1 => 2; 2 => 1
|
|
|
|
|
# ^-- fajn ze komentujes
|
|
|
|
|
if check(board, lastMove)[0]:
|
|
|
|
|
print("Vyhrál: "+ikonky[board[lastMove]])
|
|
|
|
|
else:
|
|
|
|
|
print("Remíza")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ma to divnou strukturu, na jednu stranu jsou nektery mista dobre napsany
|
|
|
|
|
# jiny jsou gay a pouzivaj globaly
|
|
|
|
|
|
|
|
|
|
# jinak + za to AI
|
|
|
|
|