-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib_Passenger.py
111 lines (78 loc) · 2.76 KB
/
lib_Passenger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'''
InterstellarTrader: Automating interstellar economics for the Traveller Universe.
Copyright (C) 2016 Christian Blouin ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
## Imports #######################################################################
##
# Internal imports
import lib_RandomTable as libRT
# External imports
from random import choice, randint
## Functions #####################################################################
##
def GetOnePassenger():
'''
'''
# output
out ={'kind':None}
# Table
while not out['kind']:
# Dice
dice = libRT.d66()
# Table
x = libRT.Randomd66('RandomPassenger', dice)
# Identity
out['kind'] = x[0]
# Secret
x = libRT.Randomd66('PassengerSecret', libRT.d66())
if x[0] != '-':
out['secret'] = x[0]
if len(x) > 1:
out['secret'] += '(%s)'%(choice( x[1].split(',') ))
# Gender
out['gender'] = libRT.Random3d6('gender', libRT.Nd6())[0]
# Returns
return out
def GeneratePassengers(BTN):
'''
'''
# Total number
n_tot = libRT.Nd6(1,-1) * BTN
n = {'high':0, 'medium':0, 'low':0}
n['high'] = n_tot
# Low passage
n['low'] = randint( 0 , n['high'])
n['high'] -= n['low']
n['low'] = randint(0,n['low'])
# Medium passage
if n_tot:
n['medium'] = randint( 0 , n['high'])
n_tot -= n['medium']
n['medium'] = randint(0, n['medium'])
# High
n['high'] = randint(0, n['high'])
# output
out = {'high':[], 'medium':[], 'low':[]}
for k in out:
for i in range(n[k]):
out[k].append( GetOnePassenger() )
return out
def PrettyPrint( x ):
out = 'Passage\tGender\tType\tSecret\n'
for k in ['high', 'medium', 'low']:
for p in x[k]:
out += '%s\t%s\t%s\t%s\n'%(k, p.get('gender','-'), p.get('kind','-'), p.get('secret','-') )
return out
if __name__ == '__main__':
x = GeneratePassengers(10)
print PrettyPrint(x)