Advertisement
Guest User

Untitled

a guest
May 5th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. class KancsosAllapot : AbsztraktÁllapot
  2. {
  3. //MEZŐK, AMIVEL LE TUDOM ÍRNI A KEZDŐÁLLAPOTOT
  4. int k3, k5, k8; //3,5,8 literes kancsó
  5. public override object Clone()
  6. {
  7. KancsosAllapot kancsóklón = new KancsosAllapot();
  8. kancsóklón.k3 = this.k3;
  9. kancsóklón.k5 = this.k5;
  10. kancsóklón.k8 = this.k8;
  11. return kancsóklón;
  12. }
  13.  
  14. public KancsosAllapot()
  15. {
  16. k3 = 3;
  17. k5 = 5;
  18. k8 = 0;
  19.  
  20. }
  21.  
  22. public override bool ÁllapotE()
  23. {
  24. return k3 >= 0 && k3 <= 3 && k5 >= 0 && k5 <= 5 && k8 >= 0 && k8 <= 8;
  25. }
  26.  
  27. public override bool CélÁllapotE()
  28. {
  29. return k5 == 4 && k8 == 4;
  30. }
  31.  
  32. public override int OperátorokSzáma()
  33. {
  34. return 6;
  35. }
  36.  
  37. public override bool SzuperOperátor(int i)
  38. {
  39. switch (i)
  40. {
  41. case 0: return atont35(); // átönt k3ból k5be
  42. case 1: return atont38();
  43. case 2: return atont53();
  44. case 3: return atont58();
  45. case 4: return atont83();
  46. case 5: return atont85();
  47. default: return false;
  48. }
  49. }
  50.  
  51. private bool atont85()
  52. {
  53. if (!preAtont85()) return false;
  54. int attoltheto = k8 + k3 <= 3 ? k8 : 3 - k3;
  55. k8 -= attoltheto;
  56. k3 += attoltheto;
  57. if (ÁllapotE()) return true;
  58. return false;
  59. }
  60.  
  61. private bool preAtont85()
  62. {
  63. return k8 > 0 && k5 < 5;
  64. }
  65.  
  66. private bool atont83()
  67. {
  68. if (!preAtont83()) return false;
  69. int attoltheto = k8 + k3 <= 3 ? k8 : 3 - k3;
  70. k8 -= attoltheto;
  71. k3 += attoltheto;
  72. if (ÁllapotE()) return true;
  73. return false;
  74. }
  75.  
  76. private bool preAtont83()
  77. {
  78. return k8 > 0 && k3 < 3;
  79. }
  80.  
  81. private bool atont58()
  82. {
  83. if (!preAtont58()) return false;
  84. int attoltheto = k5 + k8 <= 8 ? k5 : 8 - k8;
  85. k5 -= attoltheto;
  86. k8 += attoltheto;
  87. if (ÁllapotE()) return true;
  88. return false;
  89. }
  90.  
  91. private bool preAtont58()
  92. {
  93. return k5 > 0 && k8 < 8;
  94. }
  95.  
  96. private bool atont53()
  97. {
  98. if (!preAtont53()) return false;
  99. int attoltheto = k5 + k3 <= 3 ? k5 : 3 - k3;
  100. k5 -= attoltheto;
  101. k3 += attoltheto;
  102. if (ÁllapotE()) return true;
  103. return false;
  104. }
  105.  
  106. private bool preAtont53()
  107. {
  108. return k5 > 0 && k3 < 3;
  109. }
  110.  
  111. private bool atont38()
  112. {
  113. if (!preAtont38()) return false;
  114. int attotheto = k3 + k8 <= 8 ? k3 : 8 - k8;
  115. k3 -= attotheto;
  116. k8 += attotheto;
  117. if (ÁllapotE()) return true;
  118. return false;
  119. }
  120.  
  121. private bool preAtont38()
  122. {
  123. return k3 > 0 && k8 < 8;
  124. }
  125.  
  126. private bool atont35()
  127. {
  128. //előfeltétel
  129. if (!preAtont35()) return false;
  130. //állapotátmenet
  131. //mennyit lehet áttölteni
  132. int attoltheto = k3 + k5 <= 5 ? k3 : 5 - k5;
  133. k3 -= attoltheto;
  134. k5 += attoltheto;
  135. //állapot-e
  136. if (ÁllapotE())
  137. return true;
  138. return false;
  139. }
  140.  
  141. private bool preAtont35()
  142. {
  143. return k3 > 0 && k5 < 5;
  144. }
  145.  
  146. public override string ToString()
  147. {
  148. return k3 + " " + k5 + " " + k8;
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement