Advertisement
Robruizr

Untitled

Oct 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public float positionEvaluation(Position p, boolean player) {
  2. int count = 0;
  3. TicTacToePosition pos = (TicTacToePosition) p;
  4. for (int i = 0; i < 9; i++) {
  5. if (pos.board[i] == 0) count++;
  6. }
  7. count = 10 - count;
  8. // prefer the center square:
  9. float base = 1.0f;
  10. if (pos.board[4] == TicTacToePosition.HUMAN &&
  11. player) {
  12. base += 0.4f;
  13. }
  14. if (pos.board[4] == TicTacToePosition.PROGRAM &&
  15. !player) {
  16. base -= 0.4f;
  17. }
  18. float ret = (base - 1.0f);
  19. if (wonPosition(p, player)) {
  20. return base + (1.0f / count);
  21. }
  22. if (wonPosition(p, !player)) {
  23. return -(base + (1.0f / count));
  24. }
  25. return ret;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement