Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public float positionEvaluation(Position p, boolean player) {
- int counterH = 0;
- int counterV = 0;
- int counterMainD = 0;
- int counterAltD = 0;
- boolean checkH = false;
- boolean checkV = false;
- boolean checkMainD = false;
- boolean checkAltD = false;
- float smallW = 0.1f;
- float mediumW = 0.4f;
- float bigW = 0.6f;
- float base = -1.0f;
- TicTacToePosition pos = (TicTacToePosition) p;
- for (int i = 0; i < 3; i++) {
- counterH = 0;
- counterV = 0;
- checkH = false;
- checkV = false;
- for (int j = 0; j < 3; j++) {
- counterH += pos.board[j];
- counterV += pos.board[i * 3 + j];
- checkH = pos.board[j] != 0 || checkH;
- checkV = pos.board[i * 3 + j] != 0 || checkV;
- }
- if (counterH == 0) {
- if(checkH){
- base += smallW;
- }
- } else if (counterH == 2) {
- base += (player) ? bigW : mediumW;
- } else if (counterH == -2) {
- base += (player) ? mediumW : bigW;
- }
- if (counterV == 0) {
- if(checkV){
- base += smallW;
- }
- } else if (counterV == 2) {
- base += (player) ? bigW : mediumW;
- } else if (counterV == -2) {
- base += (player) ? mediumW : bigW;
- }
- }
- counterMainD = pos.board[0] + pos.board[4] + pos.board[8];
- counterAltD = pos.board[2] + pos.board[4] + pos.board[6];
- checkMainD = pos.board[0] != 0 || pos.board[4] != 0 || pos.board[8] != 0;
- checkAltD = pos.board[2] != 0 || pos.board[4] != 0 || pos.board[6] != 0;
- if (counterMainD == 0) {
- if(checkMainD){
- base += smallW;
- }
- } else if (counterMainD == 2) {
- base += (player) ? bigW : mediumW;
- } else if (counterMainD == -2) {
- base += (player) ? mediumW : bigW;
- }
- if (counterAltD == 0) {
- if(checkAltD){
- base += smallW;
- }
- } else if (counterAltD == 2) {
- base += (player) ? bigW : mediumW;
- } else if (counterAltD == -2) {
- base += (player) ? mediumW : bigW;
- }
- if (pos.board[4] == TicTacToePosition.HUMAN &&
- player) {
- base -= mediumW;
- }
- if (pos.board[4] == TicTacToePosition.PROGRAM &&
- !player) {
- base += mediumW;
- }
- return player? -base:base;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement