Advertisement
Guest User

Untitled

a guest
May 29th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. public Ruch alfaBeta(Plansza plansza, int gleb, boolean czyMax, Ruch ruch, int prev)
  2. {
  3. //System.out.print( ".");
  4. List<Ruch> ruchy = plansza.listaRuchow();
  5. //System.out.println(ruchy.size());
  6. Ruch wynik = null;
  7. Plansza nowa = plansza.kopia();
  8. Collections.shuffle(ruchy);
  9.  
  10. if( gleb>=glebokosc)
  11. {
  12. ruch.wynik = funkcjaOceny(nowa);
  13. System.out.print(ruch.wynik + ", ");
  14. return ruch;
  15. }
  16. else
  17. {
  18. if(czyMax)
  19. {
  20. int wynikNaj = Integer.MIN_VALUE;
  21. if(ruchy.size()>0)
  22. {
  23. for(Ruch r : ruchy)
  24. {
  25. if(r.skok)
  26. wynik = r;
  27. nowa.zrobRuch(r);
  28. Ruch nowyRuch = alfaBeta(nowa,gleb+1,false,r, wynikNaj);
  29. if(nowyRuch!=null)
  30. {
  31. wynik = r;
  32. if(nowyRuch.wynik > wynikNaj)
  33. {
  34. wynik.wynik = wynikNaj;
  35. if(wynikNaj > prev)
  36. {
  37. return wynik;
  38. }
  39. }
  40. wynikNaj = Math.max(nowyRuch.wynik,wynikNaj );
  41.  
  42. }
  43.  
  44. } return wynik!=null?wynik:ruch;
  45. }
  46.  
  47. }
  48. else
  49. {
  50. int wynikNaj = Integer.MAX_VALUE;
  51. if(ruchy.size()>0)
  52. {
  53. for(Ruch r : ruchy)
  54. {
  55. //if(r.skok)
  56. //wynik = r;
  57. nowa.zrobRuch(r);
  58. Ruch nowyRuch = alfaBeta(nowa,gleb+1,true,r, wynikNaj);
  59. if(nowyRuch!=null)
  60. {
  61. wynik = r;
  62. if(nowyRuch.wynik < wynikNaj)
  63. {
  64. wynik.wynik = wynikNaj;
  65. if(wynikNaj < prev)
  66. {
  67. return wynik;
  68. };
  69.  
  70. }
  71. wynikNaj = Math.min(nowyRuch.wynik,wynikNaj );
  72. //System.out.print(" MIN " + wynikNaj);
  73. }
  74. }
  75. }
  76. return wynik!=null?wynik:ruch;
  77. }
  78. return wynik!=null ?wynik:ruch;
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement