Exemplo n.º 1
0
 //payload for chooser response
 public Payload(bool error, string action, Figure f, coord pos)
 {
     this.startPos = pos;
       this.action = action;
       this.error = error;
       this.figure = f;
 }
Exemplo n.º 2
0
Arquivo: King.cs Projeto: feco93/Chess
        public bool IsInCheck(Figure[] figures)
        {
            foreach ( var figure in figures )
            {

            }
            return false;
        }
Exemplo n.º 3
0
Arquivo: King.cs Projeto: feco93/Chess
 public override bool IsValidMove(Figure[] figures, int newX, int newY)
 {
     if ( newX >= 1 && newX <= 8 &&
     Math.Abs(position.X - newX) <= 1 && Math.Abs(position.Y - newY) <= 1 &&
     !IsInCheck(figures) )
     {
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
        // constructor
        public Popup(Window parent, Figure[] f, Action<Figure, coord> callback, int scale)
            : base(Gtk.WindowType.Toplevel)
        {
            this.TransientFor = parent;
              this.SetPosition (Gtk.WindowPosition.CenterOnParent);
              this.Decorated = false;

              this.tileSize = new coord (10 * scale, 10 * scale);
              this.callback = callback;
              this.Title = "choose";
              this.figures = f;
              this.box = new HBox ();
              this.Add (this.box);
        }
Exemplo n.º 5
0
Arquivo: Rook.cs Projeto: feco93/Chess
 public override bool IsValidMove(Figure[] figures, int newX, int newY)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 //special move: castling
 private bool doCastling(Player player, coord start, coord end)
 {
     //castling is only possible if the figure on the start position is a king witch hasn' t moved
     if (this.getFieldFigureName(start) == "King" && this.fields [start.x, start.y].color == player.ToString() && this.fields [start.x, start.y].hasMoved == false)
     {
         //left side castling
         if (start.x + 2 == end.x && this.getFieldFigureName(new coord(start.x + 1, start.y)) == "Empty" && !Move(player, start, new coord(start.x + 1, start.y)).error)
         {
             //move the king a secound time
             if (!Move(player, new coord(start.x + 1, start.y), new coord(start.x + 2, start.y)).error)
             {
                 //save kings position to allow the rock to move
                 Figure tmpKingPosition = this.fields [end.x, end.y];
                 this.fields [end.x, end.y] = new Empty();
                 //move rock
                 if (!Move(player, new coord(7, start.y), new coord(4, start.y)).error)
                 {
                     this.fields [end.x, end.y] = tmpKingPosition;
                     return(true);
                 }
                 else
                 {
                     tmpKingPosition.hasMoved       = false;
                     this.fields [start.x, start.y] = tmpKingPosition;
                 }
             }
             else
             {
                 this.fields [start.x, start.y]          = this.fields [start.x + 1, start.y];
                 this.fields [start.x, start.y].hasMoved = false;
                 this.fields [start.x + 1, start.y]      = new Empty();
             }
         }
         //right side castling
         else if (start.x - 2 == end.x && this.getFieldFigureName(new coord(start.x - 1, start.y)) == "Empty" && !Move(player, start, new coord(start.x - 1, start.y)).error)
         {
             //move the king a secound time
             if (!Move(player, new coord(start.x - 1, start.y), new coord(start.x - 2, start.y)).error)
             {
                 //save kings position to allow the rock to move
                 Figure tmpKingPosition = this.fields [end.x, end.y];
                 this.fields [end.x, end.y] = new Empty();
                 //move rock
                 if (!Move(player, new coord(0, start.y), new coord(2, start.y)).error)
                 {
                     this.fields [end.x, end.y] = tmpKingPosition;
                     return(true);
                 }
                 else
                 {
                     tmpKingPosition.hasMoved       = false;
                     this.fields [start.x, start.y] = tmpKingPosition;
                 }
             }
             else
             {
                 this.fields [start.x, start.y]          = this.fields [start.x - 1, start.y];
                 this.fields [start.x, start.y].hasMoved = false;
                 this.fields [start.x - 1, start.y]      = new Empty();
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
 public FigureOnSquare(Figure figure, Square square)
 {
     Figure = figure;
     Square = square;
 }
Exemplo n.º 8
0
 public FigureOnSquare(Figure figure, Square square)
 {
     this.figure = figure;
     this.square = square;
 }
Exemplo n.º 9
0
 public void TestIsInCheck()
 {
     Figure[] figures = new Figure[0];
     Assert.IsFalse(whiteKing.IsInCheck(figures));
     Assert.IsFalse(blackKing.IsInCheck(figures));
 }
Exemplo n.º 10
0
 // Method for handling the chooser
 public void handleChooser(Figure figure, coord position)
 {
     updateGui (this.game.call (new Payload (false, "switchFigures", figure, position)));
 }
Exemplo n.º 11
0
 private void SetPosition(Figure figure, int x, int y)
 {
     figure.SetPosition(x, y);
     Figures[x, y] = figure;
 }
Exemplo n.º 12
0
 public FigureOnCord(Figure figure, Cord cord)
 {
     this.cord   = cord;
     this.figure = figure;
 }
Exemplo n.º 13
0
 private void SetPosition(Figure figure, Position position)
 {
     figure.SetPosition(position.Row, position.Column);
     Figures[position.Row, position.Column] = figure;
 }
Exemplo n.º 14
0
        public Figure GetFigurePosition(Figure figure)
        {
            Position Position = figure.GettPosition();

            return(Figures[Position.Row, Position.Column]);
        }
Exemplo n.º 15
0
        private bool isPathObstructed(Position origin, Position destination)
        {
            Figure figure = this.boardState[origin.x][origin.y];

            if (figure == null)
            {
                return(false);
            }

            if (figure is Knight)
            {
                return(false);
            }

            // Bishop same-row move
            if (origin.x == destination.x && origin.x - destination.x > 1)
            {
                int smallerOfTheTwo = origin.y > destination.y ? destination.y : origin.y;
                int largerOfTheTwo  = origin.y > destination.y ? origin.y : destination.y;
                for (int i = smallerOfTheTwo; i < largerOfTheTwo; i++)
                {
                    if (this.boardState[i][origin.y] != null)
                    {
                        // There is a piece that is in between therefore in this board state it is illegal.
                        return(true);
                    }
                }
            }
            else if (origin.y == destination.y && origin.y - destination.y > 1)
            {
                int smallerOfTheTwo = origin.x > destination.x ? destination.x : origin.x;
                int largerOfTheTwo  = origin.x > destination.x ? origin.x : destination.x;
                for (int i = smallerOfTheTwo; i < largerOfTheTwo; i++)
                {
                    if (this.boardState[origin.x][i] != null)
                    {
                        // There is a piece that is in between therefore in this board state it is illegal.
                        return(true);
                    }
                }
            }
            else // Must be either a bishop or knight specific move
                 // Out of those, only a bishop move can be obstructed
            {
                int xDelta;
                if (destination.x > origin.x)
                {
                    xDelta = -1;
                }
                else
                {
                    xDelta = 1;
                }

                int yDelta;
                if (destination.y > origin.y)
                {
                    yDelta = -1;
                }
                else
                {
                    yDelta = 1;
                }

                Position startPosition = origin;
                while (startPosition.IsValidPosition(this.BoardSize) && startPosition.x != destination.x && startPosition.y != destination.y)
                {
                    if (this.boardState[startPosition.x][startPosition.y] != null)
                    {
                        // This diagonal is obstructed and this move is illegal
                        return(true);
                    }
                    startPosition.x += xDelta;
                    startPosition.y += yDelta;
                }
            }



            return(false);
        }
Exemplo n.º 16
0
        private void MoveFigure(int x, int y, int xNew, int yNew, Figure[,] table = null)
        {
            if (table == null)
            {
                table = figureTable;
            }
            else
            {
                table = tempTable;
            }

            Figure oldFigure = table[x, y];

            oldFigure.Move(xNew, yNew);

            if (table == figureTable)
            {
                previousMove = new Tuple <PlayerType, FigureType, int, int, int, int>(onMove, oldFigure.type, x, y, xNew, yNew);
            }

            if (table[x, y] != null && table[x, y] is Pawn)
            {
                Pawn pawn = table[x, y] as Pawn;

                // Check if en passant
                if (xNew == x + pawn.Direction && (yNew == y - 1 || yNew == y + 1) && table[xNew, yNew] == null)
                {
                    table[x, yNew] = null;
                }

                table[xNew, yNew] = oldFigure;
                table[x, y]       = null;

                // Check for promotion (Upgrade this code!!!) - only in real move mode
                if (table == figureTable && (xNew == 0 || xNew == 7))
                {
                    new Promotion(onMove).ShowDialog();
                    FigureType promotionFigure = Promotion.promotedFigure;

                    switch (promotionFigure)
                    {
                    case FigureType.KNIGHT:
                        table[xNew, yNew] = new Knight(xNew, yNew, onMove, promotionFigure, this);
                        break;

                    case FigureType.BISHOP:
                        table[xNew, yNew] = new Bishop(xNew, yNew, onMove, promotionFigure, this);
                        break;

                    case FigureType.ROOK:
                        table[xNew, yNew] = new Rook(xNew, yNew, onMove, promotionFigure, this);
                        break;

                    case FigureType.QUEEN:
                        table[xNew, yNew] = new Queen(xNew, yNew, onMove, promotionFigure, this);
                        break;

                    default:
                        break;
                    }
                }
            }
            // Rokada (Castling)
            else if (table == figureTable && table[x, y] != null && table[x, y] is King && Math.Abs(yNew - y) == 2)
            {
                // Move king
                table[xNew, yNew] = oldFigure;
                table[x, y]       = null;

                // Small - move rook
                if (yNew > y)
                {
                    table[x, yNew + 1].Move(x, yNew - 1);

                    table[x, yNew - 1] = table[x, yNew + 1];
                    table[x, yNew + 1] = null;
                }
                // Big - move rook
                else
                {
                    table[x, yNew - 2].Move(x, yNew + 1);

                    table[x, yNew + 1] = table[x, yNew - 2];
                    table[x, yNew - 2] = null;
                }
            }
            else
            {
                table[xNew, yNew] = oldFigure;
                table[x, y]       = null;
            }
        }
Exemplo n.º 17
0
 public Engine()
 {
     figureTable = new Figure[8, 8]; //tabla koju vidimo
     tempTable   = new Figure[8, 8]; //tabla koja sluzi za prveravanje validnosti poteza
     Initialize();
 }
Exemplo n.º 18
0
        public List <Position> getPossibleMoves(Position from)
        {
            Figure SelectedFigure = Chessboard.GetFigureFromPosition(from);

            return(SelectedFigure.PossibleMoves(Chessboard));
        }
Exemplo n.º 19
0
 public abstract bool IsValidMove(Figure[] figures, int newX, int newY);