king-of-the-hill game python
This is going to take me a while to finish and may never be fully done. Don't expect this to be posted anytime soon. However, this will be an ongoing project under development.
Who hasn't heard of Monopoly? If not, don't worry, as I will explain the rules! If you already know the rules, read on, for they may be different in this rendition.
The Rules of Monopoly
Monopoly is played on a board, with 36 different squares, that looks somewhat like this
For this version, we'll use the original British version, because I'm British and proud of it!
Squares are split into 3 categories:
- Property. These are the ones with a coloured bar at the top, such as
Old Kent Road or
Whitehall. They also include the 4 stations in the middle of each side, and the utilities (
Electric Company and
- Bonus Cards. These are the squares marked
Community Chest or
Chance. These allow for a player to either receive or lose money, depending on a random card choice.
- Special Squares. These are the 6 other squares in the board, the 4 corner squares and the taxes (boo!)
Let's look at these categories in a bit more detail.
Properties are grouped, depending on the colour of said property. Each property has a
rent value that contains the amount that a player must pay to the owner of the property, when they land on that property. If one player owns all of the properties in one colour, the rent for each is doubled.
Players can also buy properties, which is how they own them. Each property also has a price, which is then deducted from the buyer's cash and given to the Bank, in exchange for the property. Stations cost £100 each and all other properties available to buy have their cost written below their square.
Stations' rent increases the more stations that someone owns. In the following progression
- 1 Station: Rent = £25
- 2 Stations: Rent = £50
- 3 Stations: Rent = £100
- 4 Stations: Rent = £200
Utilities' rent depends on the dice roll. If a player owns 1 utility, multiply the roll by 4 and that is the rent. If the player owns both, multiply the roll by 10 to get the rent due.
Properties can be built on. That means that a player builds houses and hotels on them, in order to increase that properties rent. A player can build houses and hotels on a property if
- it has a coloured bar at the top
- the player owns all of the properties in the group
- they have enough money. Each house costs £50 and each hotel costs £100.
Each property can have a maximum of 4 houses. After that, the player must build a hotel. A property can only have 1 hotel on it. Houses and hotels drastically increase the rent of a property, for example £4 (no buildings) to £450 (one hotel).
The name of these are a bit of a misnomer. These are denoted on the board by
? symbols and chests on squares and can either give or take money from you. For this game, we will ignore
Get Out of Jail Free cards and the
Goto cards. The cards can result in a random integer between
1000 added to your score. If this results in bankruptcy (we'll see this later), so be it.
- Go. If you land on Go, you get given a £400 reward. If you simply go past it (Mayfair -> Old Kent Road), you get £200. It's also where the pieces begin.
- Jail. If you roll and land on this square, don't worry, as you don't go to jail. You are "Just Visiting"
- Free Parking. This is where the taxes go! If you have to pay taxes, either because of the Tax squares or because of a Bonus Card, that money goes to Free Parking. If a player lands on it, they get all the money there!1
- Go to Jail. This does what it says on the tin. You go straight to Jail. But this time, you're in Jail, not just visiting. You stay in Jail until you roll a double.1 After which, game continues as normal. You cannot collect rent while in Jail.
- Taxes. Super Tax and Income Tax are two squares which charge you £100 and £200, respectively. However, you can regain that money as it goes straight to Free Parking!
In Monopoly, if you run out of money, you are bankrupt. Here, you have two options. You can either mortgage your properties or, if you don't have any, you are out of the game! The last one with any money wins the game and the KoTH!
When you lose, all your properties go to the player who bankrupted you. If that's the Bank by virtue of Bonus Cards, then all your properties are available to be bought again.
You can mortgage properties in order to get more money if you're in a pinch. Unfortunately, this "deactivates" the property, meaning that you don't get any rent when people land on it. If you have enough money, you can unmortgage a property for 110% of its mortgage value. (£100 -> £110)
If you land on an unbought property and don't buy it, either because you don't have enough or you just don't want to, the property goes on auction. This means that all players can bid on the property. Bidding starts at £1, which means that a player can, theoretically, get the property for a much lower or higher price than its original price.
I am hoping to be able to include trading but this does depend on my ability as a coder. In an ideal world, I will be able to get it working but, unfortunately, this may not happen :(
1: I am aware that this changes depending on who you're playing with, but this is how we'll do it in this version.
Rules of the KoTH
I have written (still finishing) a
Player class in Python which contains all of the things that a Monopoly player can do. Your task is to rewrite 2 of the functions that can change your player's behaviour.
While thinking about how to make this KoTH, I listed out the complete process that gives you a chance to change what you do. Let's go over that process! This flowchart shows the process for each turn. Green items show the choices that you have to make.
This is the text version:
1. Roll dice and move
2. Is the property owned by the Bank?
1. Yes. Nothing happens.
2. No. Pay the due rent.
3. Choice of:
4. Choice of:
5. Move On
5. Repeat until bankrupt
1. Choice of:
1. Play the auction
2. Don't play the auction
2. Are you playing the auction?
1. Choice of:
1. Bid new max
2. Skip one round
3. Skip all rounds
4. 'All in'
2. Repeat until 1 player left bidding
2. No. Don't do anything.
1. Choose a player to trade with
2. Offer properties and/or money
3. Does the other player agree with the trade options?
1. No. They counter offer. Do you like their options?
1. No. Do you want to continue negotiating?
1. Yes. Go to point 2 above
2. No. The trade is over.
2. Yes. You trade the agreed upon items.
2. Yes. You trade the agreed upon items
But, for you coders out there, I'll explain using a bit of code.
Your submission should contain a single class that inherits from
Player. You may add in as many extra attributes as you want, but in order to be used, your code must refer to them. I'm not editing the controller just for your bot to work.
However, each class must look like this
def turn(self, square, roll):
(code that determines your actions per turn)
def auction_action(self, price, bidders):
(code that determines your auction actions)
def trade_actions(self, players, last_offer):
(code that determines your trading actions)
(any other functions you want)
turn function will return 3 numbers as a list e.g.
[1,2,3] which are the results of the choices above. The first item should be either
2 (Buy or Auction), the second should be one of
5 (of the
4. Choice of: options) and the third should be either
1 (play the auction) or
0 (don't play the auction) such as
[1,5,0] would buy the property, move on to the next player and not play the auction on this turn (doesn't matter as there wasn't an auction).
auction_action function will return either a number (your bid) or one of
a (all in),
s (skip this round) or
q (quit auction), which determines what you will do on that round of the bidding. This continues until either you quit the auction of you are the only one left.
trade_actions function will return a list every time it is called. The list consists of
[agree with previous offer (as a bool), properties to trade (as a list), cash to trade (as an int)]. When a trade has just begun, the first item in the list will be ignored and the
last_offer parameter will be ignored. The
last_offer parameter contains the second 2 items returned by the person you are negotiating with, so that you can decide whether you want to continue trading or not.
If you lose all your money, your program with be taken out of the active players and placed into the results table. The last one standing wins!