Python Forum
small newbie task to python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
small newbie task to python
#1
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
  • mining 5 5 5 0 5
  • eating 5 -5 -20 0 -2
  • shopping 5 1 1 1 -1
  • drinking 5 -10 1 -1 0
  • sleeping -10 1 1 0 0

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?
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  simple task in python Rapito 4 2,172 Nov-22-2021, 10:09 PM
Last Post: jefsummers
  Fun Task: Python 3.7.2 CozyDarkness 1 2,032 May-10-2019, 07:12 AM
Last Post: buran
  file python task, need help ! rayabv 7 3,480 Apr-15-2019, 10:07 PM
Last Post: Yoriz
  Newbie to CS and Python, 2 questions johneven 2 2,221 Feb-01-2019, 03:00 AM
Last Post: johneven
  School python program task help TommyLee 3 4,003 Apr-17-2018, 04:44 AM
Last Post: tannishpage

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020