コード例 #1
0
ファイル: Payload.cs プロジェクト: jsparber/chess
 //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;
 }
コード例 #2
0
ファイル: King.cs プロジェクト: feco93/Chess
        public bool IsInCheck(Figure[] figures)
        {
            foreach ( var figure in figures )
            {

            }
            return false;
        }
コード例 #3
0
ファイル: King.cs プロジェクト: 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;
 }
コード例 #4
0
ファイル: Popup.cs プロジェクト: jsparber/chess
        // 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);
        }
コード例 #5
0
ファイル: Rook.cs プロジェクト: feco93/Chess
 public override bool IsValidMove(Figure[] figures, int newX, int newY)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
ファイル: Board.cs プロジェクト: sanjaypatel180621/chess
 //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);
 }
コード例 #7
0
 public FigureOnSquare(Figure figure, Square square)
 {
     Figure = figure;
     Square = square;
 }
コード例 #8
0
ファイル: FigureOnSquare.cs プロジェクト: mbr0969/Chess
 public FigureOnSquare(Figure figure, Square square)
 {
     this.figure = figure;
     this.square = square;
 }
コード例 #9
0
ファイル: KingFigureTest.cs プロジェクト: feco93/Chess
 public void TestIsInCheck()
 {
     Figure[] figures = new Figure[0];
     Assert.IsFalse(whiteKing.IsInCheck(figures));
     Assert.IsFalse(blackKing.IsInCheck(figures));
 }
コード例 #10
0
ファイル: Graphics.cs プロジェクト: jsparber/chess
 // Method for handling the chooser
 public void handleChooser(Figure figure, coord position)
 {
     updateGui (this.game.call (new Payload (false, "switchFigures", figure, position)));
 }
コード例 #11
0
ファイル: Board.cs プロジェクト: KristiyanDimitrov/Chess
 private void SetPosition(Figure figure, int x, int y)
 {
     figure.SetPosition(x, y);
     Figures[x, y] = figure;
 }
コード例 #12
0
ファイル: FigureOnCord.cs プロジェクト: Perfecy/Chess
 public FigureOnCord(Figure figure, Cord cord)
 {
     this.cord   = cord;
     this.figure = figure;
 }
コード例 #13
0
ファイル: Board.cs プロジェクト: KristiyanDimitrov/Chess
 private void SetPosition(Figure figure, Position position)
 {
     figure.SetPosition(position.Row, position.Column);
     Figures[position.Row, position.Column] = figure;
 }
コード例 #14
0
ファイル: Board.cs プロジェクト: KristiyanDimitrov/Chess
        public Figure GetFigurePosition(Figure figure)
        {
            Position Position = figure.GettPosition();

            return(Figures[Position.Row, Position.Column]);
        }
コード例 #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);
        }
コード例 #16
0
ファイル: Engine.cs プロジェクト: Rillehh/chess
        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;
            }
        }
コード例 #17
0
ファイル: Engine.cs プロジェクト: Rillehh/chess
 public Engine()
 {
     figureTable = new Figure[8, 8]; //tabla koju vidimo
     tempTable   = new Figure[8, 8]; //tabla koja sluzi za prveravanje validnosti poteza
     Initialize();
 }
コード例 #18
0
ファイル: Game.cs プロジェクト: KristiyanDimitrov/Chess
        public List <Position> getPossibleMoves(Position from)
        {
            Figure SelectedFigure = Chessboard.GetFigureFromPosition(from);

            return(SelectedFigure.PossibleMoves(Chessboard));
        }
コード例 #19
0
ファイル: Figure.cs プロジェクト: feco93/Chess
 public abstract bool IsValidMove(Figure[] figures, int newX, int newY);