Discuss New to code in the Python Programming forum on Dev Shed. New to code Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Posts: 3,458
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
You'll probably get good response if you're polite, use the best English grammar you're capable, and have specific programming questions that can be answered without familiarity with your favorite game.
If you expect your audience to understand "i mod servers and more." then perhaps devshed forums shouldn't be your first choice for help.
Likewise, if you consider "Answer please!" polite then you should look elsewhere before your transfer to the blacklist occurs.
__________________
[code]Code tags[/code] are essential for python code!
Posts: 7
Time spent in forums: 1 h 21 m 49 sec
Reputation Power: 0
Excuse me, im not so great on english but i gonna make a mod it is called INFECTION mod, cs have it and i think some other games have it. This is how the mod works. First 2 random person be in red team and the rest in blue team. If a red team player kill one in blue the blue team player that be killed forces into red team. If i am red and die i will wait to the other red die. if the red dont kill it restart the round. Any ideas how i can make this with b3? Sorry for my english
Posts: 3,458
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
You needn't be a native English speaker. Here's a python code that implements my understanding of your description:
Code:
# The game of infection
# I do not know what is "b3"
# example game command line:
# python -c 'import p;p.main(4)'
import random, pdb
class avatar:
def __init__(self,name,team,offensive_skill,defense_rating):
if not ((0 < offensive_skill < 1) and (0 < defense_rating < 1)):
raise ValueError('offensive_skill and defense_rating must be between 0 and 1')
self.name = name
self.team = team
self.offense = offensive_skill
self.defense = defense_rating
self.state = 'live'
def __str__(self):
return ' '.join(self.team,self.name,self.state)
def __gt__(self,other):
try:
return random.random() < self.offense*(1-other.defense)
except:
raise ValueError('undefined operation with '+self.__class__.__name__)
def create(name,team):
return avatar(name,
team,
offensive_skill = 0.2 + random.random()*0.2, # baseball like statistics
defense_rating = 0.7 + random.random()*0.2,
)
def shoot(red,blue):
# shooting is not simultaneous.
# a dead player can be shot.
# a dead player cannot shoot.
players = red+blue
random.shuffle(players)
#pdb.set_trace()
change = 0
for shooter in players:
if 'live' != shooter.state:
continue
i = 'red' == shooter.team
receivers = (red,blue,)[i]
if not(len(receivers)):
continue
j = random.randrange(len(receivers))
receiver = receivers[j]
if receiver < shooter:
change = 1
if i:
red.append(receiver)
del blue[j]
else:
red[i].state = 'dead'
return change
def simulation(players):
red = [create(str(i),'red') for i in range(max(0,min(2,players)))]
blue = [create(str(i+2),'blue') for i in range(max(0,players-2))]
print('%d red, %d blue'%(sum('live' == r.state for r in red),len(blue)))
while red and blue:
if shoot(red,blue):
print('%d red, %d blue'%(sum('live' == r.state for r in red),len(blue)))
red = [r for r in red if 'live' == r.state]
if red:
print('The zombie infection overwhelmed the living')
if blue:
print('blue wins---zombie threat eliminated')
infection = main = simulation