def ai(): #player 1, color red, must have function ai(board) one = mediumThreat() red = "mediumThreat" #player 2, color blue, must have function ai(board) two = human() blue = "human" #default board b = board(6, 7) #variables that change throughout game player = one color = b.red while not b.gameOver: b.updateBoard(player.ai(b, color), color) b.checkGame() b.printBoard() update = changePlayer(player, one, two, b) player = update[0] color = update[1] b.printBoard() print winner(b.winner, red, blue, b) + " WINS!!"
def addHumans(self): """Add humans to the grid, only one human can be on each field""" # Get the numbers of humans in the initial state popHuman = int(self.config["pop-human"]) # Generate a list with randomly chosen infected humans based on # init-distr-human config value infected = (np.random.rand(popHuman) < self.config["init-distr-human"]).astype(int) medicine = (np.random.rand(popHuman) < self.config["good-medicine"]).astype(int) for i in xrange(0, popHuman - 1): found = False # Make sure that every grid place has only one human (x, y) = self.findHomeHuman() self.grid[x][y].moveIn(h.human(x, y, infected[i], self.motherStats, self.config, medicine=medicine[i]))
def cycleOfLife(self, x, y): """ Deaths of humans by sickness and keeping the human population stable by generating new humans if needed """ human = self.grid[x][y].human # return if no (infected) human, nothing to do here if human == None or human.status != 1: return True # Check what happens to the human, if false is returns the human died elif human.checkLife() == False: # Human died, remove from grid self.grid[x][y].moveOut() (freeX, freeY) = self.findHomeHuman() # Check if this person have access to good medicine for malaria if random.random() < self.config["good-medicine"]: medicine = True else: medicine = False self.grid[x][y].moveIn(h.human(x, y, 0, self.motherStats, self.config, medicine))
import numpy as np import data import densities # INPUTS ARE 95 MEASUREMENTS, DENSITIES, AND ORIENTATION ANGLES # read input file of 95 measurements # create solid objects # create segment objects # create human object # plot human, no angles # read in angles file # plot human, with joint angles # plot human conforming to a bicycle # SECOND ITERATION: MOVE FROM FILE INPUTS (FOR ANGLES ONLY) TO QT GUI externalangles = np.zeros( 3 ) externalangles[0] = 0 jointangles = np.zeros( 18 ) print "Creating human object." H = hum.human(externalangles) H.draw()
def start_ui(): print "Starting YEADON user interface." measPreload = { 'Ls5L' : 0.545, 'Lb2p' : 0.278, 'La5p' : 0.24, 'Ls4L' : 0.493, 'La5w' : 0.0975, 'Ls4w' : 0.343, 'La5L' : 0.049, 'Lb2L' : 0.2995, 'Ls4d' : 0.215, 'Lj2p' : 0.581, 'Lb5p' : 0.24, 'Lb5w' : 0.0975, 'Lk8p' : 0.245, 'Lk8w' : 0.1015, 'Lj5L' : 0.878, 'La6w' : 0.0975, 'Lk1L' : 0.062, 'La6p' : 0.2025, 'Lk1p' : 0.617, 'La6L' : 0.0805, 'Ls5p' : 0.375, 'Lj5p' : 0.2475, 'Lk8L' : 0.1535, 'Lb5L' : 0.049, 'La3p' : 0.283, 'Lj9w' : 0.0965, 'La4w' : 0.055, 'Ls6L' : 0.152, 'Lb0p' : 0.337, 'Lj8w' : 0.1015, 'Lk2p' : 0.581, 'Ls6p' : 0.53, 'Lj9L' : 0.218, 'La3L' : 0.35, 'Lj8p' : 0.245, 'Lj3L' : 0.449, 'La4p' : 0.1685, 'Lk3L' : 0.449, 'Lb3p' : 0.283, 'Ls7L' : 0.208, 'Ls7p' : 0.6, 'Lb3L' : 0.35, 'Lk3p' : 0.3915, 'La4L' : 0.564, 'Lj8L' : 0.1535, 'Lj3p' : 0.3915, 'Lk4L' : 0.559, 'La1p' : 0.2915, 'Lb6p' : 0.2025, 'Lj6L' : 0.05, 'Lb6w' : 0.0975, 'Lj6p' : 0.345, 'Lb6L' : 0.0805, 'Ls0p' : 0.97, 'Ls0w' : 0.347, 'Lj6d' : 0.122, 'Ls8L' : 0.308, 'Lk5L' : 0.878, 'La2p' : 0.278, 'Lj9p' : 0.215, 'Ls1L' : 0.176, 'Lj1L' : 0.062, 'Lb1p' : 0.2915, 'Lj1p' : 0.617, 'Ls1p' : 0.865, 'Ls1w' : 0.317, 'Lk4p' : 0.34, 'Lk5p' : 0.2475, 'La2L' : 0.2995, 'Lb4w' : 0.055, 'Lb4p' : 0.1685, 'Lk9p' : 0.215, 'Lk9w' : 0.0965, 'Ls2p' : 0.845, 'Lj4L' : 0.559, 'Ls2w' : 0.285, 'Lk6L' : 0.05, 'La7w' : 0.047, 'La7p' : 0.1205, 'La7L' : 0.1545, 'Lk6p' : 0.345, 'Ls2L' : 0.277, 'Lj4p' : 0.34, 'Lk6d' : 0.122, 'Lk9L' : 0.218, 'Lb4L' : 0.564, 'La0p' : 0.337, 'Ls3w' : 0.296, 'Ls3p' : 0.905, 'Lb7p' : 0.1205, 'Lb7w' : 0.047, 'Lj7p' : 0.252, 'Lb7L' : 0.1545, 'Ls3L' : 0.388, 'Lk7p' : 0.252 } # initialize the joint angle data # user supplies names/paths of input text files print "PROVIDE DATA INPUTS: measurements and configuration (joint angles)." print "MEASUREMENTS: can be provided as a 95-field dict (units must be " \ "meters), or a .TXT file" temp = raw_input("Type the name of the dict variable "\ "or the .TXT filename (to use preloaded measurements," \ " just hit enter): ") if temp == '': meas = measPreload else: meas = temp print "CONFIGURATION (joint angles): can be provided as a 21-field dict,"\ " or a .TXT file" CFG = raw_input("Type the name of the dict variable "\ "or the .TXT filename (for all joint angles as zero," \ " just hit enter): ") # create the human object. only one is needed for this commandline program print "Creating human object." if CFG == '': H = hum.human(meas) else: H = hum.human(meas,CFG) done = 0 # loop end flag while done != 1: print "\nYEADON MAIN MENU" print "----------------" print " j: print/modify joint angles\n\n",\ " a: save current joint angles to file\n",\ " p: load joint angles from file\n",\ " s: format input measurements for ISEG Fortran code\n\n",\ " t: transform absolute/base/fixed coordinate system\n\n",\ " d: draw 3D human using matplotlib\n",\ " v: draw 3D human using VPython\n\n",\ " h: print human properties\n",\ " g: print segment properties\n",\ " l: print solid properties\n\n",\ " c: combine solids/segments for inertia parameters\n\n",\ " o: options\n",\ " q: quit" userIn = raw_input("What would you like to do next? ") print "" # MODIFY JOINT ANGLES if userIn == 'j': # this function is defined above H = modify_joint_angles(H) # SAVE CURRENT JOINT ANGLES elif userIn == 'a': fname = raw_input("The joint angle dictionary CFG will be pickled" \ " into a file saved in the current directory." \ " Specify a file name (without quotes or spaces," \ " q to quit): ") if fname != 'q': H.write_CFG(fname) print "The joint angles have been saved in",fname,".pickle." # LOAD JOINT ANGLES elif userIn == 'p': print "Be careful with this, because there is no error checking"\ " yet. Make sure that the pickle file is in the same format"\ " as a pickle output file from this program." fname = raw_input("Enter the name of a CFG .TXT file" \ " including its extension" \ " (q to quit):") if fname != 'q': H.read_CFG(fname) print "The joint angles in",fname,".pickle have been loaded." # FORMAT INPUT MEASUREMENTS FOR ISEG FORTRAN CODE elif userIn == 's': fname = raw_input("Enter the file name to which you would like" \ " to write the ISEG input: ") if H.write_meas_for_ISEG(fname) == 0: print "Success!" else: print "Uh oh, there was an error when trying to write",\ "the ISEG input." # TRANSFORM COORDINATE SYSTEM elif userIn == 't': print "Transforming absolute/base/fixed coordinate system." print "First we will rotate the yeadon coordinate system " \ "with respect to your new, desired coordinate system. " \ "We will first rotate about your x-axis, then your " \ "y-axis, then your z-axis." thetx = raw_input("Angle (rad) about your x-axis: ") thety = raw_input("Angle (rad) about your y-axis: ") thetz = raw_input("Angle (rad) about your z-axis: ") H.rotate_coord_sys(inertia.rotate3(thetx,thety,thetz)) print "Now we'll specify the position of yeadon with respect to " \ "your coordinate system. You will provide the three " \ "components, x y and z, in YOUR coordinates." posx = raw_input("X-position (m): ") posy = raw_input("Y-position (m): ") posz = raw_input("Z-position (m): ") H.translate_coord_sys( (posx,posy,posz) ) print "All done!" # DRAW HUMAN WITH MATPLOTLIB elif userIn == 'd': print "To continue using the YEADON UI after drawing,",\ "close the plot window." H.draw() # DRAW HUMAN WITH VPYTHON elif userIn == 'v': H.draw_visual() # PRINT HUMAN PROPERTIES elif userIn == 'h': print "\nHuman properties." H.print_properties() # PRINT SEGMENT PROPERTIES elif userIn == 'g': print_segment_properties(H) # PRINT SOLID PROPERTIES elif userIn == 'l': print_solid_properties(H) # COMBINE INERTIA PARAMETERS elif userIn == 'c': print "Use the following variables/keywords to select which" \ " solids/segments to combine: " print " s0 - s7, a0 - a6, b0 - b6, j0 - j8, k0 - k8" print " P, T, C, A1, A2, B1, B2, J1, J2, K1, K2\n" print "Enter in the keywords one at a time. When you are " \ "done, enter q." combinedone = False combinectr = 1 objlist = [] while combinedone == False: objtemp = raw_input('Solid/segment #' + str(combinectr) + ': ') if objtemp == 'q': combinedone = True else: objlist.append(objtemp) combinectr += 1 print "Okay, get ready for your results (mass, COM, Inertia)!" combineMass,combineCOM,combineInertia = H.combine_inertia(objlist) print "These values are with respect to your fixed frame." print "Mass (kg):", combineMass print "COM (m):\n", combineCOM print "Inertia (kg-m^2):\n", combineInertia # OPTIONS elif userIn == 'o': optionsdone = 0 sym = ('off','on') while optionsdone != 1: print "\nOPTIONS" print "-------" print " 1: toggle symmetry (symmetry is",\ sym[ int(H.isSymmetric) ],"now)\n", \ " 2: scale human by mass\n", \ " q: back to main menu" optionIn = raw_input("What would you like to do? ") if optionIn == '1': if H.isSymmetric == True: H.isSymmetrc = False H.meas = meas elif H.isSymmetric == False: H.isSymmetric = True H.average_limbs() H.update_solids() print "Symmetry is now turned",sym,"." elif optionIn == '2': measmass = raw_input("Provide a measured mass with which "\ "to scale the human (kg): ") H.scale_human_by_mass(float(measmass)) elif optionIn == 'q': print "Going back to main menu." optionsdone = 1 else: print "Invalid input." elif userIn == 'q': print "Quitting YEADON" done = 1 else: print "Invalid input."
def play_with_one(self): playerOne = human.human() playerOneName = playerOne.give_name("PlayerOne") playerTwo = ai.ai() playerTwoName = playerTwo.generate_name() self.keep_score(playerOneName, playerTwoName, playerOne, playerTwo)
def update(self, monster): self.humansSaved = self.humansSaved + 1 self.monsterMash[self.monsterMash.index(monster)] = human() if (self.humansSaved == self.population): self.updateNeighborhood(self)
del self.dog[self.dog.index(d)] mark = 1 elif mark == 1: h = random.choice(self.human) h.hurt() print('%d号人被攻击,剩余%d生命值' % (h.num, h.hp)) if h.hp <= 0: print('%d号人倒地' % h.num) del self.human[self.human.index(h)] mark = 0 if len(self.human): print('人胜') else: print('狗胜') list1 = [] list2 = [] h1 = human(1) h2 = human(2) d1 = dog(1) d2 = dog(2) d3 = dog(3) list1.append(h1) list1.append(h2) list2.append(d1) list2.append(d2) list2.append(d3) f = fight(list1, list2) f.fight()
def play_with_two(self): playerOne = human.human() playerOneName = playerOne.give_name("PlayerOne") playerTwo = human.human() playerTwoName = playerTwo.give_name("PlayerTwo") self.keep_score(playerOneName,playerTwoName,playerOne,playerTwo)
def play_with_one(self): playerOne = human.human() playerOneName = playerOne.give_name("PlayerOne") playerTwo = ai.ai() playerTwoName = playerTwo.generate_name() self.keep_score(playerOneName,playerTwoName,playerOne,playerTwo)
from human import human from scissors import scissors from fire import fire state = True while state: player_element = input() player_element.lower() pc_element = random.randint(1, 9) if player_element == "камень" or player_element == "stone": stone(pc_element) if player_element == "пистолет" or player_element == "gun": gun(pc_element) if player_element == "вода" or player_element == "water": water(pc_element) if player_element == "воздух" or player_element == "air": air(pc_element) if player_element == "бумага" or player_element == "paper": paper(pc_element) if player_element == "губка" or player_element == "sponge": sponge(pc_element) if player_element == "человек" or player_element == "human": human(pc_element) if player_element == "ножницы" or player_element == "scissors": scissors(pc_element) if player_element == "огонь" or player_element == "fire": fire(pc_element) if player_element == "выход" or player_element == "exit": break
def addNewHumans(data): global people person = hu.human(data, len(people)) people.append(person)
# -*- coding: utf-8 -*- """ Created on Sat Apr 24 11:27:53 2021 @author: Hsieh """ import human a = human.human('David', 70, 100) print(a.name, 'bmi:', a.bmi()) b = human.woman('Jenny', 95, 160, 30, 20, 30) print(b.name, 'bmi:', b.bmi()) c = human.man('Alex', 68, 179, True) print(c.name, 'bmi:', c.bmi()) c.description()