Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # 2 rozmerne pole, kde se hraci navzajem stridaji v tazich.
- # tah je mozno uskutecnit pouze v miste, ktere nesousedi s zadnym jinym prvkem na hraci plose.
- # hrac ktery uskutecni tah jako posledni (vyhral/prohral)
- # 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.
- class Game:
- def __init__(self, cols, rows):
- self.cols = cols
- self.rows = rows
- self.plan = cols*[rows*['.']]
- #[ok]
- def print_plan(self):
- for x in range(self.cols):
- for y in range(self.rows):
- print(self.plan[x][y], end="")
- print()
- #[x]
- def refresh_board(self):
- #take a board as an argument. return board with marked impossible turns.
- for x in range(self.cols):
- for y in range(self.rows):
- if(self.plan[x][y] == 'X'):
- mark_impossible_turns(x, y)
- def mark_impossible_turns(self, x, y):
- if x > 0 and y > 0 and x < cols and y < rows:
- #[ok]
- def possible_spots(self, output):
- spots = []
- for x in range(self.cols):
- for y in range(self.rows):
- if self.plan[x][y] == '.':
- spots.append([x,y])
- if output:
- print("[" +str(x) +", "+str(y)+"]", end=", ")
- return spots
- #[ok]
- def check_turn(self, x, y):
- if self.plan[x][y] == ".":
- return True
- else:
- return False
- #[x]
- def make_turn(self, x, y):
- self.plan[x][y] = 'X'
- #self.refresh_board()
- #[ok]
- def game_over(self):
- if(len(self.possible_spots(False)) == 0):
- return True
- else:
- return False
- def Game_play():
- game = Game(6,6)
- empty_position = game.possible_spots(False)
- ai_playing = False
- is_end = False
- while not game.game_over():
- if(not ai_playing):
- refresh_board(board)
- print_plan(board)
- possible_spots(board, True)
- ai_playing = True
- else:
- ai_playing = False
- game= Game(6,6)
- game.print_plan()
- game.make_turn(3,2)
- game.print_plan()
Add Comment
Please, Sign In to add comment