Guest User

Untitled

a guest
Jul 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. public Move chooseMove(Game game) {
  2.  
  3.         State s = game.getCurrentState();
  4.         List<Move> legalMoves = game.getLegalPacManMoves(); // find out what moves
  5.         // PacMan can make
  6.         double maxScore = -1000.0;
  7.         double minScore = 0.0;
  8.         Move maxMove = new Move();
  9.         Move minMove = new Move();
  10.  
  11.         for (Move m : legalMoves) {
  12.             List<List<Move>> ghostMoves = game.getLegalCombinedGhostMoves();
  13.             for (List n : ghostMoves) {
  14.                 State next = getNextState(s, m, n);
  15.                 double stateScore = evaluateState(s, next);
  16.                 double turnaroundPenalty = (lastMove == m.getOpposite() ? -10.0 : 0.0); // penalize a move that turns around
  17.                 stateScore += turnaroundPenalty;
  18.                 if (stateScore < minScore) {
  19.                     minScore = stateScore;
  20.                 }
  21.             }
  22.             if (minScore > maxScore) {
  23.                 maxScore = minScore;
  24.                 maxMove = m;
  25.             }
  26.         }
  27.         lastMove = maxMove; // remember what move we made for next time
  28.         return maxMove;
  29.     }
Add Comment
Please, Sign In to add comment