Exemplo n.º 1
0
        /// <summary>
        /// Place the piece in the given orientation at the given x,y position
        /// </summary>
        public void PerformPlacePiece(PieceBitmap bitmap, int x, int y)
        {
            if (PieceToPlace == null)
            {
                throw new Exception("Cannot place a piece when there is none to place");
            }
            if (!PieceToPlace.PossibleOrientations.Contains(bitmap))
            {
                throw new Exception("Given bitmap does not belong to the piece to be placed");
            }

            PlayerBoardState[PieceToPlacePlayer].Place(bitmap, x, y);

            //Check if they got 7x7 tile
            if (!SevenXSevenBonusPlayer.HasValue && PlayerBoardState[PieceToPlacePlayer].Has7x7Coverage)
            {
                SevenXSevenBonusPlayer = PieceToPlacePlayer;
            }


            var piece  = PieceToPlace;
            var player = PieceToPlacePlayer;

            PieceToPlace       = null;
            PieceToPlacePlayer = -1;

            PerformPurchasePlaceSteps45(piece, player);

            Logger.PlayerPlacedPiece(player, piece, x, y, bitmap);
        }
Exemplo n.º 2
0
        private void PerformPurchasePlaceSteps45(PieceDefinition piece, int player)
        {
            //4. Place the Patch on Your Quilt Board
            PlayerBoardUsedLocationsCount[player] += piece.TotalUsedLocations;
            PlayerButtonIncome[player]            += piece.ButtonsIncome;

            //5. Move Your Time Token
            if (piece.TimeCost > 0)
            {
                MoveActivePlayer(Math.Min(EndLocation, PlayerPosition[player] + piece.TimeCost));
            }
        }
Exemplo n.º 3
0
        private void MoveActivePlayer(int targetPosition)
        {
#if DEBUG
            if (targetPosition > EndLocation)
            {
                throw new ArgumentOutOfRangeException(nameof(targetPosition), nameof(targetPosition) + " (" + targetPosition + ") is past the EndLocation (" + EndLocation + ")");
            }
            if (targetPosition <= PlayerPosition[ActivePlayer])
            {
                throw new ArgumentOutOfRangeException(nameof(targetPosition), nameof(targetPosition) + " (" + targetPosition + ") is not past the current position of this player");
            }
#endif
            var startPosition = PlayerPosition[ActivePlayer];
            //Move us
            PlayerPosition[ActivePlayer] = targetPosition;


            //Check if we get buttons for passing a button marker
            PlayerButtonAmount[ActivePlayer] += PlayerButtonIncome[ActivePlayer] * (SimulationHelpers.ButtonIncomeAmountAfterPosition(startPosition) - SimulationHelpers.ButtonIncomeAmountAfterPosition(targetPosition));

            //Check if the player gets a leather patch
            if (LeatherPatchesIndex < LeatherPatches.Length && targetPosition >= LeatherPatches[LeatherPatchesIndex])
            {
                //Note: If the player cannot place the patch it is just discarded https://boardgamegeek.com/thread/1538861/cant-put-1x1-patch-what-happens

                if (Fidelity == SimulationFidelity.FullSimulation)
                {
                    //Only get the piece if their board isn't full
                    if (PlayerBoardUsedLocationsCount[ActivePlayer] < BoardState.Width * BoardState.Height)
                    {
                        PieceToPlace       = PieceDefinition.LeatherTile;
                        PieceToPlacePlayer = ActivePlayer;
                    }
                }
                else
                {
                    //Only get the points if their board isn't full
                    if (PlayerBoardUsedLocationsCount[ActivePlayer] < BoardState.Width * BoardState.Height)
                    {
                        PlayerBoardUsedLocationsCount[ActivePlayer]++;
                    }
                }

                LeatherPatchesIndex++;
            }

            //We moved in front of them, change the active player
            if (PlayerPosition[ActivePlayer] > PlayerPosition[NonActivePlayer])
            {
                ActivePlayer = NonActivePlayer;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Purchase the given piece for placement (B: Take and Place a Patch)
        /// </summary>
        /// <param name="pieceIndex">The index of the patch in the Pieces List</param>
        public void PerformPurchasePiece(int pieceIndex)
        {
#if DEBUG
            if (PieceToPlace != null)
            {
                throw new Exception("Cannot purchase a piece when there is one waiting to be placed");
            }
#endif

            //Check the piece is one of the next 3
            pieceIndex = pieceIndex % Pieces.Count;
#if DEBUG
            if (pieceIndex != NextPieceIndex % Pieces.Count && pieceIndex != (NextPieceIndex + 1) % Pieces.Count && pieceIndex != (NextPieceIndex + 2) % Pieces.Count)
            {
                throw new Exception("pieceIndex (" + pieceIndex + ") is not one of the next 3 pieces");
            }
#endif
            var piece = PieceDefinition.AllPieceDefinitions[Pieces[pieceIndex]];

            //Check the player can afford it
#if DEBUG
            if (PlayerButtonAmount[ActivePlayer] < piece.ButtonCost)
            {
                throw new Exception("Player is trying to purchase a piece they cannot afford");
            }
#endif

            //TODO(?) Check the player can place it

            //1. Choose a Patch
            Pieces.RemoveAt(pieceIndex);
            //2. Move the Neutral Token
            NextPieceIndex = pieceIndex % Pieces.Count;
            //3. Pay for the Patch
            PlayerButtonAmount[ActivePlayer] -= piece.ButtonCost;

            Logger.PlayerPurchasedPiece(ActivePlayer, piece);

            if (Fidelity == SimulationFidelity.NoPiecePlacing)
            {
                PerformPurchasePlaceSteps45(piece, ActivePlayer);
            }
            else
            {
                PieceToPlace       = piece;
                PieceToPlacePlayer = ActivePlayer;
            }
        }