def testComputerErrorEquality(self): equation = "5 * X = 1 * X^0 = 3 * X" with self.assertRaises(SystemExit) as cm: computer(equation) self.assertEqual(cm.exception.code, 1) equation = "5 * X + 3 * X" with self.assertRaises(SystemExit) as cm: computer(equation) self.assertEqual(cm.exception.code, 1)
def testComputerPol2DiscriminantNull(self): equation = "6 * X^0 + 11 * X^1 + 5 * X^2 = 1 * X^0 + X" result = computer(equation) self.assertEqual(result['degree'], 2) self.assertEqual(result['discriminant'] == 0, True) self.assertEqual(result['solution'], True) self.assertEqual(result['solution2'], None)
def startDB(self): players = dict() idList, cashList = self.getUsers() for id, cash in zip(idList, cashList): tempPlayer = player.player(id, cash) tempPlayer.computer = computer.computer() try: self.cursor.execute( 'SELECT * FROM computersetup_{}'.format(id)) componentList = self.cursor.fetchall() motherboardDB = list( filter(lambda x: x[0] == "Материнская плата", componentList)) motherboard = tempPlayer.menu.structure["Магазин"][ "Материнская плата"][motherboardDB[0][1]]['Слоты'] addCompResult = tempPlayer.computer.setMotherBoard(motherboard) for component in componentList: if component[0] != "Материнская плата": tempPlayer.computer.addComponent( component[0], component[1], component[2], component[3], component[4]) except: self.conn.commit() players[id] = tempPlayer return players
def __init__(self,name): ''' Constructor for a game of rock paper scissors Initializes Player and computer to None Initializes rounds to 0 @param name: The user-given name for the Player ''' self.player = player(name) self.computer = computer() self.rounds = 0
def save_computer(self, master, name, height, width, weight, processorId): compid = self.generate_computer_id() if self.check_processorId_exist(processorId.get()): comp = computer(compid, name.get(), height.get(), width.get(), weight.get(), processorId.get()) Computers.add_computer(comp) self.tree.insert("", Computers.get_len()-1, values=(Computers.computers[Computers.get_len()-1].id,Computers.computers[Computers.get_len()-1].Name, Computers.computers[Computers.get_len()-1].Height,Computers.computers[Computers.get_len()-1].Width ,Computers.computers[Computers.get_len()-1].Weight, Computers.computers[Computers.get_len()-1].ProcessorId)) master.destroy() else: messagebox.showwarning("Warning!","Processor with such ID is missing", parent=master)
def decode(target, optcodes): """Decode using computer attempting to reach target output.""" base_optcodes = optcodes for noun in range(100): optcodes[1] = noun for verb in range(100): optcodes[2] = verb try: print(f'Trying noun({noun}), verb({verb}): ' f'Output={computer(optcodes)[0]}') if computer(optcodes)[0] == target: return noun, verb except IndexError: print(f'Noun({noun}, verb({verb}) pair raise errors.') optcodes = base_optcodes continue optcodes = base_optcodes
class player(): computer = computer.computer() menu = menu.menu() hints = None cash = 1500 id = 0 def calculateCash(self): self.cash += self.computer.calculatePerformance() return self.cash def __init__(self, id, cash): super().__init__() hintsData = json.loads(open("hints", encoding="utf-8-sig").read()) hintKeys = list(hintsData) self.hints = list() self.id = id self.cash = cash for key in hintKeys: self.hints.append(key + " : " + hintsData[key])
def testComputerErrorNegative(self): equation = "6 * X^0 + -4 * X^2 = 1 * X^0" with self.assertRaises(SystemExit) as cm: computer(equation) self.assertEqual(cm.exception.code, 1)
import chess as chess import chess_rules import computer as cp import pygame times_to_run = 100 for game_count in range(times_to_run): print(f"GAME COUNT {game_count}") player1 = cp.computer("White") player2 = cp.computer("Black") chess.init_game(player1, player2) # del chess
from Board import board from computer import computer from sys import maxsize from copy import deepcopy #Board initialization gameBoard = board(8) #Player choice variable playerChoice = "" #Player array players = list("012") currentTile = 1 wilfred = computer(gameBoard) #Greetings print("Welcome to Ganji-Ho") #Game Setup while True: print("-------------------") print("Please select game mode.") print("Press 1 for Player versus Player") print("Press 2 for Player versus AI") print("Press 3 for instructions") choice = raw_input("\nEnter choice here: ")
def __init__(self): self.blank = blank() self.chessboard = [[self.blank for y in range(8)] for x in range(8)] self.pieces = { 'wk': King_white(), 'wq': Queen_white(), 'wr1': Rook_white(), 'wr2': Rook_white(), 'wb1': Bishop_white(), 'wb2': Bishop_white(), 'wn1': Knight_white(), 'wn2': Knight_white(), 'wp1': Pawn_white(), 'wp2': Pawn_white(), 'wp3': Pawn_white(), 'wp4': Pawn_white(), 'wp5': Pawn_white(), 'wp6': Pawn_white(), 'wp7': Pawn_white(), 'wp8': Pawn_white(), 'bk': King_black(), 'bq': Queen_black(), 'br1': Rook_black(), 'br2': Rook_black(), 'bb1': Bishop_black(), 'bb2': Bishop_black(), 'bn1': Knight_black(), 'bn2': Knight_black(), 'bp1': Pawn_black(), 'bp2': Pawn_black(), 'bp3': Pawn_black(), 'bp4': Pawn_black(), 'bp5': Pawn_black(), 'bp6': Pawn_black(), 'bp7': Pawn_black(), 'bp8': Pawn_black(), } self.chessboard[0][0] = self.pieces['br1'] self.pieces['br1'].pos = [0, 0] self.chessboard[0][7] = self.pieces['br2'] self.pieces['br2'].pos = [0, 7] self.chessboard[7][0] = self.pieces['wr1'] self.pieces['wr1'].pos = [7, 0] self.chessboard[7][7] = self.pieces['wr2'] self.pieces['wr2'].pos = [7, 7] self.chessboard[0][1] = self.pieces['bn1'] self.pieces['bn1'].pos = [0, 1] self.chessboard[0][6] = self.pieces['bn2'] self.pieces['bn2'].pos = [0, 6] self.chessboard[7][1] = self.pieces['wn1'] self.pieces['wn1'].pos = [7, 1] self.chessboard[7][6] = self.pieces['wn2'] self.pieces['wn2'].pos = [7, 6] self.chessboard[0][2] = self.pieces['bb1'] self.pieces['bb1'].pos = [0, 2] self.chessboard[0][5] = self.pieces['bb2'] self.pieces['bb2'].pos = [0, 5] self.chessboard[7][2] = self.pieces['wb1'] self.pieces['wb1'].pos = [7, 2] self.chessboard[7][5] = self.pieces['wb2'] self.pieces['wb2'].pos = [7, 5] self.chessboard[0][4] = self.pieces['bk'] self.pieces['bk'].pos = [0, 4] self.chessboard[7][4] = self.pieces['wk'] self.pieces['wk'].pos = [7, 4] self.chessboard[0][3] = self.pieces['bq'] self.pieces['bq'].pos = [0, 3] self.chessboard[7][3] = self.pieces['wq'] self.pieces['wq'].pos = [7, 3] self.amentia = cp.computer() for i in range(1, 9): self.chessboard[1][i - 1] = self.pieces['bp' + str(i)] self.pieces['bp' + str(i)].pos = [1, i - 1] self.chessboard[-2][i - 1] = self.pieces['wp' + str(i)] self.pieces['wp' + str(i)].pos = [-2, i - 1] self.board_range = [] for y in range(8): for x in range(8): self.board_range.append([y, x])
def testComputerErrorNotEntire(self): equation = "6 * X^0 + 4.2 * X^2 = 1 * X^0" result = computer(equation)
def __init__(self, players): self.players = [] self.players.append( player(400, 40, 0, 350, 40, 0, 300, 40, 0, 350, 120, 0)) if players == 2: self.players.append( computer(300, 460, 180, 350, 460, 180, 400, 460, 180, 350, 380, 180)) elif players == 3: self.players.append( computer(40, 200, 90, 40, 250, 90, 40, 300, 90, 120, 250, 90, 120, 250, 90)) self.players.append( computer(660, 200, 270, 660, 250, 270, 660, 300, 270, 580, 250, 270)) elif players == 4: self.players.append( computer(40, 200, 90, 40, 250, 90, 40, 300, 90, 120, 250, 90)) self.players.append( computer(300, 460, 180, 350, 460, 180, 400, 460, 180, 350, 380, 180)) self.players.append( computer(660, 300, 270, 660, 250, 270, 660, 200, 270, 580, 250, 270)) self.top = None self.bottom = None self.behind = None self.deck = [ 'ac', 'as', 'ah', 'ad', '2c', '2s', '2h', '2d', '3c', '3s', '3h', '3d', '4c', '4s', '4h', '4d', '5c', '5s', '5h', '5d', '6c', '6s', '6h', '6d', '7c', '7s', '7h', '7d', '8c', '8s', '8h', '8d', '9c', '9s', '9h', '9d', '10c', '10s', '10h', '10d', 'jc', 'js', 'jh', 'jd', 'qc', 'qs', 'qh', 'qd', 'kc', 'ks', 'kh', 'kd', ] self.turn = -1 self.newturn = -1 self.lastturn = None self.knocked = False self.const = 3.25 self.deal()
def testComputerPol2DiscriminantNegative2(self): equation = "4 * X^0 + 3 * X^1 + X^2 = 0" result = computer(equation) self.assertEqual(result['degree'], 2) self.assertEqual(result['discriminant'] < 0, True) self.assertEqual(result['solution'], True)
def testComputerNullCoeff(self): equation = "6 * X^0 + 0 * X^2 = 1 * X^0" result = computer(equation) self.assertEqual(result['solution'], False)
import computer import json motherBoardDefinition = "{" \ " \"slots\" : " \ " {" \ " \"Процессор\": 2," \ " \"Память\" : 4," \ " \"Жесткий_диск\" : 2," \ " \"Видеокарта\" : 1" \ " }" \ "}" computer = computer.computer() computer.setMotherBoard(json.loads(motherBoardDefinition)['slots']) res = computer.addComponent("Процессор", { "Модель": "Athlon", "Производительность": 500 }) res = computer.addComponent("Процессор", { "Модель": "Athlon", "Производительность": 500 }) computer.removeComponent("Процессор", 1) res = computer.addComponent("Процессор", { "Модель": "Athlon", "Производительность": 500 })
#!/usr/bin/python3 import sys from computer import computer if __name__ == "__main__": c = computer() c.load(sys.argv[1]) c.execute()
def testComputerPolToHigh(self): equation = "6 * X^0 + 4 * X^18 - 9.3 * X^3 = 1 * X^0" result = computer(equation) self.assertEqual(result['solution'], False)
def testComputerPolNoSolution(self): equation = "5 * X^0 = 8 * X^0" result = computer(equation) self.assertEqual(result['solution'], False)
def testComputerPol0(self): equation = "5 * X^2 = 5 * X^2" result = computer(equation) self.assertEqual(result['solution'], None)
def testComputerPol1_2(self): equation = "5 * X^0 + 4 + 7 * X^1 + 8 * X = 0" result = computer(equation) self.assertEqual(result['degree'], 1) self.assertEqual(result['solution'], True)
def testComputerPol1(self): equation = "5 * X^0 + 4 * X^1 - 0 * X^2 = 1 * X^0" result = computer(equation) self.assertEqual(result['degree'], 1) self.assertEqual(result['solution'], True)
def __init__(self,difLevel,compStat,playerStat): self.difLevel=1; self.comp = computer([1,2,1,0,2,0],compStat); self.human = player([2,1,1,0,2,0],playerStat); self.alpha=-200;#for maximiser self.beta=200;#for minimizer
def testComputerErrorConstruction(self): equation = "5X^0 + 4X^1 - 0 * X^2 = 1 * X^0" with self.assertRaises(SystemExit) as cm: computer(equation) self.assertEqual(cm.exception.code, 1)
def testComputerErrorCaracters(self): equation = "5glezjjngv = 1 * X^0" with self.assertRaises(SystemExit) as cm: computer(equation) self.assertEqual(cm.exception.code, 1)
def testComputerPol2(self): equation = "6 * X^0 + 4 * X^1 - 9.3 * X^2 = 1 * X^0" result = computer(equation) self.assertEqual(result['degree'], 2) self.assertEqual(result['discriminant'] > 0, True) self.assertEqual(result['solution'], True)
from computer import computer from laptop import laptop import json import xml.etree.ElementTree as ET voltage = int(input(" Input your voltage? ")) computer1 = computer('ARTLINE_Home_H43_v02', 'Win10', 'win_pc', voltage) hp = laptop('HP_Pavilion_dv6-6c55er', 'Win10', 'laptop_pc', voltage) print(computer1) print(computer1.working()) print(hp) print(hp.working()) # Homework-6 computer1_json = { "specifications": 'ARTLINE_Home_H43_v02', "software": 'Win10', "device_name": 'win_pc', "voltage": voltage, } s = json.dumps(computer1_json) def transporter_in_json(self): z = open('computer1.json', 'w') z.write(self) z.close() transporter_in_json(s)
def any_msg(message): #initUser(message.from_user.id) if message.text == "/start": # keyboard = types.ReplyKeyboardMarkup() # menuItems = menu.showCurrentLayer() # # for item in menuItems: # keyboard.add(types.KeyboardButton(text=item)) # # bot.send_message(message.from_user.id, text="------", reply_markup=keyboard) players[message.from_user.id] = player.player(message.from_user.id, 1500) players[message.from_user.id].computer = computer.computer() if message.from_user.id not in dbAdapter.getUsers(): dbAdapter.addUser( message.from_user.id, "{} {}".format(message.from_user.first_name, message.from_user.last_name)) dbAdapter.addCashDB(players[message.from_user.id].cash, players[message.from_user.id].id) bot.send_message(message.from_user.id, text="Пользователь зарегистрирован!") keyboard = types.ReplyKeyboardMarkup() keyboard.add(types.KeyboardButton(text="➡️")) bot.send_message(message.from_user.id, text="➡️", reply_markup=keyboard) return if message.text == "➡️": if len(players[message.from_user.id].hints) != 0: bot.send_message(message.from_user.id, text=players[message.from_user.id].hints[0]) players[message.from_user.id].hints.pop(0) keyboard = types.ReplyKeyboardMarkup() keyboard.add(types.KeyboardButton(text="➡️")) bot.send_message(message.from_user.id, text="➡️", reply_markup=keyboard) return if message.text in players[message.from_user.id].menu.assortment(): items = players[message.from_user.id].menu.structure["Магазин"][ message.text] for item in items: keyboard = types.InlineKeyboardMarkup() specification = "" for spec in items[item]: specification += spec specification += ": " specification += str(items[item][spec]) specification += "\n" bot.send_message(message.from_user.id, text=item) keyboard.add( types.InlineKeyboardButton( text="Купить", callback_data=message.text + ":" + item + ":" + str(items[item]["Производительность"]))) bot.send_message(message.from_user.id, text=specification, reply_markup=keyboard) return if message.text == "<-Назад": players[message.from_user.id].menu.backToParent() else: players[message.from_user.id].menu.selectMenuItem(message.text) if message.text == "Мой компьютер": #text=dbAdapter.showPC(message.from_user.id) testtext = players[message.from_user.id].computer.toString() try: motherboard = dbAdapter.iNeedMB(message.from_user.id) except: pass for line in testtext.split('\n'): items = line.split(":") try: itemDescription = "Тип: {}, Модель: {}, Цена: {}, Производительность: {}, Активность: {}".format( items[0], items[1], items[2], items[3], items[4]) #bot.send_message(message.from_user.id, text=itemDescription) keyboard = types.InlineKeyboardMarkup(row_width=3) button = types.InlineKeyboardButton(text="Продать", callback_data="sell:" + line) button1 = types.InlineKeyboardButton(text="Извлечь", callback_data="Eject:" + line) button2 = types.InlineKeyboardButton(text="Вставить", callback_data="Inject:" + line) #keyboard.row(types.InlineKeyboardButton(text="Продать", callback_data = "sell:" + line)) # keyboard.row(types.InlineKeyboardButton(text="Извлечь", callback_data = "Eject:" + line)) keyboard.add(button, button1, button2) bot.send_message(message.from_user.id, text=itemDescription, reply_markup=keyboard) except: if testtext.split('\n')[0] == "": bot.send_message(message.from_user.id, text="У вас нет материнки!") elif line == "": bot.send_message( message.from_user.id, text="Это слоты вашей материнки: {}!".format( motherboard)) else: itemDescription = "Тип: {}, Свободен".format(items[0]) bot.send_message(message.from_user.id, text=itemDescription) if message.text == "Мой счет": bot.send_message(message.from_user.id, text=players[message.from_user.id].cash) dbAdapter.addCashDB(players[message.from_user.id].cash, players[message.from_user.id].id) menuItems = players[message.from_user.id].menu.showCurrentLayer() keyboard = types.ReplyKeyboardMarkup() for item in menuItems: keyboard.add(types.KeyboardButton(text=item)) bot.send_message(message.from_user.id, text="------", reply_markup=keyboard)