示例#1
0
 private void DoMove(object sender, PlayerIndexEventArgs e)
 {
     Game.StatusCurrent.Result   = (PossibleResult)ChessboardLogics.GetResult();
     to.OccupyingPiece           = from.OccupyingPiece;
     from.OccupyingPiece         = null;
     to.OccupyingPiece.PieceType = (PiecesTypes)Math.Abs(ChessboardLogics.GetPieceBySquare(to.index)) - 1;
     OnExit(sender, e);
 }
示例#2
0
        void ExecuteComputerMove(object state)
        {
            if (SelectedPiece != null)
            {
                SelectedPiece.IsSelected = false;
                SelectedPiece            = null;
                foreach (Square sqr in squares)
                {
                    sqr.IsSelected = false;
                }
            }

            string move = ChessboardLogics.GetAndMakeNextComputerMove();

            Game.StatusCurrent.Result = (PossibleResult)ChessboardLogics.GetResult();

            string strFrom  = move.Substring(0, 3);
            string strTo    = move.Substring(3, 3);
            string strPromo = String.Empty;

            try{ strPromo = move.Substring(6, 1); }catch (ArgumentOutOfRangeException) {};

            Square from = GetSquareFromString(strFrom);
            Square to   = GetSquareFromString(strTo);

            //move the piece
            Piece p = from.OccupyingPiece;

            from.OccupyingPiece         = null;
            to.OccupyingPiece           = p;
            to.OccupyingPiece.PieceType = (PiecesTypes)Math.Abs(ChessboardLogics.GetPieceBySquare(to.index)) - 1;
            //UpdateSquares();

            Game.FormCollection["frmGamePlayScreen"]["lblTurn"].Text =
                "It's " + Game.StatusCurrent.SideToMove + " turn";
            Game.FormCollection["frmGamePlayScreen"]["lblComputerMove"].Text =
                "Computer has moved " + strFrom + strTo;
            Game.FormCollection["frmGamePlayScreen"]["lblComputerTime"].Text = String.Empty;

            IsComputerMoving = false;
        }
示例#3
0
        public void UpdateSquares()
        {
            //int[] board = new int[125];
            //ChessboardLogics.GetChessboard(out board);

            for (int i = 0; i < 125; i++)
            {
                Square sq = squares[
                    4 - (i % 5),
                    4 - (int)(i / 25),
                    4 - (i / 5) % 5
                            ];

                sq.index = i;

                int piece = ChessboardLogics.GetPieceBySquare(i);
                if (piece < 8)
                {
                    PiecesTypes pt = (PiecesTypes)(Math.Abs(piece) - 1);
                    SideType    st;
                    if (piece < 0)
                    {
                        st = SideType.Black;
                    }
                    else
                    {
                        st = SideType.White;
                    }

                    new Piece(pt, Game, sq, st, squares);
                }
                else
                {
                    sq.OccupyingPiece = null;
                }
            }
        }