Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #setup
- from selenium import webdriver
- driver = webdriver.Safari()
- driver.get("http://www.decisionproblem.com/paperclips/index2.html")
- #loop and bot logic
- is_playing = True
- i = 0
- def main_data():
- buttons["produce"].click()
- def strategy(demand, x=1000):
- if data["inventory"] < x:
- if data["demand"] <= demand[0]:
- buttons["lower"].click()
- print("Lowering the price to " + "$" + str(data["price"]))
- elif data["demand"] >= demand[-1]:
- buttons["more"].click()
- print("Raising the price to " + "$" + str(data["price"]))
- if data["funds"] > data["wire_price"] and i % 150 == 0:
- buttons["buy_wire"].click()
- print("Bought some wire at i: " + str(i))
- if data["autoclipper_cost"] < data["funds"] and i % 150 == 0 and data["wire"] > 500:
- buttons["autoclip"].click()
- print("Bought an autoclipper at i: " + str(i))
- else:
- if data["funds"] > data["wire_price"]:
- buttons["buy_wire"].click()
- print("(Inventory full) Bought some wire at i: " + str(i))
- if data["price"] > 0.04:
- print("(Inventory full) Lowering the price to " + "$" + str(data["price"]))
- buttons["lower"].click()
- #defining the demand range
- demand = [50, 55, 60]
- demand_2 = [40, 45, 50]
- while is_playing:
- # entering the buttons
- buttons = {
- "produce": driver.find_element_by_id("btnMakePaperclip"),
- "lower": driver.find_element_by_id("btnLowerPrice"),
- "more": driver.find_element_by_id("btnRaisePrice"),
- "buy_wire": driver.find_element_by_id("btnBuyWire"),
- "autoclip": driver.find_element_by_id("btnMakeClipper")
- }
- # entering other data
- data = {
- "funds": float(driver.find_element_by_id("funds").text.replace(",", "")),
- "inventory": float(driver.find_element_by_id("unsoldClips").text.replace(",", "")),
- "price": float(driver.find_element_by_id("margin").text.replace(",", "")),
- "demand": float(driver.find_element_by_id("demand").text.replace(",", "")),
- "wire": float(driver.find_element_by_id("wire").text.replace(",", "")),
- "wire_price": float(driver.find_element_by_id("wireCost").text.replace(",", "")),
- "autoclipper_cost": float(driver.find_element_by_id("clipperCost").text.replace(",", ""))
- }
- main_data()
- i += 1
- # checking if the script should apply the starting strategy
- if i < 1000:
- strategy(demand)
- elif i < 3000:
- strategy(demand_2, 3000)
- else:
- strategy(demand_2, 5000)
- driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement