1

so like i've posted it above. i'm trying to make the agent jump with a tiny probability , any suggestions ? thanks. i thought about importing the turtle library and using the methods featured in it to build a function based on the turtle.goto(x,y) , but was unsuccessful.

 import Bug
 import random

 nBugs = eval(input("How many bugs? "))
 bugList = []
 worldXSize = eval(input("X Size of the world? "))
 worldYSize = eval(input("Y Size of the world? "))
 length = eval(input("Length of the simulation in cycles? "))


 for i in range(nBugs):
     aBug = Bug.Bug(i, random.randint(0, worldXSize - 1),
               random.randint(0, worldYSize - 1),
               worldXSize, worldYSize)
     bugList.append(aBug)

 for t in range(length):

     random.shuffle(bugList)

     for aBug in bugList:
         aBug.randomWalk()
         aBug.reportPosition()

and here's the Bug.py Code ( that one i forgot to add it previously , sorry about that)

import random


class Bug:
    def __init__(self, number, xPos, yPos, placement, worldXSize=80, worldYSize=80):
    # the environment
        self.number = number
        self.worldXSize = worldXSize
        self.worldYSize = worldYSize
    # the bug
        self.xPos = xPos
        self.yPos = yPos
        print("Bug number ", self.number,
          " has been created at ", self.xPos, ", ", self.yPos)

    # the action
    def randomWalk(self):
        self.xPos += randomMove()
        self.yPos += randomMove()
        self.xPos = (self.xPos + self.worldXSize) % self.worldXSize
        self.yPos = (self.yPos + self.worldYSize) % self.worldYSize
    # report

    def reportPosition(self):
        print("Bug number ", self.number, " moved to X = ",
          self.xPos, " Y = ", self.yPos)

    def placement(self):
         self.xPos = self.xPos % self.worldXSize + randomMove()

def randomMove():
    return random.randint(-1, 1)
Dimi
  • 531
  • 3
  • 8
  • 20
  • what have you tried so far ? what do you exactly want to achieve ? what are your errors ? – LoneWanderer Nov 12 '18 at 00:50
  • so what i'm trying to do , is to make the bug move from one point to an other with a probability – Dimi Nov 12 '18 at 10:39
  • From what you've said so far, it sounds like you just need to change the return value of `randomMove`. For example, `return 0 if (random.random() < 0.9) else random.randint(-1, 1)`. – Alan Nov 26 '18 at 15:44
  • Thanks for the insight – Dimi Nov 27 '18 at 16:06

0 Answers0