Ship.java
1 package hlt; 2 3 public class Ship extends Entity { 4 private final int halite; 5 6 public Ship(final PlayerId owner, final EntityId id, final Position position, final int halite) { 7 super(owner, id, position); 8 this.halite = halite; 9 } 10 11 public boolean isFull() { 12 return halite >= Constants.MAX_HALITE; 13 } 14 15 public int getHalite() { 16 return halite; 17 } 18 19 public Command makeDropoff() { 20 return Command.transformShipIntoDropoffSite(id); 21 } 22 23 public Command move(final Direction direction) { 24 return Command.move(id, direction); 25 } 26 27 public Command stayStill() { 28 return Command.move(id, Direction.STILL); 29 } 30 31 static Ship _generate(final PlayerId playerId) { 32 final Input input = Input.readInput(); 33 34 final EntityId shipId = new EntityId(input.getInt()); 35 final int x = input.getInt(); 36 final int y = input.getInt(); 37 final int halite = input.getInt(); 38 39 return new Ship(playerId, shipId, new Position(x, y), halite); 40 } 41 42 @Override 43 public boolean equals(Object o) { 44 if (this == o) return true; 45 if (o == null || getClass() != o.getClass()) return false; 46 if (!super.equals(o)) return false; 47 48 Ship ship = (Ship) o; 49 50 return halite == ship.halite; 51 } 52 53 @Override 54 public int hashCode() { 55 int result = super.hashCode(); 56 result = 31 * result + halite; 57 return result; 58 } 59 }