Example #1
0
 public CircledRookModel(ChessSide side, BoardPosition pos, int steps = 0) : base(side, (byte)CircledChessItemType.rook, pos, steps)
 {
 }
Example #2
0
        public static void GetBoardPositionsFromMoveCommand(string move_cmd, out BoardPosition from, out BoardPosition to)
        {
            byte x = 0, y = 0;

            x    = byte.Parse(((char)((byte)(move_cmd[0].ToString().ToUpper()[0]) - 17)).ToString());
            y    = (byte)(byte.Parse(move_cmd[1].ToString()));
            from = new BoardPosition(x, y - 1);
            x    = byte.Parse(((char)((byte)(move_cmd[2].ToString().ToUpper()[0]) - 17)).ToString());
            y    = (byte)(byte.Parse(move_cmd[3].ToString()));
            to   = new BoardPosition(x, y - 1);
        }
Example #3
0
        public override void DoAction(BoardPosition bp, bool back = false)
        {
            var fig = FigureOnBoard.GetFigureByPosition(bp);

            if (fig.IsNullObject && ChessMatchCurrentState.CurrentSelectedPosition == BoardPosition.None)
            {
                return;
            }

            var prev_bp = ChessMatchCurrentState.PreviousSelectedPosition;
            var curr_bp = ChessMatchCurrentState.CurrentSelectedPosition;

            SetBPs(ChessMatchCurrentState.CurrentSelectedPosition, bp);

            IChessItemModelShort chess = FigureOnBoard.GetFigureByPosition(ChessMatchCurrentState.CurrentSelectedPosition);
            IChessItemModelShort prev_chess;

            if (ChessMatchCurrentState.PreviousSelectedPosition.IsNullObject)
            {
                prev_chess = new NullChessItemModelShort();
            }
            else
            {
                prev_chess = FigureOnBoard.GetFigureByPosition(ChessMatchCurrentState.PreviousSelectedPosition);
            }

            //If there wasn't chosen any position on board
            if (prev_chess.IsNullObject)
            {
                //If there figure on this board position and it's side is current player's side
                if (!chess.IsNullObject && ChessMatchCurrentState.CurrentPlayer.Side == chess.Side)
                {
                    Select();
                }
            }
            //If one of the positions on board is chosen
            else
            {
                bool wasMoved = false;
                //Check for possible moves
                var         possibleMoves = new List <BoardPosition>();
                List <bool> temp;
                if (!back)
                {
                    possibleMoves = FigureOnBoard.GetPossibleMoves(ChessMatchCurrentState.PreviousSelectedPosition, out temp);
                }
                else
                {
                    for (byte i = 0; i < FigureOnBoard.BoardSizeX; i++)
                    {
                        for (byte j = 0; j < FigureOnBoard.BoardSizeY; j++)
                        {
                            possibleMoves.Add(new BoardPosition(i, j));
                        }
                    }
                }


                foreach (var possibleMove in possibleMoves)
                {
                    //If figure can move to this board position
                    if (possibleMove == ChessMatchCurrentState.CurrentSelectedPosition)
                    {
                        Move();

                        wasMoved = true;
                        break;
                    }
                }

                //If move was not possible
                if (!wasMoved)
                {
                    if (!chess.IsNullObject && chess.Side == prev_chess.Side)
                    {
                        Select();
                    }
                    else
                    {
                        SetBPs(prev_bp, curr_bp);
                    }
                }
            }
        }