package uno.perwironegoro.boardgames;

import uno.perwironegoro.boardgames.pawnrace.SymbolsPR;

public abstract class Board {
	//The squares are pivoted from (1,1)!
	protected Square[][] squares;
	
	public Board(int width, int height) {
		squares = new Square[width][height];
		for(int x = 0; x < width; x++) {
			for(int y = 0; y < height; y++) {
				squares[x][y] = new Square(x + 1, y + 1);
			}
		}
	}
	
	public void applyMove(Move move) {
		copyOntoBoard(move.from);
		copyOntoBoard(move.to);
	}
	
	//Override to replace the taken piece
	public void unapplyMove(Move move) {
		getBoardSquare(move.from).setOccupier(move.to.getOccupier());
		getBoardSquare(move.to).setOccupier(Colour.NONE);
	}
	
	public Square getSquare(int x, int y) {
		return squares[x - 1][y - 1];
	}
	
	public Square getBoardSquareRelative(Square s, int xo, int yo) {
		return getSquare(s.getX() + xo, s.getY() + yo);
	}
	
	public Square getBoardSquare(Square s) {
		return getSquare(s.getX(), s.getY());
	}
	
	public void copyOntoBoard(Square s) {
		getBoardSquare(s).setOccupier(s.getOccupier());
	}
	
	public void display() {
		int marginSize = UtilsDisplay.digits(getHeight()) + 1;
		
		String alphaIndex = UtilsDisplay.fitInMargin(marginSize, "", ' ');
		
		for(int x = 0; x < getWidth(); x++) {
			alphaIndex += UtilsBoard.indexToStringUpper(x) + " ";
		}

		System.out.println(alphaIndex);
		System.out.println("");
		for(int y = getHeight() - 1; y >= 0; y--) {
			System.out.print(UtilsDisplay.fitInMargin(marginSize, String.valueOf(y + 1), ' '));
			
			for(int x = 0; x < getWidth(); x++) {
				System.out.print(SymbolsPR.symbolOf(squares[x][y].getOccupier()) + " ");
			}
			
			System.out.println(y + 1);
		}
		
		System.out.println("");
		System.out.println(alphaIndex);
		System.out.println("");
	}
	
	public int getWidth() {
		return squares.length;
	}
	
	public int getHeight() {
		return squares[0].length;
	}
}

@@ -38,67 +38,8 @@
 %0D%0A%0D%0A
-import uno.perwironegoro.boardgames.pawnrace.SymbolsPR;%0D%0A%0D%0A
 publ
@@ -1080,16 +1080,27 @@
 display(
+Symbols sym
 ) %7B%0D%0A%09%09i
@@ -1607,17 +1607,11 @@
 int(
-S
+s
 ym
-bolsPR
 .sym

abstracted the symbol display code