Files
mestint/ora1/sajat.py

44 lines
1.6 KiB
Python
Raw Permalink Normal View History

2025-03-03 12:34:16 +01:00
from keres import *
class Korso(Feladat): # feladat osztaly a szuroje
def __init__(self, kezdo, cél):
super().__init__(kezdo, cél)
self.korsok=(3,5,8) #korsok meretei
def célteszt(self, allapot:tuple[int,int,int]) -> bool:
2025-03-10 16:46:29 +01:00
if allapot[0] == self.cél or allapot[1] == self.cél or allapot[2] == self.cél:
2025-03-03 12:34:16 +01:00
#teljesult a cél allpot
return True
else:
return False
def rákövetkező(self, allapot: tuple[int,int,int]) -> list[tuple[str, tuple[int,int,int]]]:
lepesek = []
for i in range(3):
for j in range(3):
2025-03-10 16:46:29 +01:00
if i != j: #nem toltunk onmagabol onamagaba
2025-03-03 12:34:16 +01:00
if allapot[i] > 0 and allapot[j] < self.korsok[j]: #van e folyadek vagy televan a korso:
m = min(allapot[i], self.korsok[j]-allapot[j]) #self.korsok[j] max(Hj)-aj
tmp_allapot = list(allapot) #ezzel szerkesztheto a tuple
tmp_allapot[i] -= m
2025-03-10 10:34:06 +01:00
tmp_allapot[j] += m
2025-03-03 12:34:16 +01:00
tmp = (f'{i+1}-bol toltok {j+1}-be {m} litert', tuple(tmp_allapot))
lepesek.append(tmp) #amit a listaba rakunk
return lepesek
2025-03-10 16:46:29 +01:00
h3 = Korso((2,2,3), 4)
2025-03-03 12:34:16 +01:00
print(h3.rákövetkező(h3.kezdő))
2025-03-10 16:46:29 +01:00
print(h3.célteszt((2,5,6)))
2025-03-03 12:34:16 +01:00
2025-03-10 10:34:06 +01:00