from rute import Rute from spiller import Spiller class Brett: def __init__(self): self._brett = [[Rute(), Rute(), Rute()], [Rute(), Rute(), Rute()], [Rute(), Rute(), Rute()]] self._spiller1 = None self._spiller2 = None def legg_til_spiller(self, symbol): if self._spiller1 is None: self._spiller1 = Spiller(symbol) elif self._spiller2 is None: self._spiller2 = Spiller(symbol) else: print("Det er allerede to spillere") def plasser_brikke(self, spiller, x, y): if x >= 0 and x <= 2 and y >= 0 and y <= 2: rute = self._brett[x][y] if rute.er_ledig(): rute.plasser_brikke(spiller) else: print(f"Beklager {x},{y} er opptatt") def sjekk_vinner(self): for rad in self._brett: if rad[0].hent_symbol() == rad[1].hent_symbol() == rad[2].hent_symbol() and rad[0].hent_symbol() is not None: return rad[0].hent_symbol() for kol in range(2): if self._brett[0][kol].hent_symbol() == self._brett[1][kol].hent_symbol() == self._brett[2][kol] and self._brett[0][kol].hent_symbol() is not None: return self._brett[0][kol].hent_symbol() if self._brett[0][0].hent_symbol() == self._brett[1][1].hent_symbol() == self._brett[2][2].hent_symbol() and self._brett[0][0].hent_symbol() is not None: return self._brett[0][0].hent_symbol() # def legg_til_spiller(self, symbol): # if spiller1 == None: # spiller1 = Spiller(symbol) # elif spille2 == None: # spiller2 = Spiller(symbol) # else: # print("Beklager det er allerede to spillere") # def plasser_brikke(self, spiller, x, y): # if x >= 0 and x <= 3 and y >= 0 and y <= 3: # if self._brett[x][y].er_opptatt() == None: # self._brett[x][y].plasser_brikke(spiller) # else: # print("Du kan ikke sette en brikke der") # else: # print("Venligst skriv inn gyldige koordinater") # def sjekk_vinner(self): # for rad in self._brett: # if rad[0] == rad[1] == rad[2] and rad[0] is not None: # return rad[0] # for kolonne in range(3): # if self._brett[0][kolonne] == self._brett[1][kolonne] == self._brett[2][kolonne] and self._brett[0][kolonne] is not None: # return self._brett[0][kolonne] # if self._brett[0][0] == self._brett[1][1] == self._brett[2][2] and self._brett[0][0] is not None: # return self._brett[0][0] # if self._brett[0][2] == self._brett[1][1] == self._brett[2][0] and self._brett[0][2] is not None: # return self._brett[0][2] mitt_brett = Brett()