//**************************************************************** //Protected Methods //Test the king's protected List <sbyte[]> TestForKingSafety(List <sbyte[]> unTestedMoves) { List <sbyte[]> testedMoves = new List <sbyte[]>(); //Finds the allied king's position King alliedKing = null; for (sbyte i = 0; i < ChessGame.rowSize; i++) { for (sbyte j = 0; j < ChessGame.colSize; j++) { if (pieces[i, j] != null && pieces[i, j].side == this.side && pieces[i, j] is King) { alliedKing = pieces[i, j] as King; } } } if (alliedKing == null) { throw new Exception("Where did your king go seriously"); } //Go through every move and test if the outcome would lead to the king being in chess foreach (var item in unTestedMoves) { Piece save = pieces[item[0], item[1]]; pieces[item[0], item[1]] = this; pieces[this.rowPos, this.colPos] = null; sbyte rowSave = this.rowPos; sbyte colSave = this.colPos; this.rowPos = item[0]; this.colPos = item[1]; if (!alliedKing.IsKingInDanger()) { testedMoves.Add(item); } pieces[item[0], item[1]] = save; this.rowPos = rowSave; this.colPos = colSave; pieces[this.rowPos, this.colPos] = this; } return(testedMoves); }