Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import numpy as np
  2. from copy import deepcopy
  3. class Nod:
  4. def __init__(self, nrStare, stare, parinte, scor):
  5. self.nrStare = nrStare
  6. self.stare = stare
  7. self.parinte = parinte
  8. self.scor = scor
  9. def afisare(self):
  10. print("{} {} {} {}".format(self.nrStare, self.stare, self.parinte, self.scor))
  11.  
  12. frontiera = []
  13. teritoriu = []
  14. si = [0, 0, 0, 0, 0]
  15. sf = [1, 2, 3, 4, 5]
  16. nodInit = Nod(1, si, 0, 0)
  17. frontiera.append(nodInit)
  18. F=50
  19. scorMax=0
  20. nodMax=nodInit
  21. ok=False
  22. nr = 2
  23. while not ok:
  24. if len(frontiera) == 0:
  25. print("Insucces")
  26. break
  27. nodCurent = frontiera.pop()
  28. # print(nodCurent.stare)
  29.  
  30. if 0 in nodCurent.stare:
  31. teritoriu.append(Nod(nr, nodCurent.stare, nodCurent.nrStare, 0))
  32. else:
  33. nodCurent.scor = F
  34. if nodCurent.stare[0] == 3:
  35. nodCurent.scor+=5
  36. if nodCurent.stare[1] == 5:
  37. nodCurent.scor+=4
  38. for i in range(4):
  39. if nodCurent.stare[i] % 2 == nodCurent.stare[i+1] % 2:
  40. nodCurent.scor-=8
  41. if nodCurent.scor > scorMax:
  42. scorMax = nodCurent.scor
  43. nodMax = nodCurent
  44. teritoriu.append(Nod(nr, nodCurent.stare, nodCurent.nrStare, nodCurent.scor))
  45.  
  46. for element in range(1,6):
  47. if element not in nodCurent.stare:
  48. poz = 0
  49. for x in nodCurent.stare:
  50. if x != 0:
  51. poz +=1
  52.  
  53. succesor = deepcopy(nodCurent)
  54. succesor.stare[poz] = element
  55. nr+=1
  56. if succesor not in frontiera and succesor not in teritoriu:
  57. if succesor.stare == sf:
  58. print(nodMax.stare)
  59. # afisare.Solutie()
  60. ok=True
  61. exit(0)
  62. frontiera.append(succesor)
  63. # print(frontiera)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement