package net.hoo2.auth.dsproject.snake; import java.util.*; /** * @class HeuristicPlayer * @brief Represent a Heuristic Player in the Game * * The players are playing in a round-robin sequence and we keep track * for each one of them their playing order, score and place on the board. * This kind of player, is a cheater. He can control the dice. Not fair dude. * * @author Christos Choutouridis AEM:8997 * @email cchoutou@ece.auth.gr */ public class HeuristicPlayer extends Player { /** @name Constructors */ /** @{ */ /** Default doing nothing constructor */ public HeuristicPlayer() { super (); path = new ArrayList(); } /** * @brief The main constructor * * This creates a player for the game * @param playerId The player's to create * @param name The name of the player * @param board Reference to the board the player will play on. */ HeuristicPlayer (int playerId, String name) { super (playerId, name); path = new ArrayList(); } /* @} */ /** @name Get/Set interface */ /** @{ */ ArrayList getPath() { return path; } void setPath (ArrayList path) { this.path = path; } /** @} */ /** * Override dice functionality for the player * @return As this is called from the game only to select playing order * we cheat and return 1 */ @Override int dice () { return 1; } /** * Override get the next tile after the user's move * @param tile The initial tile * @return The tile after the move */ @Override int getNextMove (int tile) { Map moves = new HashMap(); double max = Double.NEGATIVE_INFINITY; double ev = Double.NEGATIVE_INFINITY; int roll = 0; // Evaluate each possible dice result and find the better one for (int r=1 ; r<=6 ; ++r) { moves.put (new Integer(r), evaluate (tile, r)); if ((ev = moves.get(r)) > max) { max = ev; roll = r; } } // Do the move and get the move data Integer[] move_data = Arrays.stream(move (tile, roll, true)) .boxed() .toArray(Integer[]::new); // Store the move data path.add(move_data); return tile + roll; // return the new tile position } /** * The Heuristic statistics version * @param verbose Flag to select the verbosity * @param sum Flag to select if we need to print a summarize of the user hystory */ @Override void statistics (boolean verbose, boolean sum) { if (sum) { // If we run the summarize int nSnakes =0; int nLadders =0; int nRedApples =0; int nBlackApples =0; // Calculate frequencies for (int i=0 ; i path; /**< Players history as required */ /** @} */ }