def test_fire(self): repoGame = Repo() validate = Validate() controller = Controller(repoGame, validate) with self.assertRaises(ValidError): controller.fire('J1') with self.assertRaises(ValidError): controller.fire('A9') with self.assertRaises(ValidError): controller.fire('J9') self.assertEqual(controller.fire('A1'), False) repoGame.addAlien((1,2)) repoGame.mark_table(1, 2, 'X') self.assertEqual(controller.fire('B1'), True) repoGame.addAlien((1,3)) repoGame.mark_table(1, 3, '') self.assertEqual(controller.fire('C1'), True) self.assertEqual(repoGame.getAliens(), 0) self.assertEqual(repoGame.getTable[1][2], '-') self.assertEqual(repoGame.getAliens(), 0) self.assertEqual(repoGame.getTable[1][3], '-')
from Ui import Console from Controller import Controller from Repository import Repo from Validators import Validate repoGame = Repo() validate = Validate() controller = Controller(repoGame, validate) console = Console(controller) console.run()
# -*- coding: utf-8 -*- """ Created on Tue Apr 7 12:27:10 2020 @author: Bogdan """ ''' Decision Tree ''' from Repository import Repo from Controller import Controller import sys r = Repo('balance-scale.data') c = Controller(r) nrTests = 30 minv = sys.maxsize maxv = 0 sumv = 0 for i in range(nrTests): r.loadFromFile(0.8) c.train() val = c.test() sumv += val if val > maxv: maxv = val
def logoutService(self, username): Repo().logoutServiceRepo(username)
def getOnlineUsersService(self): return Repo().getOnlineUsersRepo()
def loginService(self, userName, password): return Repo().loginRepo(userName, password)
from Repository import Repo from Controller import Controller r = Repo("data.txt") c = Controller(r) nrTests = 5 sumTests = 0 for i in range(nrTests): r.loadFromFile(.8) c.startTraining(200) s = 0 for t in r.testData: res = c.test(t) s += abs(res - t.res) # print average error for this test average = s / len(r.testData) print("Test", i + 1, "average error: %.5f" % average) # add test average to global sum sumTests += average print("\nOverall average error: %.5f" % (sumTests / nrTests)) # beta 0 e de fapt ultimul print(c.beta)
def __init__(self): self._repo = Repo()
class Service: def __init__(self): self._repo = Repo() def init_repo(self): self._repo.read_file(path="questions.txt") def add(self, ID, question, choiceA, choiceB, choiceC, correct_choice, difficulty): q = Quiz(ID, question, choiceA, choiceB, choiceC, correct_choice, difficulty) self._repo.add(q) def create(self, difficulty, no_question, file_name): """ Creates a new quiz. :return: """ no_of_diff = [] for x in self._repo.data: if x.difficulty == difficulty and int(no_question) > len( no_of_diff): no_of_diff.append(x) if len(no_of_diff) < int(no_question) // 2: raise Exception("Not enough " + difficulty + " questions!") else: i = 0 while len(no_of_diff) < int(no_question): if not self._repo.data[i] in no_of_diff: no_of_diff.append(self._repo.data[i]) i += 1 self.write_file(no_of_diff, file_name) @staticmethod def write_file(data, path): file = open(path, "w") string = "" for obj in data: string += str(obj) + "\n" file.write(string) file.close() @staticmethod def read_file(data, path): # this can crash file = open(path, "r") l = file.readlines() for line in l: line = line.split(";") obj = Quiz(line[0], line[1], line[2], line[3], line[4], line[5], line[6]) data.append(obj) file.close() def sort_memo(self, mem): pass def start(self, path): memory = [] self.read_file(memory, path) score = 0 for x in memory: if x.difficulty == "easy": print(x.question) print(x.choiceA) print(x.choiceB) print(x.choiceC) choice = input(">") if choice == x.correct_choice: # still nice score += 1
for j in range(n - 1): s = s + d[int(rute_opt[i, j]) - 1, int(rute_opt[i, j + 1]) - 1] # dist_cost[i] = s dist_min_loc = np.argmin(dist_cost) dist_min_cost = dist_cost[dist_min_loc] best_route = rute[dist_min_loc, :] pheromne = (1 - e) * pheromne for i in range(m): for j in range(n - 1): dt = 1 / dist_cost[i] pheromne[int(rute_opt[i, j]) - 1, int(rute_opt[i, j + 1]) - 1] = pheromne[int(rute_opt[i, j]) - 1, int(rute_opt[i, j + 1]) - 1] + dt print('route of all the ants at the end :') print(rute_opt) print() print('best path :', best_route) print('cost of the best path', int(dist_min_cost[0]) + d[int(best_route[-2]) - 1, 0]) repo = Repo() service = Service(repo) service.lab5()
def registerService(self, registerUserName, registerEmail, registerPassword, registerTopic): if (Repo().registerRepo(registerUserName, registerEmail, registerPassword, registerTopic)): return True
from Ui import Console from Controller import PlayerController, ComputerController from Validators import Validate from Repository import Repo validate = Validate() repoPoints = Repo() repoCPoints = Repo() playerController = PlayerController(validate, repoPoints) computerController = ComputerController(validate, repoCPoints) console = Console(playerController, computerController) console.run()