Advertisement
Robruizr

sdaf

Oct 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. public float positionEvaluation(Position p, boolean player) {
  2.         int counterH = 0;
  3.         int counterV = 0;
  4.         int counterMainD = 0;
  5.         int counterAltD = 0;
  6.         boolean checkH = false;
  7.         boolean checkV = false;
  8.         boolean checkMainD = false;
  9.         boolean checkAltD = false;
  10.         float smallW = 0.1f;
  11.         float mediumW = 0.4f;
  12.         float bigW = 0.6f;
  13.         float base = -1.0f;
  14.         TicTacToePosition pos = (TicTacToePosition) p;
  15.         for (int i = 0; i < 3; i++) {
  16.             counterH = 0;
  17.             counterV = 0;
  18.             checkH = false;
  19.             checkV = false;
  20.             for (int j = 0; j < 3; j++) {
  21.                 counterH += pos.board[j];
  22.                 counterV += pos.board[i * 3 + j];
  23.                 checkH = pos.board[j] != 0 || checkH;
  24.                 checkV = pos.board[i * 3 + j] != 0 || checkV;
  25.             }
  26.             if (counterH == 0) {
  27.                 if(checkH){
  28.                     base += smallW;
  29.                 }
  30.             } else if (counterH == 2) {
  31.                 base += (player) ? bigW : mediumW;
  32.             } else if (counterH == -2) {
  33.                 base += (player) ? mediumW : bigW;
  34.             }
  35.             if (counterV == 0) {
  36.                 if(checkV){
  37.                     base += smallW;
  38.                 }
  39.             } else if (counterV == 2) {
  40.                 base += (player) ? bigW : mediumW;
  41.             } else if (counterV == -2) {
  42.                 base += (player) ? mediumW : bigW;
  43.             }
  44.         }
  45.         counterMainD = pos.board[0] + pos.board[4] + pos.board[8];
  46.         counterAltD = pos.board[2] + pos.board[4] + pos.board[6];
  47.         checkMainD = pos.board[0] != 0 ||  pos.board[4] != 0 || pos.board[8] != 0;
  48.         checkAltD = pos.board[2] != 0 ||  pos.board[4] != 0 || pos.board[6] != 0;
  49.  
  50.         if (counterMainD == 0) {
  51.             if(checkMainD){
  52.                 base += smallW;
  53.             }
  54.         } else if (counterMainD == 2) {
  55.             base += (player) ? bigW : mediumW;
  56.         } else if (counterMainD == -2) {
  57.             base += (player) ? mediumW : bigW;
  58.         }
  59.  
  60.         if (counterAltD == 0) {
  61.             if(checkAltD){
  62.                 base += smallW;
  63.             }
  64.         } else if (counterAltD == 2) {
  65.             base += (player) ? bigW : mediumW;
  66.         } else if (counterAltD == -2) {
  67.             base += (player) ? mediumW : bigW;
  68.         }
  69.  
  70.         if (pos.board[4] == TicTacToePosition.HUMAN &&
  71.                 player) {
  72.             base -= mediumW;
  73.         }
  74.         if (pos.board[4] == TicTacToePosition.PROGRAM &&
  75.                 !player) {
  76.             base += mediumW;
  77.         }
  78.  
  79.         return player? -base:base;
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement