prvni payload piskvorek uz je tady

pull/1/head
Dawid J. Kubis 5 years ago
parent bf7d82392f
commit 13838c8dbf

@ -0,0 +1 @@
furt piskvorky...

@ -0,0 +1,51 @@
plocha = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]
hrac = "X"
def kontrola():
if plocha[0][0] == plocha[0][1] and plocha[0][1] == plocha[0][2] and plocha[0][2] != " ":
print("Vyhrál " + hrac)
return True
if plocha[1][0] == plocha[1][1] and plocha[1][1] == plocha[1][2] and plocha[1][2] != " ":
print("Vyhrál " + hrac)
return True
if plocha[2][0] == plocha[2][1] and plocha[2][1] == plocha[2][2] and plocha[2][2] != " ":
print("Vyhrál " + hrac)
return True
if plocha[0][0] == plocha[1][0] and plocha[1][0] == plocha[2][0] and plocha[2][0] != " ":
print("Vyhrál " + hrac)
return True
if plocha[0][1] == plocha[1][1] and plocha[1][1] == plocha[2][1] and plocha[2][1] != " ":
print("Vyhrál " + hrac)
return True
if plocha[0][2] == plocha[1][2] and plocha[1][2] == plocha[2][2] and plocha[2][2] != " ":
print("Vyhrál " + hrac)
return True
if plocha[0][0] == plocha[1][1] and plocha[1][1] == plocha[2][2] and plocha[2][2] != " ":
print("Vyhrál " + hrac)
return True
if plocha[0][2] == plocha[1][1] and plocha[1][1] == plocha[2][0] and plocha[2][0] != " ":
print("Vyhrál " + hrac)
return True
return False
def vytiskni():
print(plocha[0][0] + "|" + plocha[0][1] + "|" + plocha[0][2])
print("-+-+-")
print(plocha[1][0] + "|" + plocha[1][1] + "|" + plocha[1][2])
print("-+-+-")
print(plocha[2][0] + "|" + plocha[2][1] + "|" + plocha[2][2])
vytiskni()
while True:
x = input()
y = x.split()
if plocha[int(y[0])][int(y[1])] == " ":
plocha[int(y[0])][int(y[1])] = hrac
if kontrola():
vytiskni()
break
if hrac == "X":
hrac = "O"
else:
hrac = "X"
vytiskni()

@ -0,0 +1,181 @@
grid = [
["", "", ""],
["", "", ""],
["", "", ""]
]
x = False
def play1():
global x_input_1
global y_input_1
true_x = False
true_y = False
true_taken_1 = False
print("Now will play player 1")
while not true_taken_1:
while not true_x:
x_input_1 = int(input("Enter x axis position (1, 2, 3): "))
if x_input_1 == 1:
true_x = True
elif x_input_1 == 2:
true_x = True
elif x_input_1 == 3:
true_x = True
else:
print("Try again (1, 2, 3)")
while not true_y:
y_input_1 = int(input("Enter y axis position (1, 2, 3): "))
if y_input_1 == 1:
true_y = True
elif y_input_1 == 2:
true_y = True
elif y_input_1 == 3:
true_y = True
else:
print("Try again (1, 2, 3)")
if grid[x_input_1 - 1][y_input_1 - 1] not in ("X", "O"):
true_taken_1 = True
else:
print("That position is taken")
true_x = False
true_y = False
grid[x_input_1 - 1][y_input_1 - 1] = "X"
print(grid[0][0] + " | " + grid[1][0] + " | " + grid[2][0] + "\n" + "__" + " " + "__" + " " + "__" +
"\n" + grid[0][1] + " | " + grid[1][1] + " | " + grid[2][1] + "\n" + "__" + " " + "__" + " " + "__" +
"\n" + grid[0][2] + " | " + grid[1][2] + " | " + grid[2][2])
def play2():
print("Now will play player 2\n")
global x_input_2
global y_input_2
true_taken_2 = False
true_x_1 = False
true_y_1 = False
while not true_taken_2:
while not true_x_1:
x_input_2 = int(input("Enter x axis position (1, 2, 3): "))
if x_input_2 == 1:
true_x_1 = True
elif x_input_2 == 2:
true_x_1 = True
elif x_input_2 == 3:
true_x_1 = True
else:
print("Try again (1, 2, 3)")
while not true_y_1:
y_input_2 = int(input("Enter y axis position (1, 2, 3): "))
if y_input_2 == 1:
true_y_1 = True
elif y_input_2 == 2:
true_y_1 = True
elif y_input_2 == 3:
true_y_1 = True
else:
print("Try again (1, 2, 3)")
if grid[x_input_2 - 1][y_input_2 - 1] not in ("X", "O"):
true_taken_2 = True
else:
print("That position is taken")
true_x_1 = False
true_y_1 = False
grid[x_input_2 - 1][y_input_2 - 1] = "O"
print(grid[0][0] + " | " + grid[1][0] + " | " + grid[2][0] + "\n" + "__" + " " + "__" + " " + "__" +
"\n" + grid[0][1] + " | " + grid[1][1] + " | " + grid[2][1] + "\n" + "__" + " " + "__" + " " + "__" +
"\n" + grid[0][2] + " | " + grid[1][2] + " | " + grid[2][2])
def win():
global x
x0_y0 = grid[0][0]
x0_y1 = grid[0][1]
x0_y2 = grid[0][2]
x1_y0 = grid[1][0]
x1_y1 = grid[1][1]
x1_y2 = grid[1][2]
x2_y0 = grid[2][0]
x2_y1 = grid[2][1]
x2_y2 = grid[2][2]
if x0_y0 == x0_y1 == x0_y2 and x0_y0 == "X":
print("Player 1 wins")
x = True
elif x1_y0 == x1_y1 == x1_y2 and x1_y0 == "X":
print("Player 1 wins")
x = True
elif x2_y0 == x2_y1 == x2_y2 and x2_y0 == "X":
print("Player 1 wins")
x = True
elif x0_y0 == x1_y0 == x2_y0 and x0_y0 == "X":
print("Player 1 wins")
x = True
elif x0_y1 == x1_y1 == x0_y2 and x0_y1 == "X":
print("Player 1 wins")
x = True
elif x0_y2 == x1_y2 == x2_y2 and x0_y2 == "X":
print("Player 1 wins")
x = True
elif x0_y0 == x1_y1 == x2_y2 and x0_y0 == "X":
print("Player 1 wins")
x = True
elif x2_y0 == x1_y1 == x0_y2 and x2_y0 == "X":
print("Player 1 wins")
x = True
elif x0_y0 == x0_y1 == x0_y2 and x0_y0 == "O":
print("Player 2 wins")
x = True
elif x1_y0 == x1_y1 == x1_y2 and x1_y0 == "O":
print("Player 2 wins")
x = True
elif x2_y0 == x2_y1 == x2_y2 and x2_y0 == "O":
print("Player 2 wins")
x = True
elif x0_y0 == x1_y0 == x2_y0 and x0_y0 == "O":
print("Player 2 wins")
x = True
elif x0_y1 == x1_y1 == x0_y2 and x0_y1 == "O":
print("Player 2 wins")
x = True
elif x0_y2 == x1_y2 == x2_y2 and x0_y2 == "O":
print("Player 2 wins")
x = True
elif x0_y0 == x1_y1 == x2_y2 and x0_y0 == "O":
print("Player 2 wins")
x = True
elif x2_y0 == x1_y1 == x0_y2 and x2_y0 == "O":
print("Player 2 wins")
x = True
while not x:
win()
play1()
win()
if not x:
play2()
print("End of the game")

@ -0,0 +1,121 @@
board = ["[ ]", "[ ]", "[ ]",
"[ ]", "[ ]", "[ ]",
"[ ]", "[ ]", "[ ]"]
player_2 = False
Hra = True
kolo = 1
winner_2 = None
#spuští funkce ve správném pořadí
def tah():
Tah = Input_pos()
while Input_chack(Tah) == False:
Tah = Input_pos()
Move(Tah)
Show()
#zobarí hrací desku
def Show():
print(board[0], board[1], board[2], sep="")
print(board[3], board[4], board[5], sep="")
print(board[6], board[7], board[8], sep="")
print("_________")
#vrátí array s xy informací o tahu
def Input_pos():
player = int(player_2) + 1
print("hráč", player, "hraje")
vert = int(input("zadej sloupec (max 3)"))
while vert > 3:
print("vstup nesmí být větší než 3")
vert = int(input("zadej sloupec (max 3)"))
hor = int(input("zadej řádek (max 3)"))
while hor > 3:
hor = int(input("zadej řádek (max 3)"))
print("vstup nesmí být větší než 3")
tah = [vert, hor]
return To_Index(tah)
#změní políčko
def Move(tah):
if Input_chack(tah):
if player_2:
x = "O"
else:
x = "X"
board[tah] = "[" + x + "]"
else:
pass
#skontroluje platnost vstupu
def Input_chack(index):
if not board[index] == "[ ]":
print("pole je již obsazené")
return False
else:
return True
#převede array s xy pozicí do indexu
def To_Index(tah):
index = tah[0] + ((tah[1] - 1) * 3) - 1
return index
#skontroluje zde hráč nevyhrál
def Chack():
if board[0] == board[1] and board[0] == board[2] and not board[0] == "[ ]": #123
if board[0] == "[X]":
return True
else:
return False
elif board[3] == board[4] and board[3] == board[5] and not board[3] == "[ ]": #456
if board[3] == "[X]":
return True
else:
return False
elif board[6] == board[7] and board[6] == board[8] and not board[6] == "[ ]": #789
if board[6] == "[X]":
return True
else:
return False
elif board[0] == board[3] and board[0] == board[6] and not board[0] == "[ ]": #147
if board[0] == "[X]":
return True
else:
return False
elif board[1] == board[4] and board[1] == board[7] and not board[1] == "[ ]": #258
if board[1] == "[X]":
return True
else:
return False
elif board[2] == board[5] and board[2] == board[8] and not board[2] == "[ ]": #369
if board[2] == "[X]":
return True
else:
return False
elif board[0] == board[4] and board[0] == board[8] and not board[0] == "[ ]": #159
if board[0] == "[X]":
return True
else:
return False
elif board[2] == board[4] and board[2] == board[6] and not board[2] == "[ ]": #357
if board[2] == "[X]":
return True
else:
return False
else:
return None
Show()
while Hra:
tah()
if not Chack() == None:
Hra = False
if player_2:
print("Hráč 2 wyhrál v kole", kolo)
else:
print("Hráč 1 wyhrál v kole", kolo)
player_2 = not player_2
kolo += 1
if kolo > 8:
Hra = False
print("Hra skončila bez výsledku")

@ -0,0 +1,56 @@
values = {
0: " ",
1: "x",
2: "o"
}
board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
def print_board():
for i in range(3):
print("{}|{}|{}".format(values.get(board[i][0]), values.get(board[i][1]), values.get(board[i][2])))
print("-+-+-")
def get_user_input():
return [int(i) for i in input().split()]
def check_win():
for i in range(3):
if board[i][0] == board[i][1] == board[i][2] and board[i][0] != 0:
return True
if board[0][i] == board[1][i] == board[2][i] and board[0][i] != 0:
return True
if board[0][0] == board[1][1] == board[2][2] and board[1][1] != 0:
return True
if board[2][0] == board[1][1] == board[0][2] and board[1][1] != 0:
return True
return False
def main():
finished = False
plays = 1
while not finished:
print_board()
print("Hraje {}".format(values.get(plays)))
inp = False
while not inp:
try:
user_input = get_user_input()
if board[user_input[0]][user_input[1]] == 0:
board[user_input[0]][user_input[1]] = plays
if plays == 2:
plays = 0
plays += 1
inp = True
else:
print("Buňka je již obsazena")
except:
print("Váš vstup není platný")
finished = check_win()
print_board()
print("Konec hry")
if __name__ == "__main__":
main()

@ -0,0 +1,84 @@
#Jupyter je lepsi
import numpy as np
ikonky = [" "," X "," O "]
def render(board):
text = "+---+---+---+\n"
for row in board:
text += "|"
for column in row:
text += ikonky[column] + "|"
text += "\n+---+---+---+\n"
print(text)
print("""+---+---+---+
| 0 | 1 | 2 |
+---+---+---+
| 3 | 4 | 5 |
+---+---+---+
| 6 | 7 | 8 |
+---+---+---+""")
def compare3(a,b,c):
return a == b and b == c and a != 0
def check(board, move):
#print(board, move)
end = False
#kontrola řádku
end = end or compare3(board[0, move[1]],board[1, move[1]],board[2, move[1]])
#kontrola sloupce
end = end or compare3(board[move[0], 0],board[move[0], 1],board[move[0], 2])
#kontrola diagnálně
end = end or compare3(board[0, 0],board[1, 1],board[2, 2])
end = end or compare3(board[0, 2],board[1, 1],board[2, 0])
return (end, 0 in board)
def inputMove():
x = ""
OK = False
while not OK:
x = input("Zadejte tah od 0 do 8 \n > ")
OK = x.isnumeric()
if OK:
OK = int(x) >= 0 and int(x) <= 8
if OK:
X = int(x)//3
Y = int(x)%3
OK = move((X, Y),1)
def move(move,player):
global board
global lastMove
OK = board[move] == 0
if OK:
board[move] = player
lastMove = move
return OK
from random import randint
def AImove():
#vim ze to neni minmax
while not move((randint(0,2),randint(0,2)), 2):
continue
return move
#hra
global board
board = np.zeros((3, 3), dtype=np.int)
global lastMove
lastMove = (0,0)
player = 1
render(board)
while (not check(board, lastMove)[0]) and check(board, lastMove)[1]:
if player == 1:
inputMove()
else:
AImove()
render(board)
player = (player%2)+1 #Hraje další hráč; 1 => 2; 2 => 1
if check(board, lastMove)[0]:
print("Vyhrál: "+ikonky[board[lastMove]])
else:
print("Remíza")
Loading…
Cancel
Save