|
|
@ -1,7 +1,12 @@
|
|
|
|
#Jupyter je lepsi
|
|
|
|
#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 "]
|
|
|
|
ikonky = [" "," X "," O "]
|
|
|
|
def render(board):
|
|
|
|
def render(board): # board jako argument - super
|
|
|
|
text = "+---+---+---+\n"
|
|
|
|
text = "+---+---+---+\n"
|
|
|
|
for row in board:
|
|
|
|
for row in board:
|
|
|
|
text += "|"
|
|
|
|
text += "|"
|
|
|
@ -17,10 +22,10 @@ def render(board):
|
|
|
|
| 6 | 7 | 8 |
|
|
|
|
| 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
|
|
|
|
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)
|
|
|
|
#print(board, move)
|
|
|
|
end = False
|
|
|
|
end = False
|
|
|
|
#kontrola řádku
|
|
|
|
#kontrola řádku
|
|
|
@ -37,8 +42,8 @@ def inputMove():
|
|
|
|
x = ""
|
|
|
|
x = ""
|
|
|
|
OK = False
|
|
|
|
OK = False
|
|
|
|
while not OK:
|
|
|
|
while not OK:
|
|
|
|
x = input("Zadejte tah od 0 do 8 \n > ")
|
|
|
|
x = input("Zadejte tah od 0 do 8 \n > ") # eeh, input ve funkci - vedlejsi efekt
|
|
|
|
OK = x.isnumeric()
|
|
|
|
OK = x.isnumeric() # nice, hezky reseni problemu vstupu
|
|
|
|
if OK:
|
|
|
|
if OK:
|
|
|
|
OK = int(x) >= 0 and int(x) <= 8
|
|
|
|
OK = int(x) >= 0 and int(x) <= 8
|
|
|
|
if OK:
|
|
|
|
if OK:
|
|
|
@ -47,27 +52,29 @@ def inputMove():
|
|
|
|
OK = move((X, Y),1)
|
|
|
|
OK = move((X, Y),1)
|
|
|
|
|
|
|
|
|
|
|
|
def move(move,player):
|
|
|
|
def move(move,player):
|
|
|
|
global board
|
|
|
|
global board # fuj fuj
|
|
|
|
global lastMove
|
|
|
|
global lastMove # bleh
|
|
|
|
OK = board[move] == 0
|
|
|
|
OK = board[move] == 0 # chytry ze sis to zapsal do promenny
|
|
|
|
|
|
|
|
# diky tomu neprovadis stejny vypocet dvakrat
|
|
|
|
if OK:
|
|
|
|
if OK:
|
|
|
|
board[move] = player
|
|
|
|
board[move] = player
|
|
|
|
lastMove = move
|
|
|
|
lastMove = move
|
|
|
|
return OK
|
|
|
|
return OK # vyuzivas return hodnot - nice
|
|
|
|
|
|
|
|
|
|
|
|
from random import randint
|
|
|
|
from random import randint
|
|
|
|
def AImove():
|
|
|
|
def AImove():
|
|
|
|
#vim ze to neni minmax
|
|
|
|
#vim ze to neni minmax
|
|
|
|
|
|
|
|
#^-- to ne no, ale je to zajimavy ozvlastneni programu
|
|
|
|
while not move((randint(0,2),randint(0,2)), 2):
|
|
|
|
while not move((randint(0,2),randint(0,2)), 2):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
return move
|
|
|
|
return move
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#LUKÁŠ - Tyhle module-level globaly by neměly fungovat, jsi si jistý, že jsi nahrál správný kód?
|
|
|
|
# LUKÁŠ - Tyhle module-level globaly by neměly fungovat, jsi si jistý, že jsi nahrál správný kód?
|
|
|
|
#hra
|
|
|
|
# hra
|
|
|
|
global board
|
|
|
|
global board # wtf vlasto
|
|
|
|
board = np.zeros((3, 3), dtype=np.int)
|
|
|
|
board = np.zeros((3, 3), dtype=np.int)
|
|
|
|
global lastMove
|
|
|
|
global lastMove # wut; sice to nechazi chybu ale melo by
|
|
|
|
lastMove = (0,0)
|
|
|
|
lastMove = (0,0)
|
|
|
|
player = 1
|
|
|
|
player = 1
|
|
|
|
render(board)
|
|
|
|
render(board)
|
|
|
@ -77,9 +84,14 @@ while (not check(board, lastMove)[0]) and check(board, lastMove)[1]:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
AImove()
|
|
|
|
AImove()
|
|
|
|
render(board)
|
|
|
|
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]:
|
|
|
|
if check(board, lastMove)[0]:
|
|
|
|
print("Vyhrál: "+ikonky[board[lastMove]])
|
|
|
|
print("Vyhrál: "+ikonky[board[lastMove]])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Remíza")
|
|
|
|
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
|
|
|
|