Exemplo n.º 1
0
        override public bool IsValidMove(BoardState board)
        {
            // First two moves need to be placements.
            bool correctPlayerIsActing = (board.GetActivePlayer() == Actor);
            bool normalTurn            = (board.HistoryMoveStack.Count >= 2);
            bool validStartingPosition = (board.IsInside(StartPosition));

            if (!correctPlayerIsActing || !normalTurn || !validStartingPosition)
            {
                return(false);
            }

            bool actorOwnsStack     = (board[StartPosition].Count > 0 && board[StartPosition].Peek().Owner == Actor);
            bool stoneLimitObeyed   = (NumStonesTaken <= board.BoardSize);
            bool enoughStones       = (NumStonesTaken <= board[StartPosition].Count);
            bool alwaysDroppedStone = (NumStonesDroppedPerField.Min() > 0);

            if (!actorOwnsStack || !stoneLimitObeyed || !enoughStones || !alwaysDroppedStone)
            {
                return(false);
            }

            // Moving a single capstone in the end can flatten a wall.
            bool canFlattenWall = (NumStonesDroppedPerField[NumStonesDroppedPerField.Count - 1] == 1 &&
                                   board[StartPosition].Peek().Type == StoneType.Capstone);

            for (int step = 0; step < NumStonesDroppedPerField.Count; ++step)
            {
                // Moving outside the field?
                Vector2Int pos = StartPosition + (step + 1) * MoveDirection.ToVector();
                if (!board.IsInside(pos))
                {
                    return(false);
                }

                // Can place on top?
                StoneType top          = board[pos].Count > 0 ? board[pos].Peek().Type : StoneType.FlatStone;
                bool      placeStone   = (top == StoneType.FlatStone);
                bool      flattenStone = (top == StoneType.StandingStone &&
                                          canFlattenWall &&
                                          step == NumStonesDroppedPerField.Count - 1);
                if (!placeStone && !flattenStone)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        override public bool IsValidMove(BoardState board)
        {
            bool correctPlayerIsActing = (board.GetActivePlayer() == Actor);
            bool emptyField            = (board[Position].Count == 0);
            bool actorIsOwner          = (Stone.Owner == Actor);

            // Only on the first move, the opposing players stone may be placed.
            if (board.HistoryMoveStack.Count < 2)
            {
                bool flatStone = (Stone.Type == StoneType.FlatStone);
                return(!actorIsOwner && flatStone && emptyField);
            }

            // Make sure the owner has enough stones to place.
            PlayerState ownerState   = board.Players[(int)Stone.Owner];
            bool        enoughStones = Stone.Type == StoneType.Capstone
                                   ? (ownerState.NumCapstones > 0)
                                   : (ownerState.NumStones > 0);

            return(correctPlayerIsActing && actorIsOwner && emptyField && enoughStones);
        }