package uno.perwironegoro.boardgames.pawnrace;

import uno.perwironegoro.boardgames.Board;
import uno.perwironegoro.boardgames.Colour;
import uno.perwironegoro.boardgames.UtilsBoard;

public class BoardPR extends Board {
	public static final char ARBCHAR = '@';

	public BoardPR(BoardPR b) {
		super(b.getWidth(), b.getHeight());
		for (int x = 1; x <= b.getWidth(); x++) {
			for (int y = 1; y <= b.getHeight(); y++) {
				copyOntoBoard(b.getSquare(x, y));
			}
		}
	}

	public BoardPR(char blackGap, char whiteGap) {
		this(8, 8, blackGap, whiteGap);
	}

	public BoardPR(int width, int height, char whiteGap, char blackGap) {
		super(width, height);
		assert (width >= 2) : "Min board width: 2";
		assert (height >= 4) : "Max board height: 4";
		for (int x = 0; x < width; x++) {
			squares[x][height - 2].setOccupier(Colour.BLACK);
			squares[x][1].setOccupier(Colour.WHITE);
		}
		if (blackGap != ARBCHAR) {
			squares[UtilsBoard.alphaCharToIndex(blackGap) - 1][height - 2].setOccupier(Colour.NONE);
		}
		if (whiteGap != ARBCHAR) {
			squares[UtilsBoard.alphaCharToIndex(whiteGap) - 1][1].setOccupier(Colour.NONE);
		}
	}

	public void applyMove(MovePR move) {
		super.applyMove(move);

		if (move.isEnPassant()) {
			UtilsPR.getBoardSquareBefore(move.getTo(), this).setOccupier(Colour.NONE);
		}
	}

	public void unapplyMove(MovePR move) {
		super.unapplyMove(move);

		Colour movedPlayer = move.getTo().getOccupier();

		if (move.isEnPassant()) {
			getBoardSquare(UtilsPR.getBoardSquareBefore(move.getTo(), this)).setOccupier(movedPlayer.opposite());
		} else if (move.isCapture()) {
			getBoardSquare(move.getTo()).setOccupier(movedPlayer.opposite());
		}
	}
}

@@ -132,16 +132,62 @@
 olour;%0D%0A
+import uno.perwironegoro.boardgames.Symbols;%0D%0A
 import u
@@ -309,16 +309,71 @@
 = '@';%0D%0A
+%09private static final Symbols sym = new SymbolsPR();%0D%0A%09
 %0D%0A%09publi
@@ -1819,11 +1819,67 @@
 %09%7D%0D%0A%09%7D%0D%0A
+%09%0D%0A%09public void display() %7B%0D%0A%09%09super.display(sym);%0D%0A%09%7D%0D%0A
 %7D%0D%0A

abstracted the symbol display code