public override bool[,] PossibleMoviments() { bool[,] mat = new bool[Board.Lines, Board.Columns]; Position pos = new Position(0, 0); // Up pos.DefineValues(Position.Line - 1, Position.Column); while (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color) { break; } pos.Line -= 1; } // Down pos.DefineValues(Position.Line + 1, Position.Column); while (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color) { break; } pos.Line += 1; } // Right pos.DefineValues(Position.Line, Position.Column + 1); while (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color) { break; } pos.Column += 1; } // Left pos.DefineValues(Position.Line, Position.Column - 1); while (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color) { break; } pos.Column -= 1; } return(mat); }
private bool CanMove(Position pos) { Piece p = Board.UniquePiece(pos); return(p == null || p.Color != Color); }
public override bool[,] PossibleMoviments() { bool[,] mat = new bool[Board.Lines, Board.Columns]; Position pos = new Position(0, 0); if (Color == Color.White) { pos.DefineValues(Position.Line - 1, Position.Column); if (Board.IsPositionValid(pos) && Free(pos)) { mat[pos.Line, pos.Column] = true; } pos.DefineValues(Position.Line - 2, Position.Column); Position p2 = new Position(Position.Line - 1, Position.Column); if (Board.IsPositionValid(p2) && Free(p2) && Board.IsPositionValid(pos) && Free(pos) && ManyMoves == 0) { mat[pos.Line, pos.Column] = true; } pos.DefineValues(Position.Line - 1, Position.Column - 1); if (Board.IsPositionValid(pos) && IsThereEnemy(pos)) { mat[pos.Line, pos.Column] = true; } pos.DefineValues(Position.Line - 1, Position.Column + 1); if (Board.IsPositionValid(pos) && IsThereEnemy(pos)) { mat[pos.Line, pos.Column] = true; } // #SpecialPlay // EnPassant if (Position.Line == 3) { Position left = new Position(Position.Line, Position.Column - 1); if (Board.IsPositionValid(left) && IsThereEnemy(left) && Board.UniquePiece(left) == Match.VulnerableEnPassant) { mat[left.Line - 1, left.Column] = true; } Position right = new Position(Position.Line, Position.Column + 1); if (Board.IsPositionValid(right) && IsThereEnemy(right) && Board.UniquePiece(right) == Match.VulnerableEnPassant) { mat[right.Line - 1, right.Column] = true; } } } else { pos.DefineValues(Position.Line + 1, Position.Column); if (Board.IsPositionValid(pos) && Free(pos)) { mat[pos.Line, pos.Column] = true; } Position p2 = new Position(Position.Line + 1, Position.Column); pos.DefineValues(Position.Line + 2, Position.Column); if (Board.IsPositionValid(p2) && Free(p2) && Board.IsPositionValid(pos) && Free(pos) && ManyMoves == 0) { mat[pos.Line, pos.Column] = true; } pos.DefineValues(Position.Line + 1, Position.Column + 1); if (Board.IsPositionValid(pos) && IsThereEnemy(pos)) { mat[pos.Line, pos.Column] = true; } pos.DefineValues(Position.Line + 1, Position.Column - 1); if (Board.IsPositionValid(pos) && IsThereEnemy(pos)) { mat[pos.Line, pos.Column] = true; } // #SpecialPlay // EnPassant if (Position.Line == 4) { Position left = new Position(Position.Line, Position.Column - 1); if (Board.IsPositionValid(left) && IsThereEnemy(left) && Board.UniquePiece(left) == Match.VulnerableEnPassant) { mat[left.Line + 1, left.Column] = true; } Position right = new Position(Position.Line, Position.Column + 1); if (Board.IsPositionValid(right) && IsThereEnemy(right) && Board.UniquePiece(right) == Match.VulnerableEnPassant) { mat[right.Line + 1, right.Column] = true; } } } return(mat); }
private bool Free(Position position) { return(Board.UniquePiece(position) == null); }
private bool IsThereEnemy(Position position) { Piece p = Board.UniquePiece(position); return(p != null && p.Color != Color); }
public override bool[,] PossibleMoviments() { bool[,] mat = new bool[Board.Lines, Board.Columns]; Position pos = new Position(0, 0); // Up pos.DefineValues(Position.Line - 1, Position.Column); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Up + Right pos.DefineValues(Position.Line - 1, Position.Column + 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Right pos.DefineValues(Position.Line, Position.Column + 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Right + Down pos.DefineValues(Position.Line + 1, Position.Column + 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Down pos.DefineValues(Position.Line + 1, Position.Column); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Down + Left pos.DefineValues(Position.Line + 1, Position.Column - 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Left pos.DefineValues(Position.Line, Position.Column - 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // Left + Up pos.DefineValues(Position.Line - 1, Position.Column - 1); if (Board.IsPositionValid(pos) && CanMove(pos)) { mat[pos.Line, pos.Column] = true; } // #SpecialPlay if (ManyMoves == 0 && !Match.Check) { // Castle Kingside - roque pequeno Position positionOfRook = new Position(Position.Line, Position.Column + 3); if (testRookToCastle(positionOfRook)) { Position p1 = new Position(Position.Line, Position.Column + 1); Position p2 = new Position(Position.Line, Position.Column + 2); if (Board.UniquePiece(p1) == null && Board.UniquePiece(p2) == null) { mat[Position.Line, Position.Column + 2] = true; } { } } // Castle Queenside - roque grande Position positionOfRookQueenSide = new Position(Position.Line, Position.Column - 4); if (testRookToCastle(positionOfRookQueenSide)) { Position p1 = new Position(Position.Line, Position.Column - 1); Position p2 = new Position(Position.Line, Position.Column - 2); Position p3 = new Position(Position.Line, Position.Column - 3); if (Board.UniquePiece(p1) == null && Board.UniquePiece(p2) == null && Board.UniquePiece(p3) == null) { mat[Position.Line, Position.Column - 2] = true; } { } } } return(mat); }
private bool testRookToCastle(Position pos) { Piece p = Board.UniquePiece(pos); return(p != null && p is Rook && p.Color == Color && ManyMoves == 0); }