Random Movement

Trying to make my batle bot move randomly

Page 1 of 1

2 Replies - 2060 Views - Last Post: 18 November 2009 - 07:51 AM Rate Topic: -----

#1 cjbeliever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-November 09

Random Movement

Post icon  Posted 08 November 2009 - 07:07 PM

I am trying to add to my battle bot program. I would like to make the target move randomly. Could you let me know what command i use to do this. just looking for the command nothing else. Below is what i have so far.

def main():
	ammo = 5
	fuel = 200
	targ = 10
	fobs = 100
	bobs = 100
	choice = 0
	while choice !=5:
				if choice == 4:
						ammo,fuel,targ,fobs,bobs=restart(ammo,fuel,targ,fobs,bobs)
						choice = 0
				else:
						os.system("cls")
						print 'Ammo:', ammo,'/5'
						print 'Energy:', fuel,'/200'
						print 'The', status(targ)
						print 'Menu Selections:'
						print '1 - Launch Volunteer'
						print '2 - Push Catapult Forward'
						print '3 - Drag Catapult Backward'
						print '4 - Restart'
						print '5 - Exit'
						choice = input('Enter your selection:')
						if choice == 1:
							ammo, targ, choice=fireWeapon(ammo,targ,fobs, choice)
						elif choice == 2:
							fobs, bobs, fuel=moveFor(fobs,bobs,fuel)
						elif choice == 3:
							fobs, bobs, fuel=moveBack(fobs,bobs,fuel)
						elif choice == 4:
								ammo,fuel,targ,fobs,bobs=restart(ammo,fuel,targ,fobs,bobs)
						elif choice == 5:
								os.system("cls")
								print 'Bye Bye!'
								time.sleep(5)
def fireWeapon(ammo,targ,fobs, choice):
	import os
	os.system("cls")
	if ammo > 0:
		os.system("cls")
		dist = input('How far do you want to fire the volunteer: ')
		adist = fobs + 20
		tohit = adist - dist
		if tohit == 0:
			targ = targ - 10
			print 'You shattered the window!! Good Job!!'
		elif tohit == 1 or tohit == 2 or tohit == -1 or tohit == -2:
			targ = targ - 9
			print 'You caused major damage to the window and the', status(targ)
		elif tohit == 3 or tohit == 4 or tohit == -3 or tohit == -4:
			targ = targ - 8
			print 'You caused significant damage to the window and the', status(targ)
		elif tohit == 5 or tohit == 6 or tohit == -5 or tohit == -6:
			targ = targ - 7
			print 'You caused significant damage to the window and the', status(targ)
		elif tohit == 7 or tohit == 8 or tohit == -7 or tohit == -8:
			targ = targ - 6
			print 'You cause significant damage to the window and the', status(targ)
		elif tohit == 9 or tohit == 10 or tohit == -9 or tohit == -10:
			targ = targ - 5
			print 'You cause medium damage to the window and the', status(targ)
		elif tohit == 11 or tohit == 12 or tohit == -11 or tohit == -12:
			targ = targ - 4
			print 'You cause medium damage to the window and the', status(targ)
		elif tohit == 13 or tohit == 14 or tohit == -13 or tohit == -14:
			targ = targ - 3
			print 'You cause minor damage to the window and the', status(targ)
		elif tohit == 15 or tohit == 16 or tohit == 17 or tohit == -15 or tohit == -16 or tohit == -17:
			targ = targ - 2
			print 'You cause minor damage to the window and the', status(targ)
		elif tohit == 18 or tohit == 19 or tohit == 20 or tohit == -18 or tohit == -19 or tohit == -20:
			targ = targ - 1
			print 'You cause minor damage to the window and the', status(targ)
		else:
			print 'You missed the window!!'
	else:
		print 'You dont have enough ammo!!'
	ammo = ammo - 1
	time.sleep(1)
	targ,choice=checkwin(targ,choice)
	time.sleep(1)
	return (ammo,targ,choice)
def status(targ):
		if targ == 10:
				print 'window is in perfect shape.'
		elif targ == 9 or targ == 8:
				print 'window has minor cracks'
		elif targ == 7 or targ == 6:
				print 'window has some cracks starting to appear'
		elif targ == 5 or targ == 4:
				print 'window has major cracks.'
		elif targ == 3 or targ == 2 or targ == 1:
				print 'window is about to shatter!'
		elif targ <= 0:
				print 'window is shattered!'
		else:
				print 'Fatal Error has occured!!'
		return('-------------')
def moveFor(fobs,bobs,fuel):
		os.system("cls")
		mv=input('How far do you wish do push the catapult forward?')
		if mv<=fuel:
				if mv>fobs:
						print 'Your path is blocked by a barrier, you did not move at all.'
				else:
						print 'You push the catapult forward',mv,'spaces.'
						fuel = fuel - mv
						fobs = fobs - mv
						bobs = bobs + mv
		else:
				print 'You do not have enough energy to move that far!'
		time.sleep(2)
		return (fobs,bobs,fuel)
def moveBack(fobs,bobs,fuel):
		os.system("cls")
		mv=input('How far do you wish drag the catapult backwards?')
		if mv<=fuel:
				if mv>bobs:
						print 'Your path is blocked by a barrier, you did not move at all.'
				else:
						print 'You drag the catapult back',mv,'spaces.'
						fuel = fuel - mv
						bobs = bobs - mv
						fobs = fobs + mv
		else:
				print 'You do not have enough energy to move that far!'
		time.sleep(2)
		return (fobs,bobs,fuel)
def restart(ammo,fuel,targ,fobs,bobs):
		time.sleep(1)
		os.system("cls")
		print 'Reloading.'
		time.sleep(1)
		os.system("cls")
		print 'Reloading..'
		time.sleep(1)
		os.system("cls")
		print 'Reloading...'
		time.sleep(1)
		os.system("cls")
		print 'Reloading... Done!'
		time.sleep(1)
		ammo=5
		fuel = 200
		targ = 10
		fobs = 100
		bobs = 100
		return (ammo,fuel,targ,fobs,bobs)
def checkwin(targ,choice):
		if targ <= 0:
				for counter in range(3):
						os.system("cls")
						print "/\-/\-/\-/\-/"
						print "--*YOU WON*--"
						print "/\-/\-/\-/\-/"
						time.sleep(1)
						os.system("cls")
						print "\-/\-/\-/\-//"
						print "-*-YOU WON-*-"
						print "\-/\-/\-/\-//"
						time.sleep(1)
						os.system("cls")
						print "-/\-/\-/\-/\-"
						print "*--YOU WON--*"
						print "-/\-/\-/\-/\-"
						time.sleep(1)
				print
				ach=raw_input('Would you like to play again? (y = yes and n = no)')
				if ach == "n":
						choice = 5
				else:
						choice = 4
		return(targ,choice)
import time
import os
main()




let me know what you think.

Is This A Good Question/Topic? 0
  • +

Replies To: Random Movement

#2 Project 2501  Icon User is offline

  • import awesome as Project_2501
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,565
  • Joined: 14-December 08

Re: Random Movement

Posted 08 November 2009 - 08:17 PM

You could try using the random module. Specifically the randint command.

Here's the full documentation on the random module:
http://docs.python.o...ary/random.html

Also, I noticed that you imported the os module a few times throughout your script -- Correct me if I'm wrong, but you only need to do that once, at the top of your script.

This post has been edited by Project 2501: 08 November 2009 - 08:20 PM

Was This Post Helpful? 0
  • +
  • -

#3 ITTrobL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-November 09

Re: Random Movement

Posted 18 November 2009 - 07:51 AM

View Postcjbeliever, on 8 Nov, 2009 - 06:07 PM, said:

I am trying to add to my battle bot program. I would like to make the target move randomly. Could you let me know what command i use to do this. just looking for the command nothing else. Below is what i have so far.

def main():
	ammo = 5
	fuel = 200
	targ = 10
	fobs = 100
	bobs = 100
	choice = 0
	while choice !=5:
				if choice == 4:
						ammo,fuel,targ,fobs,bobs=restart(ammo,fuel,targ,fobs,bobs)
						choice = 0
				else:
						os.system("cls")
						print 'Ammo:', ammo,'/5'
						print 'Energy:', fuel,'/200'
						print 'The', status(targ)
						print 'Menu Selections:'
						print '1 - Launch Volunteer'
						print '2 - Push Catapult Forward'
						print '3 - Drag Catapult Backward'
						print '4 - Restart'
						print '5 - Exit'
						choice = input('Enter your selection:')
						if choice == 1:
							ammo, targ, choice=fireWeapon(ammo,targ,fobs, choice)
						elif choice == 2:
							fobs, bobs, fuel=moveFor(fobs,bobs,fuel)
						elif choice == 3:
							fobs, bobs, fuel=moveBack(fobs,bobs,fuel)
						elif choice == 4:
								ammo,fuel,targ,fobs,bobs=restart(ammo,fuel,targ,fobs,bobs)
						elif choice == 5:
								os.system("cls")
								print 'Bye Bye!'
								time.sleep(5)
def fireWeapon(ammo,targ,fobs, choice):
	import os
	os.system("cls")
	if ammo > 0:
		os.system("cls")
		dist = input('How far do you want to fire the volunteer: ')
		adist = fobs + 20
		tohit = adist - dist
		if tohit == 0:
			targ = targ - 10
			print 'You shattered the window!! Good Job!!'
		elif tohit == 1 or tohit == 2 or tohit == -1 or tohit == -2:
			targ = targ - 9
			print 'You caused major damage to the window and the', status(targ)
		elif tohit == 3 or tohit == 4 or tohit == -3 or tohit == -4:
			targ = targ - 8
			print 'You caused significant damage to the window and the', status(targ)
		elif tohit == 5 or tohit == 6 or tohit == -5 or tohit == -6:
			targ = targ - 7
			print 'You caused significant damage to the window and the', status(targ)
		elif tohit == 7 or tohit == 8 or tohit == -7 or tohit == -8:
			targ = targ - 6
			print 'You cause significant damage to the window and the', status(targ)
		elif tohit == 9 or tohit == 10 or tohit == -9 or tohit == -10:
			targ = targ - 5
			print 'You cause medium damage to the window and the', status(targ)
		elif tohit == 11 or tohit == 12 or tohit == -11 or tohit == -12:
			targ = targ - 4
			print 'You cause medium damage to the window and the', status(targ)
		elif tohit == 13 or tohit == 14 or tohit == -13 or tohit == -14:
			targ = targ - 3
			print 'You cause minor damage to the window and the', status(targ)
		elif tohit == 15 or tohit == 16 or tohit == 17 or tohit == -15 or tohit == -16 or tohit == -17:
			targ = targ - 2
			print 'You cause minor damage to the window and the', status(targ)
		elif tohit == 18 or tohit == 19 or tohit == 20 or tohit == -18 or tohit == -19 or tohit == -20:
			targ = targ - 1
			print 'You cause minor damage to the window and the', status(targ)
		else:
			print 'You missed the window!!'
	else:
		print 'You dont have enough ammo!!'
	ammo = ammo - 1
	time.sleep(1)
	targ,choice=checkwin(targ,choice)
	time.sleep(1)
	return (ammo,targ,choice)
def status(targ):
		if targ == 10:
				print 'window is in perfect shape.'
		elif targ == 9 or targ == 8:
				print 'window has minor cracks'
		elif targ == 7 or targ == 6:
				print 'window has some cracks starting to appear'
		elif targ == 5 or targ == 4:
				print 'window has major cracks.'
		elif targ == 3 or targ == 2 or targ == 1:
				print 'window is about to shatter!'
		elif targ <= 0:
				print 'window is shattered!'
		else:
				print 'Fatal Error has occured!!'
		return('-------------')
def moveFor(fobs,bobs,fuel):
		os.system("cls")
		mv=input('How far do you wish do push the catapult forward?')
		if mv<=fuel:
				if mv>fobs:
						print 'Your path is blocked by a barrier, you did not move at all.'
				else:
						print 'You push the catapult forward',mv,'spaces.'
						fuel = fuel - mv
						fobs = fobs - mv
						bobs = bobs + mv
		else:
				print 'You do not have enough energy to move that far!'
		time.sleep(2)
		return (fobs,bobs,fuel)
def moveBack(fobs,bobs,fuel):
		os.system("cls")
		mv=input('How far do you wish drag the catapult backwards?')
		if mv<=fuel:
				if mv>bobs:
						print 'Your path is blocked by a barrier, you did not move at all.'
				else:
						print 'You drag the catapult back',mv,'spaces.'
						fuel = fuel - mv
						bobs = bobs - mv
						fobs = fobs + mv
		else:
				print 'You do not have enough energy to move that far!'
		time.sleep(2)
		return (fobs,bobs,fuel)
def restart(ammo,fuel,targ,fobs,bobs):
		time.sleep(1)
		os.system("cls")
		print 'Reloading.'
		time.sleep(1)
		os.system("cls")
		print 'Reloading..'
		time.sleep(1)
		os.system("cls")
		print 'Reloading...'
		time.sleep(1)
		os.system("cls")
		print 'Reloading... Done!'
		time.sleep(1)
		ammo=5
		fuel = 200
		targ = 10
		fobs = 100
		bobs = 100
		return (ammo,fuel,targ,fobs,bobs)
def checkwin(targ,choice):
		if targ <= 0:
				for counter in range(3):
						os.system("cls")
						print "/\-/\-/\-/\-/"
						print "--*YOU WON*--"
						print "/\-/\-/\-/\-/"
						time.sleep(1)
						os.system("cls")
						print "\-/\-/\-/\-//"
						print "-*-YOU WON-*-"
						print "\-/\-/\-/\-//"
						time.sleep(1)
						os.system("cls")
						print "-/\-/\-/\-/\-"
						print "*--YOU WON--*"
						print "-/\-/\-/\-/\-"
						time.sleep(1)
				print
				ach=raw_input('Would you like to play again? (y = yes and n = no)')
				if ach == "n":
						choice = 5
				else:
						choice = 4
		return(targ,choice)
import time
import os
main()




let me know what you think.









I Like this Programm. It's fun
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1