Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. package checkers; // Ten pakiet jest wymagany - nie usuwaj go
  2. public class EvaluatePosition // Ta klasa jest wymagana - nie usuwaj jej
  3. {
  4. static private final int WIN=Integer.MAX_VALUE/2;
  5. static private final int LOSE=Integer.MIN_VALUE/2;
  6. static private boolean _color; // To pole jest wymagane - nie usuwaj go
  7. static public void changeColor(boolean color) // Ta metoda jest wymagana - nie zmieniaj jej
  8. {
  9. _color=color;
  10. }
  11. static public boolean getColor() // Ta metoda jest wymagana - nie zmieniaj jej
  12. {
  13. return _color;
  14. }
  15. static public int evaluatePosition(AIBoard board) // Ta metoda jest wymagana. Jest to główna metoda heurystyki - umieść swój kod tutaj
  16. {
  17. int myRating=0;
  18. int opponentsRating=0;
  19. int size=board.getSize();
  20. int sep = (int)Math.ceil(size/4);
  21. int poziom1 = sep;
  22. int poziom2 = sep*2;
  23. int poziom3 = sep*3;
  24.  
  25. for (int i=0;i<size;i++)
  26. {
  27. for (int j=(i+1)%2;j<size;j+=2)
  28. {
  29. if (!board._board[i][j].empty) // pole nie jest puste
  30. {
  31. if (board._board[i][j].white==getColor()) // to jest moj pionek
  32. {
  33.  
  34. if(i<poziom1)
  35. myRating+=1;
  36. else if(i<poziom2)
  37. myRating+=5;
  38. else if(i<poziom3)
  39. myRating+=10;
  40. else
  41. myRating+=20;
  42.  
  43. if( i+2 < size) { //bicie do przodu
  44. if( j+2 < size ) { // bicie w lewo
  45. if( !board._board[i+1][j+1].empty && board._board[i+1][j+1].white!=getColor() ) { //nie puste pole i pionek przeciwnika
  46. if( board._board[i+2][j+2].empty ) //puste pole, możliwe bycie
  47. myRating+=30;
  48. }
  49. }
  50. if( j-2 < size ) { // bicie w prawo
  51. if( !board._board[i+1][j-1].empty && board._board[i+1][j-1].white!=getColor() ) { //nie puste pole i pionek przeciwnika
  52. if( board._board[i+2][j-2].empty ) //puste pole, możliwe bycie
  53. myRating+=30;
  54. }
  55. }
  56. }
  57.  
  58. if (board._board[i][j].king) myRating+=30; // to jest moja damka
  59. else myRating+=1 ; // to jest moj pionek
  60. }
  61. else
  62. {
  63.  
  64. if(i<poziom1)
  65. opponentsRating+=20;
  66. else if(i<poziom2)
  67. opponentsRating+=10;
  68. else if(i<poziom3)
  69. opponentsRating+=5;
  70. else
  71. opponentsRating+=1;
  72.  
  73. if( i-2 < size) { //bicie do przodu
  74. if( j+2 < size ) { // bicie w lewo
  75. if( !board._board[i-1][j+1].empty && board._board[i-1][j+1].white==getColor() ) { //nie puste pole i moj pionek
  76. if( board._board[i-2][j+2].empty ) //puste pole, możliwe bycie
  77. opponentsRating+=30;
  78. }
  79. }
  80. if( j-2 < size ) { // bicie w prawo
  81. if( !board._board[i-1][j-1].empty && board._board[i+1][j-1].white==getColor() ) { //nie puste pole i moj pionek
  82. if( board._board[i-2][j-2].empty ) //puste pole, możliwe bycie
  83. opponentsRating+=30;
  84. }
  85. }
  86. }
  87.  
  88. if (board._board[i][j].king) opponentsRating+=30; // to jest damka przeciwnika
  89. else opponentsRating+=1;
  90. }
  91. }
  92. }
  93. }
  94. //Judge.updateLog("Tutaj wpisz swoją wiadomość - zobaczysz ją w oknie log\n");
  95. if (myRating==0) return LOSE; // przegrana
  96. else if (opponentsRating==0) return WIN; // wygrana
  97. else return myRating-opponentsRating;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement