Guest User

Untitled

a guest
Nov 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import random
  2. # 2 rozmerne pole, kde se hraci navzajem stridaji v tazich.
  3. # tah je mozno uskutecnit pouze v miste, ktere nesousedi s zadnym jinym prvkem na hraci plose.
  4. # hrac ktery uskutecni tah jako posledni (vyhral/prohral)
  5. # Umela inteligence 1. nahodna - ma pole moznosti a vybere z nich jednu nahodnou, 2. Pokud je urcitim zpusobem(sude, liche radky), urcene nalezitosti hraci plochy, tak muzeme urcit vyherni strategii.
  6. class Game:
  7. def __init__(self, cols, rows):
  8. self.cols = cols
  9. self.rows = rows
  10. self.plan = cols*[rows*['.']]
  11. #[ok]
  12. def print_plan(self):
  13. for x in range(self.cols):
  14. for y in range(self.rows):
  15. print(self.plan[x][y], end="")
  16. print()
  17.  
  18. #[x]
  19. def refresh_board(self):
  20. #take a board as an argument. return board with marked impossible turns.
  21. for x in range(self.cols):
  22. for y in range(self.rows):
  23. if(self.plan[x][y] == 'X'):
  24. mark_impossible_turns(x, y)
  25.  
  26. def mark_impossible_turns(self, x, y):
  27. if x > 0 and y > 0 and x < cols and y < rows:
  28.  
  29.  
  30.  
  31.  
  32. #[ok]
  33. def possible_spots(self, output):
  34. spots = []
  35. for x in range(self.cols):
  36. for y in range(self.rows):
  37. if self.plan[x][y] == '.':
  38. spots.append([x,y])
  39. if output:
  40. print("[" +str(x) +", "+str(y)+"]", end=", ")
  41. return spots
  42. #[ok]
  43. def check_turn(self, x, y):
  44. if self.plan[x][y] == ".":
  45. return True
  46. else:
  47. return False
  48. #[x]
  49. def make_turn(self, x, y):
  50. self.plan[x][y] = 'X'
  51. #self.refresh_board()
  52.  
  53. #[ok]
  54. def game_over(self):
  55. if(len(self.possible_spots(False)) == 0):
  56. return True
  57. else:
  58. return False
  59.  
  60.  
  61. def Game_play():
  62. game = Game(6,6)
  63. empty_position = game.possible_spots(False)
  64. ai_playing = False
  65. is_end = False
  66. while not game.game_over():
  67.  
  68. if(not ai_playing):
  69. refresh_board(board)
  70. print_plan(board)
  71. possible_spots(board, True)
  72. ai_playing = True
  73. else:
  74.  
  75. ai_playing = False
  76.  
  77. game= Game(6,6)
  78. game.print_plan()
  79. game.make_turn(3,2)
  80. game.print_plan()
Add Comment
Please, Sign In to add comment