Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public float positionEvaluation(Position p, boolean player) {
- int count = 0;
- TicTacToePosition pos = (TicTacToePosition) p;
- for (int i = 0; i < 9; i++) {
- if (pos.board[i] == 0) count++;
- }
- count = 10 - count;
- // prefer the center square:
- float base = 1.0f;
- if (pos.board[4] == TicTacToePosition.HUMAN &&
- player) {
- base += 0.4f;
- }
- if (pos.board[4] == TicTacToePosition.PROGRAM &&
- !player) {
- base -= 0.4f;
- }
- float ret = (base - 1.0f);
- if (wonPosition(p, player)) {
- return base + (1.0f / count);
- }
- if (wonPosition(p, !player)) {
- return -(base + (1.0f / count));
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement