Пример #1
0
    def validateBid(self, move: BuyPrivateCompanyMove):
        # User needs to be one of the users who bid already.
        # User needs to not have passed on this company yet.
        valid_bidders = [pb.player for pb in move.private_company.player_bids]
        minimum_bid = max(
            [move.private_company.actual_cost] +
            [pb.bid_amount for pb in move.private_company.player_bids]) + 5

        return self.validate([
            err(move.player in valid_bidders,
                "You can't bid on this now, bitterboi."),
            err(
                move.player not in move.private_company.passed_by,
                "You can only keep bidding until you've passed once.",
            ),
            err(move.private_company.hasNoOwner(),
                "Someone already owns this cheatingboi. {0}",
                move.private_company.belongs_to),
            err(move.player.hasEnoughMoney(move.bid_amount),
                "You cannot afford poorboi. {} (You have: {})",
                move.bid_amount, move.player.cash),
            err(move.bid_amount >= minimum_bid,
                "Your bid is too small weenieboi. {} (Minimum Bid: {})",
                move.bid_amount, minimum_bid),
        ])
Пример #2
0
    def validateBid(self, move: BuyPrivateCompanyMove, kwargs: MutableGameState):
        minimum_bid = max([move.private_company.actual_cost] +
                          [pb.bid_amount for pb in move.private_company.player_bids]) + 5

        earlier_unsold_private_companies = [pc.name for pc in kwargs.private_companies
                       if pc.order < move.private_company_order and not pc.hasOwner()]

        return self.validate([
            err(move.private_company.hasNoOwner(),
                "Someone already owns this cheatingboi {} {}",
                move.private_company.order,
                move.private_company.belongs_to,
                ),

            err(len(earlier_unsold_private_companies) > 0,
                "You can't bid on this, it's currently for sale"
            ),

            err(move.player.hasEnoughMoney(move.bid_amount),
                "You cannot afford poorboi. {} (You have: {})",
                move.bid_amount, move.player.cash
            ),

            err(move.bid_amount >= minimum_bid,
                "Your bid is too small weenieboi. {} (Minimum Bid: {})",
                move.bid_amount, minimum_bid
            ),
        ])
Пример #3
0
 def validateBid(self, move: AuctionBidMove, state: MutableGameState):
     return self.validate([
         err(move.player.hasEnoughMoney(move.amount),
             "You cannot afford poorboi. {} (You have: {})", move.amount,
             move.player.cash),
         err(
             move.private_company == state.auctioned_private_company,
             "You are bidding on the wrong company numbnuts. {} vs. {}"
             " Probably something wrong with your UI system.",
             move.private_company.name,
             state.auctioned_private_company.name),
         err(move.player != state.auctioned_private_company.belongs_to,
             "You can't bid on your own company.",
             move.private_company.name,
             state.auctioned_private_company.name),
         err(
             move.amount >= int(state.auctioned_private_company.cost / 2),
             "You are paying too little.  Your bid must be 1/2 to 2 times the price of the company ({} to {}).",
             int(move.private_company.cost / 2),
             move.private_company.cost * 2),
         err(
             move.amount <= int(state.auctioned_private_company.cost * 2),
             "You are paying too much.  Your bid must be 1/2 to 2 times the price of the company ({} to {}).",
             int(move.private_company.cost / 2),
             move.private_company.cost * 2),
     ])
Пример #4
0
    def validateBuy(self, move: StockRoundMove,
                    kwargs: MutableGameState) -> bool:
        number_of_total_players = len(kwargs.players)
        player_certificates = move.player.getCertificateCount()
        cost_of_stock = move.public_company.checkPrice(move.source,
                                                       STOCK_CERTIFICATE,
                                                       move.ipo_price)

        my_sales = kwargs.sales[kwargs.stock_round_count].get(move.player, [])

        return self.validate([
            err(move.public_company not in my_sales,
                "You can't buy from a company you sold this round {} {}",
                move.public_company.id, move.public_company.name),
            err(
                player_certificates + 1 <=
                VALID_CERTIFICATE_COUNT[number_of_total_players],
                "You have too many certificates. There are {} players, and you are allowed a "
                "total of {} certificates.  You own {} certificates and would have too many if you bought more.",
                number_of_total_players,
                VALID_CERTIFICATE_COUNT[number_of_total_players],
                player_certificates),
            err(move.public_company.hasStock(move.source, STOCK_CERTIFICATE),
                "The company does not have enough stock in category {}",
                move.source),
            err(move.player.hasEnoughMoney(cost_of_stock),
                "You cannot afford poorboi. {} (You have: {})", cost_of_stock,
                move.player.cash),
        ])
Пример #5
0
    def validateBuy(self, move: BuyPrivateCompanyMove, kwargs: MutableGameState):
        """Ensures you can buy the Private company;
        Player order validations are out of scope"""
        private_companies: List[PrivateCompany] = kwargs.private_companies
        cost_of_private_company = move.private_company.actual_cost
        wrong_order = [pc.name for pc in private_companies
                       if pc.order < move.private_company_order and not pc.hasOwner()]

        return self.validate([
            err(
                move.private_company.hasNoOwner(),
                "Someone already owns this cheatingboi {} / {}",
                move.private_company.name, move.player.id
            ),

            err(
                len(wrong_order) == 0,
                "You can't buy this yet. {0} needs to be sold first.",
                ",".join(wrong_order)
            ),

            err(
                move.player.hasEnoughMoney(cost_of_private_company),
                "You cannot afford poorboi. {} (You have: {})",
                cost_of_private_company, move.player.cash
            ),

            err(
                not move.private_company.hasBids(),
                "You cannot buy something that has a bid on it."
            ),

        ])
Пример #6
0
 def validatePass(self, move: AuctionBidMove, state: MutableGameState):
     return self.validate([
         err(move.player != state.auctioned_private_company.belongs_to,
             "You can't pass (or bid) on your own company.",
             move.private_company.name,
             state.auctioned_private_company.name),
     ])
Пример #7
0
 def validatePass(self, move: BuyPrivateCompanyMove, kwargs: MutableGameState):
     actual_cost = move.private_company.actual_cost
     return self.validate([
         err(move.private_company.actual_cost > 0,
             "You must purchase the private company if its price has been reduced to zero. ({})",
             actual_cost),
     ])
Пример #8
0
 def validateReject(self, move: AuctionDecisionMove, state: MutableGameState):
     return self.validate([
         err(
             move.player == move.private_company.belongs_to,
             """You can't reject an auction if you do not own the company.""",
             move.accepted_player_id
         ),
     ])
Пример #9
0
    def validatePass(self, move: BuyPrivateCompanyMove):
        valid_bidders = [pb.player for pb in move.private_company.player_bids]
        is_valid_bidder = move.player in valid_bidders
        hasnt_passed = move.player not in move.private_company.passed_by
        other_bidder_remain = len(
            set(valid_bidders) - set(move.private_company.passed_by)) > 1

        return self.validate([
            err(
                is_valid_bidder,
                "You can't pass on this - heck you can't bid on this.  "
                "There probably is something wrong with your UI implementation that "
                "is letting you make a move."),
            err(hasnt_passed, "You already passed on this company."),
            err(
                other_bidder_remain,
                "You are the only bidder left; you can't pass.  You should have received the stock already."
            ),
        ])
Пример #10
0
    def validateFirstPurchase(self, move: StockRoundMove) -> bool:
        cost_of_stock = move.public_company.checkPrice(
            move.source, STOCK_PRESIDENT_CERTIFICATE, move.ipo_price)
        valid_ipo_prices = ",".join([str(p) for p in VALID_IPO_PRICES])

        return self.validate([
            err(move.ipo_price in VALID_IPO_PRICES,
                "Invalid IPO Price ({}).  Valid prices are {}.",
                move.ipo_price, valid_ipo_prices),
            err(
                move.source == StockPurchaseSource.IPO,
                "You need to purchase stock from the IPO as this is an initial purchase",
            ),
            err(
                move.player.hasEnoughMoney(cost_of_stock),
                "You cannot afford to be president poorboi. {} (You have: {})",
                cost_of_stock,
                move.player.cash,
            )
        ])
Пример #11
0
    def isValidPlayer(self, move: Move) -> bool:
        """The person who submitted the move must be the current player.

        Warning: The player object is only set in the move once the "Backfill" function is executed (to load info from state)
        To avoid that, we are only comparing the player ids, which it always has."""
        errors = err(move.player_id == self.current_player.id,
                     "Wrong player; {} is not {}", move.player_id,
                     self.current_player.id)
        if errors == None:
            return True
        self.errors_list = [errors]
        return False
Пример #12
0
 def validateAccept(self, move: AuctionDecisionMove, state: MutableGameState):
     """
     1. Are you accepting a bid from someone who actually made a bid?
     :param move:
     :param state:
     :return:
     """
     return self.validate([
         err(
             move.accepted_player_id in [player_id for player_id, amount in state.auction],
             """You are accepting a bid from a player who didn't make a bid. (ID: "{}")""",
             move.accepted_player_id
         ),
         err(
             move.player == move.private_company.belongs_to,
             """You can't accept an auction if you do not own the company.""",
         ),
         err(
             move.accepted_amount > 0,
             """You cannot accept invalid bids.""",
         ),
     ])
Пример #13
0
    def _validateSale(self, player: Player, company: PublicCompany,
                      amount: int, kwargs: MutableGameState):
        """You can't sell stocks you bought in previous rounds."""
        my_purchases = kwargs.purchases[kwargs.stock_round_count].get(
            player, [])

        my_stock = player.hasStock(company)
        potential_owners = company.potentialPresidents()

        validations = [
            err(company not in my_purchases,
                "You can't sell something you already bought: {} {}",
                company.id, company.short_name),
            err(my_stock >= amount,
                "You must have as much stock than you are trying to sell {}",
                amount),
            err(
                company.availableStock(StockPurchaseSource.BANK) + amount <=
                60,
                "You can't sell that much ({}); the bank can only have 50 shares max.",
                amount),
            err(
                len(company.potentialPresidents() - {player}) > 0
                or my_stock - amount >= 20,
                "There are no other potential presidents, so you can't sell your shares. {} / {} (original stock: {})",
                ",".join([p.id for p in company.potentialPresidents()]),
                company.name, str(company.owners.get(player))),
            err(
                amount % STOCK_CERTIFICATE == 0,
                "You can only sell in units of 10 stocks ({})".format(amount),
            ),
            err(kwargs.stock_round_count > 1,
                "You can only sell after the first stock round.")
        ]

        return self.validate(validations)