public static PlayingPiece[,] cloneField(PlayingPiece[,] board) { PlayingPiece[,] postField = new PlayingPiece[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (board [x, y] != null) { postField [x, y] = board [x, y].clone(); } } } return(postField); }
public Board playMove(Move move) { PlayingPiece[,] postField = cloneField(board); PlayingPiece movePiece = postField [move.start [0], move.start [1]]; postField [move.start [0], move.start [1]] = null; postField [move.target [0], move.target [1]] = movePiece; movePiece.setPos(move.target); movePiece.onPlayingMove(); if (move.type == PieceType.pawn) { postField = handlePawnSpecialls(postField, move, movePiece); } return(new Board(postField)); }
public void giveAnPeasant(PlayingPiece[,] board) { for (int i = -1; i <= 1; i += 2) { int[] sidePos = new int[2] { pos [0] + i, pos [1] }; SquareStatus temp = getSquareState(board, sidePos); if (temp != SquareStatus.occupied) { continue; } PlayingPiece p = board[sidePos[0], sidePos[1]]; if (p.type != PieceType.pawn || p.getColor() == playerColor) { continue; } (p as Pawn).enableEnPeasant(this); } }
private void initPlayerLists() { for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { PlayingPiece p = board [x, y]; if (p == null) { continue; } if (p.getColor() == Color.white) { whites.Add(p); } else { blacks.Add(p); } } } }
public void enableEnPeasant(PlayingPiece target) { canEnPeasant = true; enPeasantPos = target.getPos(); enPeasantPos [1] += playerColor == Color.white ? 1 : -1; }
private PlayingPiece[,] handlePawnSpecialls(PlayingPiece[,] postField, Move move, PlayingPiece movePiece) { if (Math.Abs(move.start [1] - move.target [1]) == 2) //Played double step, give enpeasant! { (movePiece as Pawn).giveAnPeasant(postField); } if (move.start [0] != move.target [0]) //Played enpeasant! remove targetEnpeasant { postField = (movePiece as Pawn).onPlayedOnPeasant(postField); } return(postField); }