Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 6
- def empty_plan():
- return[[0 for i in range(n)]
- for j in range(n)]
- def print_plan(plan):
- symbol = {0: ".", 1: "X", 2: "O", 3: "B"}
- for i in range(n):
- for j in range(n):
- print(symbol[plan[i][j]], end=" ")
- print()
- return
- def game_over(plan):
- for i in range(n):
- for j in range(n):
- if plan[i][j] == 0:
- return False
- return True
- def strategy_plan():
- from random import randint
- j = randint(1,6)
- k = randint(1,6)
- stancik = "%(j)d %(k)d" %{"j":j,"k":k}
- return stancik
- def make_turn():
- plan = empty_plan()
- player = 1
- c = input("press 1 to play PLAYER VS PLAYER. Press 2 to play against COMPUTER: ")
- while game_over(plan) == False:
- print_plan(plan)
- if ((c ==1) and (player == 1 or player == 2)) or (c==2 and player == 1):
- move = input("Player "+str(player)+" move x y:")
- elif (c == 2) and (player == 2):
- strategy_plan()
- move = stancik
- x, y = list(map(int, move.split(" ")))
- x = x-1
- y = y-1
- if (plan[y][x] == 0) :
- if plan[y][x] == 0: plan[y][x] = player
- if x+1<n and plan[y][x+1] == 0 and y >=0 and x+1 >=0: plan[y][x+1] = 3
- if plan[y][x-1] == 0 and y >=0 and x-1 >=0: plan[y][x-1] = 3
- #vodorovně
- if plan[y-1][x] == 0 and y-1 >=0 and x >=0: plan[y-1][x] = 3
- if y+1<n and plan[y+1][x] == 0 and y+1 >=0 and x >=0: plan[y+1][x] = 3
- #nadpod
- if y+1<n and plan[y+1][x-1] == 0 and y+1 >=0 and x-1 >=0: plan[y+1][x-1] = 3
- if x+1<n and y+1<n and plan[y+1][x+1] == 0 and y+1 >=0 and x+1 >=0: plan[y+1][x+1] = 3
- if plan[y-1][x-1] == 0 and y-1 >=0 and x-1 >=0: plan[y-1][x-1] = 3
- if x+1<n and plan[y-1][x+1] == 0 and y-1 >=0 and x+1 >=0: plan[y-1][x+1] = 3
- #šikmo
- if game_over(plan) == True:
- print_plan(plan)
- print("zvítězil hráč číslo:", player)
- player = 3 - player
- return
- def play(): # v zadaní je ať obsahuje funkci play :D :D
- make_turn()
- play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement