small newbie task to python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: small newbie task to python (/thread-19190.html) |
small newbie task to python - intoxicated_dk - Jun-17-2019 Hi, I am just getting through startups, and got a minor task, just a simple else,if, vba look a like. Task is You have 5 states which have 5 things it will increase or decrease
Columns are starting with sleepy, thirsty, hungry, whisky, gold Rules: sleepy, thirsty, hungry cannot go over 100 whisky cannot go over 10 nothing can be below 0 1000 loops, meaning each time you turn state, you use 1. Goal is to get as much goal as possible. My points so far is around 1150.. Anybody that can share some nice idea to what i miss? RE: small newbie task to python - Gribouillis - Jun-17-2019 intoxicated_dk Wrote:Anybody that can share some nice idea to what i miss?If you share the code, we may have some idea about what can be improved. RE: small newbie task to python - intoxicated_dk - Jun-17-2019 Ah, yes, i can. And of course it was gold, i reached 1158, and i am in doubt if i can go higher, that's why your ideas :) import numpy as np Resources = np.array([0, 0, 0, 0, 0]) MiningEffect = np.array([5, 5, 5, 0, 5]) EatingEffect = np.array([5, -5, -20, 0, -2]) DrinkingEffect = np.array([5, -10, 1, -1, 0]) ShoppingEffect = np.array([5, 1, 1, 1, -1]) SleepingEffect = np.array([-10, 1, 1, 0, 0]) State = "M" max_turns = 1000 turn = 1 while turn <= max_turns: # Apply Effect print("Turn : " + str(turn)) print("Activity : " + State) if State == "M": Resources = Resources + MiningEffect if State == "E": Resources = Resources + EatingEffect if State == "D": Resources = Resources + DrinkingEffect if State == "SH": Resources = Resources + ShoppingEffect if State == "SL": Resources = Resources + SleepingEffect if Resources[0] > 100 or Resources[1] > 100 or Resources[2] > 100 or Resources[3] < 0: print("DIE!!") break # Optimize next state State = "M" # Default if Resources[1] > 94: State = "D" if Resources[2] > 94 and turn < 994: State = "E" if Resources[0] > 94: State = "SL" if Resources[3] < 1 and Resources[2] > 85 and turn < 998: State = "SH" print(" = Ressources" + str(Resources)) print("") turn += 1 |