Ejemplo n.º 1
0
        private void ApplyMove(GameState game)
        {
            int dR, dC;

            if (Direction == MoveDirection.Left)
            {
                dR = 0;
                dC = -1;
            }
            else if (Direction == MoveDirection.Right)
            {
                dR = 0;
                dC = 1;
            }
            else if (Direction == MoveDirection.Up)
            {
                dR = 1;
                dC = 0;
            }
            else
            {
                dR = -1;
                dC = 0;
            }
            PieceStack stack = game.Board[Row, Column].Grab(NumMoved);

            for (int i = 0; i < Drops.Count; i++)
            {
                int        row = Row + dR * (i + 1);
                int        col = Column + dC * (i + 1);
                PieceStack dst = game.Board[row, col];
                stack.Drop(dst, Drops[i]);
            }
        }
Ejemplo n.º 2
0
        private bool IsLegalMove(GameState game, out string reason)
        {
            TakBoard boardState = game.Board;

            // if we're moving more pices than are in the stack
            if (boardState[Row, Column].Size < NumMoved || boardState[Row, Column].Size == 0)
            {
                reason = "Not enough pieces in stack";
                return(false);
            }

            // we actually own the stack being moved
            if (boardState[Row, Column].Top.Color != PieceColor)
            {
                reason = "Stack belongs to another player";
                return(false);
            }

            // if we're moving more pieces than the carry limit
            if (boardState.Size < NumMoved)
            {
                reason = "Carry limit exceeded";
                return(false);
            }

            // if we're moving so far that we'd fall off the edge of the board
            if ((Direction == MoveDirection.Up && Row + Drops.Count >= boardState.Size) ||
                (Direction == MoveDirection.Down && Row - Drops.Count < 0) ||
                (Direction == MoveDirection.Right && Column + Drops.Count >= boardState.Size) ||
                (Direction == MoveDirection.Left && Column - Drops.Count < 0))
            {
                reason = "Not enough room to move in that direction";
                return(false);
            }

            // if we're placing non-capstones on walls, or any piece on a capstone
            int dR, dC;

            if (Direction == MoveDirection.Left)
            {
                dR = 0;
                dC = -1;
            }
            else if (Direction == MoveDirection.Right)
            {
                dR = 0;
                dC = 1;
            }
            else if (Direction == MoveDirection.Up)
            {
                dR = 1;
                dC = 0;
            }
            else
            {
                dR = -1;
                dC = 0;
            }
            PieceStack src = boardState[Row, Column].NonDestructiveGrab(NumMoved);

            for (int i = 0; i < Drops.Count; i++)
            {
                int        row = Row + dR * (i + 1);
                int        col = Column + dC * (i + 1);
                PieceStack dst = boardState[row, col];

                if (!src.CanDrop(dst, Drops[i]))
                {
                    reason = string.Format("Cannot drop piece on {0}{1}", (char)(col + 'a'), row + 1);
                    return(false);
                }

                src.Drop(Drops[i]);
            }

            // if we reach here then the move is legal
            reason = "";
            return(true);
        }