Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. n = 6
  2.  
  3.  
  4. def empty_plan():
  5. return[[0 for i in range(n)]
  6. for j in range(n)]
  7.  
  8. def print_plan(plan):
  9. symbol = {0: ".", 1: "X", 2: "O", 3: "B"}
  10. for i in range(n):
  11. for j in range(n):
  12. print(symbol[plan[i][j]], end=" ")
  13. print()
  14. return
  15.  
  16. def game_over(plan):
  17. for i in range(n):
  18. for j in range(n):
  19. if plan[i][j] == 0:
  20. return False
  21. return True
  22.  
  23. def strategy_plan():
  24. from random import randint
  25. j = randint(1,6)
  26. k = randint(1,6)
  27. stancik = "%(j)d %(k)d" %{"j":j,"k":k}
  28. return stancik
  29.  
  30.  
  31.  
  32. def make_turn():
  33. plan = empty_plan()
  34. player = 1
  35.  
  36. c = input("press 1 to play PLAYER VS PLAYER. Press 2 to play against COMPUTER: ")
  37. while game_over(plan) == False:
  38. print_plan(plan)
  39.  
  40. if ((c ==1) and (player == 1 or player == 2)) or (c==2 and player == 1):
  41. move = input("Player "+str(player)+" move x y:")
  42. elif (c == 2) and (player == 2):
  43. strategy_plan()
  44. move = stancik
  45.  
  46.  
  47. x, y = list(map(int, move.split(" ")))
  48. x = x-1
  49. y = y-1
  50. if (plan[y][x] == 0) :
  51. if plan[y][x] == 0: plan[y][x] = player
  52. if x+1<n and plan[y][x+1] == 0 and y >=0 and x+1 >=0: plan[y][x+1] = 3
  53. if plan[y][x-1] == 0 and y >=0 and x-1 >=0: plan[y][x-1] = 3
  54. #vodorovně
  55. if plan[y-1][x] == 0 and y-1 >=0 and x >=0: plan[y-1][x] = 3
  56. if y+1<n and plan[y+1][x] == 0 and y+1 >=0 and x >=0: plan[y+1][x] = 3
  57. #nadpod
  58. 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
  59. 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
  60. if plan[y-1][x-1] == 0 and y-1 >=0 and x-1 >=0: plan[y-1][x-1] = 3
  61. 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
  62. #šikmo
  63. if game_over(plan) == True:
  64. print_plan(plan)
  65. print("zvítězil hráč číslo:", player)
  66. player = 3 - player
  67.  
  68.  
  69. return
  70.  
  71. def play(): # v zadaní je ať obsahuje funkci play :D :D
  72.  
  73. make_turn()
  74.  
  75.  
  76.  
  77. play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement