001 package rules;
002
003 import java.util.*;
004
005 import core.*;
006
007 /**
008 * Empty piece.
009 *
010 */
011 public class Spawn extends NoneSquare
012 {
013 /**
014 * @see Piece
015 */
016 public String getName()
017 {
018 return "s";
019 }
020
021 /**
022 * Constructs a new Destroy instance
023 */
024 public Spawn() { }
025
026 public String pieceString()
027 {
028 return "powerup_spawn";
029 }
030
031 public void postMove(GameState gs, Map<Position, Piece> move,
032 Position here) {
033 int[] dx = {1,1,0,-1,-1,-1,0,1};
034 int[] dy = {0,-1,-1,-1,0,1,1,1};
035 Position ans = null;
036 Board board = gs.getBoard();
037 for (int i = 0; i < 8; i++) {
038 if (!Position.isValid(here.getX() + dx[i],
039 here.getY() + dy[i]))
040 continue;
041 Position there = Position.get(here.getX() + dx[i],
042 here.getY() + dy[i]);
043 Piece p = move.get(there);
044 if (p == null)
045 p = board.get(there);
046 if (p instanceof Empty) {
047 ans = there;
048 break;
049 }
050 }
051 if (ans != null)
052 move.put(ans, move.get(here));
053 }
054 public int hashCode() {
055 return 14;
056 }
057 }