def hub(): save.save_game() print(c.clear) print(c.yellow+"Welcome to the Pines!") hubquestion=input("Would you like to go to the field, shop, inn, or the old tower? (1), (2), (3), (4)"+c.reset+" >>>"+c.violet) if hubquestion=="1": print(c.yellow+"You decide to go to the field.") t.sleep(1.3) f.field() elif hubquestion=="2": print(c.yellow+"You decide to go to the shop.") t.sleep(1.3) shop() elif hubquestion=="3": print(c.yellow+"You decide to go to the inn.") t.sleep(1.3) inn() elif hubquestion=="4": print(c.yellow+"You take a lantern and travel to the old tower.") t.sleep(1.25) tower.tower() else: print("I don't understand...") t.sleep(1) hub()
def hub(): save.save_game() print(c.clear) print(c.yellow + "Welcome to the Pines!") hubquestion = input( "Would you like to go to the field, shop, inn, or the old tower? (1), (2), (3), (4)" + c.reset + " >>>" + c.violet) if hubquestion == "1": print(c.yellow + "You decide to go to the field.") t.sleep(1.3) f.field() elif hubquestion == "2": print(c.yellow + "You decide to go to the shop.") t.sleep(1.3) shop() elif hubquestion == "3": print(c.yellow + "You decide to go to the inn.") t.sleep(1.3) inn() elif hubquestion == "4": print(c.yellow + "You take a lantern and travel to the old tower.") t.sleep(1.25) tower.tower() else: print("I don't understand...") t.sleep(1) hub()
def place(self): x = int(input('x pos of your coin: ')) y = int(input('y pos of your coin: ')) if self.canPlace(x, y): if self.player1.isTurn(self.turn): self.board[y][x] = field.field(self.player1.getColor()) elif self.player2.isTurn(self.turn): self.board[y][x] = field.field(self.player2.getColor())
def check_updates(): print(strftime("%Y-%m-%d, %H:%M:%S: ", gmtime()) + "Update is now running") a = field('ios official') b = field('ios beta') c = field("firefox official") d = field("safari official") e = field("chrome webdrive") if field.load_and_compare(): print(strftime("%Y-%m-%d, %H:%M:%S: ", gmtime()) + "End of update: There was an update\n") else: print(strftime("%Y-%m-%d, %H:%M:%S: ", gmtime()) + "End of update: No update\n")
def hub(): print(c.clear) print(c.yellow+"Welcome to the Pines!") hubquestion=input("Would you like to go to the field, shop, or the inn? (1), (2), (3)"+c.reset+" >>>"+c.violet) if hubquestion=="1": print(c.yellow+"You decide to go to the field.") f.field() elif hubquestion=="2": print(c.yellow+"You decide to go to the shop.") t.sleep(1.3) shop() elif hubquestion=="3": pass
def create_game(self): self.end = False self.c = config() self.f = field(True, self.c.width, self.c.height, self.c.game) self.old_score = 0 self.history = history() self.history.save_state(self.f, self.f.p)
def menu_item_new_chillout(self, widget, event): self.history.fields_purge() self.c.game = 'chillout' self.f = field(True, self.c.width, self.c.height, self.c.game) self.old_score = 0 self.end = False self.queue_draw()
def generate_map(n): maps = [] for i in range(n): map_ = field(name=str(i), x=randint(20, 40), y=randint(20, 40)) #map_.create_boarder() #map_.create_room(randint(0,map_.width-6),randint(0,map_.height-6),randint(3,6),randint(3,6)) map_.rise_wall(map_.width * map_.height // 10) maps.append(map_) return maps
def menu_item_size_small(self, widget, event): self.history.fields_purge() self.c.width = 8 self.c.height = 10 self.c.size = 'small' self.f = field(True, self.c.width, self.c.height, self.c.game) self.old_score = 0 self.end = False self.resize_window() self.queue_draw()
def menu_item_size_extra_large(self, widget, event): self.history.fields_purge() self.c.width = 16 self.c.height = 19 self.c.size = 'extra_large' self.f = field(True, self.c.width, self.c.height, self.c.game) self.old_score = 0 self.end = False self.resize_window() self.queue_draw()
def __init__(self, x, y, vel, circle): self.x = x self.y = y self.vel = vel self.circle = circle self.press = None self.robot_field = field() self.center = geo.Point(self.x, self.y) self.intercept_radius = 0.5 self.intercept_circle = geo.Circle(self.center, self.intercept_radius)
def __init__(self, xSize, ySize, deltaX, deltaY, thickness=8.0, mode="TMz"): # init self.mode = mode self.thickness = thickness self.memoryField = fi.field(xSize, ySize, deltaX, deltaY) # crate material xShape, yShape = xSize / deltaX, ySize / deltaY self.material = { "sigmaOddX": numpy.zeros((xShape, yShape)), "sigmaOddY": numpy.zeros((xShape, yShape)), "sigmaEvenX": numpy.zeros((xShape, yShape)), "sigmaEvenY": numpy.zeros((xShape, yShape)), } self.mask = numpy.zeros((xShape, yShape)) # apply mode c1, c2 = 1.0, constants.u0 / constants.e0 if mode == "TEz": c1, c2 = c2, c1 # init PML sigmaMaxX = -(3.0 + 1.0) * constants.e0 * constants.c0 * math.log(1.0e-8) / (2.0 * deltaX * thickness) sigmaMaxY = -(3.0 + 1.0) * constants.e0 * constants.c0 * math.log(1.0e-8) / (2.0 * deltaY * thickness) for n in range(0, int(thickness + 1.0), 1): for j in range(0, int(yShape), 1): self.material["sigmaOddX"][n, j] = sigmaMaxY * math.pow((thickness - n) / thickness, 3.0) * c1 self.material["sigmaEvenX"][n, j] = sigmaMaxY * math.pow((thickness - n) / thickness, 3.0) * c2 self.mask[n, j] = 1.0 self.material["sigmaOddX"][xShape - 1 - n, j] = ( sigmaMaxY * math.pow((thickness - n) / thickness, 3.0) * c1 ) self.material["sigmaEvenX"][xShape - 1 - n, j] = ( sigmaMaxY * math.pow((thickness - n) / thickness, 3.0) * c2 ) self.mask[xShape - 1 - n, j] = 1.0 for i in range(0, int(xShape), 1): self.material["sigmaOddY"][i, n] = sigmaMaxX * math.pow((thickness - n) / thickness, 3.0) * c1 self.material["sigmaEvenY"][i, n] = sigmaMaxX * math.pow((thickness - n) / thickness, 3.0) * c2 self.mask[i, n] = 1.0 self.material["sigmaOddY"][i, yShape - 1 - n] = ( sigmaMaxX * math.pow((thickness - n) / thickness, 3.0) * c1 ) self.material["sigmaEvenY"][i, yShape - 1 - n] = ( sigmaMaxX * math.pow((thickness - n) / thickness, 3.0) * c2 ) self.mask[i, yShape - 1 - n] = 1.0
def lorentz(q, x0, y0, vx0, vy0, m, epsz, muz): # We use the [field] function E, B, theta = field(q, x0, y0, vx0, vy0, m, epsz, muz) v = np.array([vx0, vy0, np.zeros(len(vx0))]) Ex = E.dot(np.array(np.cos(theta))) Ey = E.dot(np.array(np.sin(theta))) Etot = [np.sum(Ex, axis=1), np.sum(Ey, axis=1), np.zeros(len(vx0))] Btot = [np.zeros(len(vx0)), np.zeros(len(vx0)), np.sum(B, axis=1)] # Cross products Fcross = np.cross(np.swapaxes(v, 0, 1), np.swapaxes(Btot, 0, 1)) Fcross = np.swapaxes(Fcross, 0, 1) # Lorentz = E * Fcross F = q * [Etot[0] + Fcross[0], Etot[1] + Fcross[1], Etot[2] + Fcross[2]] return F, Etot, Btot, Ey
def __init__(self, xSize, ySize, deltaX, deltaY, mode='TMz'): # init layer xShape = xSize/deltaX yShape = ySize/deltaY self.material = {'epsilon': numpy.ones((xShape, yShape)), 'mu': numpy.ones((xShape, yShape)), 'sigma': numpy.zeros((xShape, yShape)) } # create memoryField self.memoryField = fi.field(xSize, ySize, deltaX, deltaY) # save atributes self.mode = mode self.deltaX = deltaX self.deltaY = deltaY self.xSize = xSize self.ySize = ySize
def __init__(self, A=0, B=0, Polynomial=0, Generator=0, Order = 0): self.A = mpz(A) self.B = mpz(B) self.Polynomial = mpz(Polynomial) self.Generator = Generator width = self.Generator.bit_length() width += 8 - ((width % 8) or 8) c = self.Generator >> (width-8) if c == 4: self.Gx = (self.Generator ^ (c << (width-8))) >> ((width-8)/2) self.Gy = (self.Generator ^ (c << (width-8)) ^ (self.Gx << ((width-8)/2))) self.Field = field.field(self.Polynomial) self.Order = mpz(Order) self.G = point(self.Gx, self.Gy) if self.isNotPoint(self.G): print 'generator not good'
def _sample(self): from field import field from player import player from math import cos, sin, radians, sqrt from random import random, randint template_field = field() score = -100 action = [0, 0] #Number of trials : 100 for i in range(100): template_player = player(self.sitiation[0], self.sitiation[1]) template_score = 0 #Search depth for t in range(5): d = random() # Moving radius r = radians(randint(0, 359)) if (t == 0): template_action = [d * cos(r), d * sin(r)] template_player.simulation_move(d * cos(r), d * sin(r)) if (template_field.check_player_status(template_player) == "gameover"): break #Evaluation value state = template_field.check_player_status(template_player) if (state == "gameover"): template_score = -100 elif (state == "playing"): GOAL_POSITION_X = 9.5 GOAL_POSITION_Y = 9.5 template_score = -sqrt( (GOAL_POSITION_X - template_player.position_x)**2 + (GOAL_POSITION_Y - template_player.position_y)**2) else: template_score = 1 #update if (score < template_score): score = template_score action = template_action return action[0], action[1]
def battle_window(screen): winrect = screen.get_rect() f = fie.field((20, 20)) flag = 0 mouseDown_flag = False isBattle = True while (isBattle): screen.fill((122, 255, 122)) isBattle = f.draw(screen) if not isBattle: pygame.mixer.stop() winner = f.result() result_window(screen, winner, f) return if pygame.mouse.get_pressed()[0]: #押している間は牌を表示 pos = pygame.mouse.get_pos() f.putdemo(pos, screen) mouseDown_flag = True pygame.display.update() # 画面更新 pygame.time.wait(20) # 更新間隔 for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() elif event.key == K_p: f.pass_turn() if event.type == MOUSEBUTTONUP and mouseDown_flag: pos = pygame.mouse.get_pos() f.put(pos) mouseDown_flag = False
def main(): #initialize field and player base_field = field() base_player = player() history = [] turn = 0 while (base_field.check_player_status(base_player) == "playing"): history.append(base_player.position_x) history.append(base_player.position_y) situation = [base_player.position_x, base_player.position_y] base_player.move(situation) turn += 1 print("player's position: ({},{})".format(base_player.position_x, base_player.position_y)) if (base_field.check_player_status(base_player) == "clear"): print("clear") print(turn) with open("output.csv", "w") as f: writer = csv.writer(f, lineterminator='\n') writer.writerow(history) else: print("gameover")
def scanner(): if player.hp < 1: print("You Died!") t.sleep(1) ter=input(c.yellow+"Do you want to keep playing, or quit? (1), (2)"+c.reset+" >>>"+c.violet).strip() if ter == '1': f.field() elif ter == '2': exit() else: f.field() elif monster.hp < 1: print(c.yellow+"You won!") t.sleep(1) curr=random.randint(10,25) print("You got "+str(curr)+" Gold!") cl.Player.gold+=int(curr) t.sleep(1) save.save_game() input('[Game Saved! Press enter to continue.]') f.field()
def f1(arg): return Unique(field(data, "job-name"), ignore_case=True)
"y": 1, "dist": 1 }), target=room1_act.player) room1_act.add_actor(Enemy({ "name": "rat", "SPD": 10, "HP": 10, "STR": 5, "DEF": 5, "x": 3, "y": 4, "dist": 1 }), target=room1_act.player) room1_map = field(name="room1") room1_map.door[1][1] = ["room2", 8, 8] room2_act = ActorController() p = Player({ "name": "Player", "SPD": 20, "HP": 100, "STR": 150, "DEF": 5, "x": 5, "y": 5 }) room2_act.add_actor_as_player(p) room2_act.add_actor(Enemy({ "name": "bat",
def f1(arg): return sorted(list(Unique(field(arg, 'job-name'), ignore_case=True)))
def f1(arg): return sorted(Unique([x for x in field(arg, "job-name")], ignore_case=True))
def __init__(self, arraySize, fieldSize): self.arraySize = arraySize self.fieldSize = fieldSize self.array = [field(fieldSize, 0) for x in range(arraySize)]
def start_game(self): self.character = self.create_character() self.show('stats') self.Field = field(self.character) self.status = 'moving' self.game()
string += str(self.array[self.arraySize - 1].getValue()) + ']' print(string) def giveArraySimpleForm(self): tempList = [] ''' return coefficient as an simple array''' for i in range(self.arraySize): tempList.append(self.array[i].getValue()) return tempList if __name__ == "__main__": varJ = fieldArray(10, 10) varJ.fillRandom() varJ.show() varK = fieldArray(10, 10) varK.fillRandom() varK.show() varTest = varK * varJ varTest.show() varA = field(10, 7) varB = field(10, 5) varC = varA + varB varD = varA * varC print(varC.getValue()) print(varD.getValue())
def __init__(self, parent, **kwargs): super().__init__(**kwargs) # Store mainWindow to use in slots self.mainWindow = parent # Set tabWidget properties self.setTabsClosable(True) self.setMovable(True) self.setTabShape(QtWidgets.QTabWidget.Triangular) self.tabCloseRequested.connect(self.on_tabCloseRequested) parent.setCentralWidget(self) # ITRI: we need easier interface (loaded default) parent.easyWidget = QtWidgets.QWidget() self.gridLayout = QtWidgets.QGridLayout() parent.easyWidget.setLayout(self.gridLayout) # select part groupboxSelectFormat = QtWidgets.QGroupBox(self.tr("選擇輸出格式 (更改勾選後,再按一次生效)")) sp = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred , QtWidgets.QSizePolicy.Preferred) sp.setVerticalStretch(5) groupboxSelectFormat.setSizePolicy(sp) groupboxSelectFormatLayout = QtWidgets.QHBoxLayout() groupboxSelectFormat.setLayout(groupboxSelectFormatLayout) btn_format1 = QtWidgets.QPushButton() btn_format1.pressed.connect(self.on_btn_format1_pressed) btn_format1.setText(self.tr("附件二")) btn_format2 = QtWidgets.QPushButton() btn_format2.pressed.connect(self.on_btn_format2_pressed) btn_format2.setText(self.tr("專利清查")) btn_format2_2 = QtWidgets.QPushButton() btn_format2_2.pressed.connect(self.on_btn_format2_2_pressed) btn_format2_2.setText(self.tr("授權資料")) btn_format3 = QtWidgets.QPushButton() btn_format3.pressed.connect(self.on_btn_format3_pressed) btn_format3.setText(self.tr("專利清單")) btn_format4 = QtWidgets.QPushButton() btn_format4.pressed.connect(self.on_btn_format4_pressed) btn_format4.setText(self.tr("計價格式")) btn_format5 = QtWidgets.QPushButton() btn_format5.pressed.connect(self.on_btn_format5_pressed) btn_format5.setText(self.tr("計價表格")) sp2 = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred , QtWidgets.QSizePolicy.Preferred) sp2.setVerticalStretch(2) btn_format1.setSizePolicy(sp2) btn_format2.setSizePolicy(sp2) btn_format2_2.setSizePolicy(sp2) btn_format3.setSizePolicy(sp2) btn_format4.setSizePolicy(sp2) btn_format5.setSizePolicy(sp2) bigFont = QtGui.QFont() bigFont.setPointSize(18) bigFont.setBold(True) btn_format1.setFont(bigFont) btn_format2.setFont(bigFont) btn_format2_2.setFont(bigFont) btn_format3.setFont(bigFont) btn_format4.setFont(bigFont) btn_format5.setFont(bigFont) groupboxSelectFormatLayout.addWidget(btn_format1, QtCore.Qt.AlignCenter) groupboxSelectFormatLayout.addWidget(btn_format2, QtCore.Qt.AlignCenter) groupboxSelectFormatLayout.addWidget(btn_format2_2, QtCore.Qt.AlignCenter) groupboxSelectFormatLayout.addWidget(btn_format3, QtCore.Qt.AlignCenter) groupboxSelectFormatLayout.addWidget(btn_format4, QtCore.Qt.AlignCenter) groupboxSelectFormatLayout.addWidget(btn_format5, QtCore.Qt.AlignCenter) self.gridLayout.addWidget(groupboxSelectFormat, 0, 0) # target vals part groupboxTargetVals = QtWidgets.QGroupBox(self.tr("填入目標值")) sp3 = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred , QtWidgets.QSizePolicy.Preferred) sp3.setVerticalStretch(15) groupboxTargetVals.setSizePolicy(sp3) groupboxTargetValsLayout = QtWidgets.QVBoxLayout() groupboxTargetVals.setLayout(groupboxTargetValsLayout) self.checkbox_p40_patentno = QtWidgets.QCheckBox() self.checkbox_p40_patentno.setText(self.tr("件編號")) self.checkbox_p40_patentno.setChecked(True) self.checkbox_p40_patentno.stateChanged.connect(self.on_checkbox_p40_patentno_stateChanged) self.checkbox_p40_applypntno = QtWidgets.QCheckBox() self.checkbox_p40_applypntno.setText(self.tr("申請案號")) self.checkbox_p40_applypntno.stateChanged.connect(self.on_checkbox_p40_applypntno_stateChanged) self.targetValsEdit = QtWidgets.QTextEdit() okToChangeValsBtn = QtWidgets.QPushButton() okToChangeValsBtn.setFixedSize(100, 50) okToChangeValsBtn.setText(self.tr("確認")) okToChangeValsBtn.pressed.connect(self.on_okToChangeValsBtn_pressed) outputBtn = QtWidgets.QPushButton() outputBtn.setFixedSize(100, 50) outputBtn.setText(self.tr("輸出")) outputBtn.pressed.connect(self.on_outputBtn_pressed) groupboxTargetValsLayout.addWidget(self.checkbox_p40_patentno, QtCore.Qt.AlignCenter) groupboxTargetValsLayout.addWidget(self.checkbox_p40_applypntno, QtCore.Qt.AlignCenter) groupboxTargetValsLayout.addWidget(self.targetValsEdit, QtCore.Qt.AlignCenter) groupboxTargetValsLayout.addWidget(okToChangeValsBtn) groupboxTargetValsLayout.addWidget(outputBtn) self.gridLayout.addWidget(groupboxTargetVals, 1, 0) self.addTab(parent.easyWidget, self.tr("簡易介面")) # Main work space parent.mainWidget = QtWidgets.QSplitter() # make field of mainWindow to access mainWidget in other places propertiesWidget = properties.properties(parent) parent.mainWidget.addWidget(propertiesWidget) self.fieldWidget = field.field(parent) parent.mainWidget.addWidget(self.fieldWidget) parent.mainWidget.setSizes([320, 1600]) self.addTab(parent.mainWidget, self.tr("樣板工作區"))
def main(): # print ("The values are....", roll.roll(min, max), roll.roll(min, max)) # print ("The values are....", roll.sum_rolls(3)) # print ("Compared to 4 ....", roll.compare_rolls(2, 4)) # group = [[1,2],[3,4],[5,6]] # val = roll.sum_rolls(1) # print ("Roll",val,"Matches group",roll.find_group(val, group)); # t = team.team(1) # print (t) # t2 = team.team(1) # print (t2) # with open('data.pickle', 'wb') as f: # Pickle the 'data' dictionary using the highest protocol available. # pickle.dump(t2, f, pickle.HIGHEST_PROTOCOL) # f.close() # with open('data.pickle', 'rb') as g: # The protocol version used is detected automatically, so we do not # have to specify it. # data = pickle.load(g) # g.close() # print (data) ssn = season.season(2020) with open('data.2020', 'wb') as f: pickle.dump(ssn, f, pickle.HIGHEST_PROTOCOL) f.close() with open('data.2020', 'rb') as g: data = pickle.load(g) g.close() print(data) f = field.field(int((1800 / 2) - (1598 / 2)), int((900 / 2) - (821 / 2))) m = match.match(f) # v = view.view(1598,821) v = view.view(1800, 900) playing = True last = time.time() * 1000 while (playing == True): new = time.time() * 1000 elapsed = new - last if (elapsed >= 20): last = new v.view_refresh(v.window, f) if (m.do_tick() == 0): # playing = False playing = True events = sdl2.ext.get_events() for event in events: if event.type == sdl2.SDL_QUIT: running = False break if event.type == sdl2.SDL_MOUSEBUTTONDOWN: print("Mouse Button Down", event.button.button, event.button.x, event.button.y, event.button.state, event.button.clicks) f.add_ball(event.button.x, event.button.y) # draw_rect(windowsurface, event.button.x, event.button.y, 10, 10) break if event.type == sdl2.SDL_MOUSEBUTTONUP: print("Mouse Button Up", event.button.button, event.button.x, event.button.y, event.button.state, event.button.clicks) break if event.type == sdl2.SDL_MOUSEMOTION: print("Mouse Motion", event.motion.which, event.motion.state, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel) break if event.type == sdl2.SDL_MOUSEWHEEL: print("Mouse Wheel", event.wheel.x, event.wheel.y, event.wheel.direction) break if event.type == sdl2.SDL_KEYDOWN: print("Key Down: ", event.key.state) if (event.key.keysym.sym == sdl2.SDLK_UP): print("Up Arrow") if (event.key.keysym.sym == sdl2.SDLK_DOWN): print("DOWN Arrow") if (event.key.keysym.sym == sdl2.SDLK_a): print("a") break
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import json import tornado from tornado import websocket from tornado import web from field import field color = {} player = [] gameField = field() class MainHandler(tornado.web.RequestHandler): def get(self): if self.request.uri == "/": self.render("../static/index.html") class EchoWebSocket(websocket.WebSocketHandler): def open(self): print "open" player.append(self) def on_message(self, message): data = json.loads(message) print "#receive: %s" % data
def f1(arg): return sorted(list(Unique(field(arg, 'job-name'), ignore_case=True)), key=lambda x: str.casefold(x))
################################################################################################# # some initial setup for the plot and the world figure, ax = plt.subplots() ax.set_xlim(field.leftx - 1, field.rightx + 1) ax.set_ylim(field.boty - 1, field.topy + 1) world = world() world.create_their_bots(11) world.create_our_bots(11) world.plot_bots(ax) # some constants for the field N = 30 x = np.linspace(field.leftx, field.rightx, N, endpoint=False) y = np.linspace(field.boty, field.topy, N, endpoint=False) main_field = field() # when the robots are dragged, the cost function needs to be recalculated def redraw_cost_function(): z = np.array([[a.cost_function(xpoint, ypoint)[0] for xpoint in x] for ypoint in y]) # remove the current imshow object, otherwise it stacks them on each other and your program will run slower for child in ax.get_children(): if type(child) is AxesImage: child.remove() p = plt.imshow(z, extent=[field.leftx, field.rightx, field.topy, field.boty], cmap="Blues") figure.canvas.draw() print("Finished redrawing cost function.")
class FourWins(object): board = [[field.field()] * 7 for c in range(7)] player1 = player.player('empty', 0) player2 = player.player('empty', 0) turn = 0 def getTurn(self): return self.turn def __init__(self, p1, p2): self.player1 = p1 self.player2 = p2 def output(self): sys.stdout.write(' ') for p in range(0, 6): sys.stdout.write(str(p) + ' ') sys.stdout.write('\n') for i in range(0, 6): sys.stdout.write(str(i) + ' ') for k in range(0, 6): if self.board[i][k].getFigur() == 'red': sys.stdout.write('R ') if self.board[i][k].getFigur() == 'yellow': sys.stdout.write('Y ') if self.board[i][k].getFigur() == 'empty': sys.stdout.write('░ ') #176 sys.stdout.write('\n') def checkWinner(self): winner = 'n' for i in range(0, 3): for k in range(0, 6): if self.board[0 + i][k].getFigur() != 'empty': if self.board[0 + i][k].getFigur() == self.board[ 1 + i][k].getFigur() == self.board[2 + i][k].getFigur( ) == self.board[3 + i][k].getFigur(): if self.board[0 + i][k].getFigur() == 'red': winner = 'red' elif self.board[0 + i][k].getFigur() == 'yellow': winner = 'yellow' for i in range(0, 6): for k in range(0, 3): if self.board[i][0 + k].getFigur() != 'empty': if self.board[i][0 + k].getFigur() == self.board[i][ 1 + k].getFigur() == self.board[i][2 + k].getFigur( ) == self.board[i][3 + k].getFigur(): if self.board[i][0 + k].getFigur() == 'red': winner = 'red' elif self.board[i][0 + k].getFigur() == 'yellow': winner = 'yellow' #diagonal to come return winner def canPlace(self, x, y): if not self.board[y][x].getFigur() == 'empty': return False if not y == 5: if self.board[y + 1][x].getFigur() == 'empty': return False return True def place(self): x = int(input('x pos of your coin: ')) y = int(input('y pos of your coin: ')) if self.canPlace(x, y): if self.player1.isTurn(self.turn): self.board[y][x] = field.field(self.player1.getColor()) elif self.player2.isTurn(self.turn): self.board[y][x] = field.field(self.player2.getColor()) def gameloop(self): winner = 'n' while winner == 'n' and self.turn < 49: clear() self.output() self.place() winner = self.checkWinner() self.turn += 1 self.output() if winner == self.player1.getColor(): return self.player1 elif winner == self.player2.getColor(): return self.player2 else: return 'n'
Nsteps = 20000001 # total number of timesteps to run Ndump = 2500 # output every this number of timesteps Nrat = 20 # update radiative transfer this number of time-steps Short_Fric = False ## whether to use short friction time approx or not Arad = True Haze_flux = 1e-14 Kzz = 1e6 Tstar = 5777. #### initialise the grid gd = grid.grid(9.9e9, 1.181e10, 0.01, np.pi - 0.01, 225, 2000, 2.) ry = grid.rays(gd, 400, 3.) fd = field.field(gd, 1, 1.25) sy = field.system(9.5e29, 3.83e33, 0.03 * 1.5e13, 5e6, 0., 2.35) fd.setup_iso_atm(sy, gd, True) fd.short_friction = Short_Fric fd.Tstar = Tstar sy.kappa_star = 4e-3 ### value from Guillot et al. (2010) ry.get_tau_grid_analytic(gd, sy) #### Below is for testing ray-tracing scheme on analytic gas profile #ry.do_ray_trace(fd.gas_dens*sy.kappa_star) ### using analytic gas optical depth calculation #pu.update_tau_b_gas(fd,gd,ry,sy)
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import json import tornado from tornado import websocket from tornado import web from field import field color = {} player = [] gameField = field() class MainHandler(tornado.web.RequestHandler): def get(self): if self.request.uri == "/": self.render("../static/index.html") class EchoWebSocket(websocket.WebSocketHandler): def open(self): print "open" player.append(self) def on_message(self, message): data = json.loads(message) print "#receive: %s" % data if data["message"] == "connect": # send complete array to new player response = {"message":"init", "data": {"collision": gameField.fieldMap, "color":color}}
def init(self): self.field = field() self.playerConnect =[] self.player = {}
# Call each function and write to excel sample(sccwrp_field_results).to_excel(writer, sheet_name="Sample", index=False) samplehistory(sccwrp_field_results).to_excel(writer, sheet_name="SampleHistory", index=False) personnel(sccwrp_field_results).to_excel(writer, sheet_name="PersonnelDuty", index=False) locations(sccwrp_field_results).to_excel(writer, sheet_name="Locations", index=False) field(sccwrp_field_results).to_excel(writer, sheet_name="FieldResults", index=False) habitat(sccwrp_field_results).to_excel(writer, sheet_name="HabitatResults", index=False) pd.read_excel('info/BLM_Project_SWAMPformat_Field_CollectionResults.xlsx', sheet_name = "BenthicResults") \ .to_excel(writer, sheet_name = "BenthicResults", index = False) pd.read_excel('info/BLM_Project_SWAMPformat_Field_CollectionResults.xlsx', sheet_name = "ChemResults") \ .to_excel(writer, sheet_name = "ChemResults", index = False) pd.read_excel('info/BLM_Project_SWAMPformat_Field_CollectionResults.xlsx', sheet_name = "LabBatch") \ .to_excel(writer, sheet_name = "LabBatch", index = False) # Save it and we're done! writer.save() # Use openpyxl to fit the columns to character width
from field import field from unique import Unique from gen_random import gen_random goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'color': 'black' }] data = [ 1, 1, 11, 1, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] if __name__ == "__main__": print(list(gen_random(20, 1, 100))) print(list(field(goods, 'title'))) print(list(Unique(data)))
def f1(arg): return sorted(unique.Unique(list(field.field(arg, "job-name"))), key=str.lower)
__author__ = 'mitik' from field import field a = field('chrome webdrive') b = field('ios beta') c = field("firefox official") d = field("chrome webdrive") a.load_and_compare()
return err, x except: print("not an int") def throw(place): print("Throw a water balloon!") err = True while err: err, x = clean(input('x coordinate for a water balloon')) err, y = clean(input('y coordinate for a water balloon')) print("a water balloon at %s" % [x,y]) place.loadbod(grenade(x,y)) place.display() def quit(): if input("q to quit").upper()=="Q": return False else: return True keepgoing = True title() f = field(10) f.display() populate(f) while keepgoing == True: throw(f) keepgoing = quit()