# File vw2b.py # # Author: G.Doeben-Henisch # First date: July 21, 2019 # Last date: July 23, 2019 ''' ACTOR STORY 1. There is a human executive actor as a user who uses a program as an assisting actor by an interface with inputs and outputs. 2. The program tries to construct a 2D-virtual world in the format of a grid. The program needs the size of the grid as (m,n) = (number of columns, number of rows), which is here assumed by default as equal m=n. After the input the program will show the grid on screen. 3. Then the program will ask for the percentage of obstacles 'O' and energy objects (= food) 'F' in the world. Randomly the grid will be filled according to these values. 4. Then a finite number of virtual actors will be randomly inserted too. In the first version only one. POSSIBLE EXTENSIONS In upcoming versions the following options should be added: 1. Allow multiple objects with free selectable strings for encoding. 2. Allow multiple actors. 3. Allow storage of a world specification with reloading in the beginning instead of editing. 4. Transfer the whole world specification into an object specification. This allows the usage of different worlds in one program. ''' ############################ # IMPORTS import random as rnd import gridHelper as grh ############################ # SUPPORTING FUNCTION # # Now in a dedicated module gridHelper.py in folder 'code' # Complete path: C:\Users\gerd_2\code # This path has to be included for the python path search mechanism # # Show actual path values # # >>> import sys #>>> sys.path # ... # Extend the python path by appending the modul path: # # In my case the path is as follows: # #>>> sys.path.append('C:\\Users\\gerd_2\\code') ########################## # Main Programm ############### # Start main loop # # The loop will work as long as the value of the variable 'loop' is different to 'N' # # SOME GLOBAL DICTIONARY # objL={'F':[0,1000, 20], 'A':[0,1000,5,100]} ''' A food object 'F' has an initial value of '1000' and can grow if below 1000 by 20 every cycle An actor object 'A' has an ID, an initial energy level of 1000, loses every cycle 5 energy units, and can gain 100 energy units by eating ''' loop='Y' while loop!='N': ################### # The user will be asked for some parameters needed for the editing of a virtual 2-dimensional world # Number of columns (m) and rows (n); by default equal. m=int(input('Number of columns (= equal to rows!) of 2D-grid ?')) n=m mx=grh.nmlist(n) # Generate a first empty matrix n*m # Percentage % of obstacles in the 2D-world?\n) obstacles=int(input('Percentage (as integer) of obstacles in the 2D-grid?')) no=grh.numberObj(obstacles,n) mx=grh.placeObj(no,n,mx,'O') # Percentage % of energy objects in the 2D-world?\n) energyObj=int(input('Percentage (as integer) of Energy Objects (= Food) in the 2D-grid ?')) no=grh.numberObj(energyObj,n) mx=grh.placeObj(no,n,mx,'F') # Percentage % of actor objects in the 2D-world?\n) actorObj=int(input('Percentage (as integer) of Actor Objects in the 2D-grid ?')) no=grh.numberObj(actorObj,n) if no<1: no=1 mx=grh.placeObj(no,n,mx,'A') # List of actual food objects in the grid: c='F' name='food' olF=grh.makeobjL(c,objL,mx,n) print('\n Objects as ',name,'\n') for i in range(len(olF)): print(olF[i]) # List of actual actor objects in the grid: c='A' name='actor' olA=grh.makeobjL(c,objL,mx,n) print('\n Objects as ',name,'\n') for i in range(len(olA)): print(olA[i]) # Clarify how to continue loop=input("\n STOP = 'N', CONTINUE != 'N' \n")