Exemplo n.º 1
0
 def _config(self):
     """Returns the configuration instance"""
     
     config = self._get(Config, "current_game_id >=", 0)
     
     if config == None:
         config = Config(current_game_id = 1)
         config.put()
         
     return config
Exemplo n.º 2
0
    def write_to_file(self):
        config = Config.get()

        config.properties.update({
            'username': self.usernameEdit.text(),
            'board_width': self.board_width.value(),
            'board_height': self.board_height.value(),
            'rock_count': self.rock_count.value(),
            'diamond_count': self.diamond_count.value()
        })

        config.save()
Exemplo n.º 3
0
    def write_to_file(self):
        config = Config.get()

        config.properties.update({
            'username': self.usernameEdit.text(),
            'board_width': self.board_width.value(),
            'board_height': self.board_height.value(),
            'rock_count': self.rock_count.value(),
            'diamond_count': self.diamond_count.value()
        })

        config.save()
Exemplo n.º 4
0
 def __init__(self, parent, image_repository):
     super(Board, self).__init__(parent)
     self.started = True
     self.paused = False
     self.image_repository = image_repository
     self.config = Config.get()
     self.size = 50
     self.grid = Grid.random(self.config.properties['board_width'], self.config.properties['board_height'],
                             self.config.properties['rock_count'], self.config.properties['diamond_count'])
     self.game_state = GameState(self.grid, self.grid.cells[1][1], self)
     for x in range(self.grid.width):
         for y in range(self.grid.height):
             self.grid.cells[x][y].game_state = self.game_state
     self.initUI()
     self.timer = QtCore.QTimer()
     self.timer.timeout.connect(self.update_game)
     self.timer.start(100)
Exemplo n.º 5
0
 def __init__(self, parent, image_repository):
     super(Board, self).__init__(parent)
     self.started = True
     self.paused = False
     self.image_repository = image_repository
     self.config = Config.get()
     self.size = 50
     self.grid = Grid.random(self.config.properties['board_width'],
                             self.config.properties['board_height'],
                             self.config.properties['rock_count'],
                             self.config.properties['diamond_count'])
     self.game_state = GameState(self.grid, self.grid.cells[1][1], self)
     for x in range(self.grid.width):
         for y in range(self.grid.height):
             self.grid.cells[x][y].game_state = self.game_state
     self.initUI()
     self.timer = QtCore.QTimer()
     self.timer.timeout.connect(self.update_game)
     self.timer.start(100)
Exemplo n.º 6
0
 def write_default_options(self):
     Config.get().destroy()
Exemplo n.º 7
0
 def write_default_options(self):
     Config.get().destroy()
Exemplo n.º 8
0
# test for game.py

from game import State, Config
import numpy as np
import time
import random

# create a new state
state = State(Config())

# print (state.get_actions(True).astype(np.int))
# print (state.get_actions(False).astype(np.int))
print(state.actions_att.astype(np.int))
print(state.actions_def.astype(np.int))

# start_time = time.time()
# cross_product = np.multiply(state.actions_att.astype(np.int), state.actions_def.astype(np.int))
# print ("---calculate scores %s seconds ---" % (time.time() - start_time))

a = (state.size_graph + 1) * (state.size_graph + 1)
b = np.sum(state.actions_att.astype(np.int)) * np.sum(
    state.actions_def.astype(np.int))

print("{} {} {} ".format(a, b, b / a))

print("Testings World")
# test for game.py

import numpy as np
import random
from game import ChainState, Config
import time

# Configuration
config = Config()
config.num_nodes = 25
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})

histogram_options = np.zeros(20, dtype=np.int)
histogram_distance = np.zeros(30, dtype=np.int)
duration_paretos = 0
duration_minimax = 0
distance_paretos = 0
distance_minimax = 0
matches = 0

for i in range(1000):
    # run the experiment
    config.num_nodes = 20
    state = ChainState(config)
    state.generate_graph()
    state.calculate_results()

    # do the pareto calculation
    start_time = time.time()
    paretos_efficient = state.pareto_defense_actions()
    duration_paretos += time.time() - start_time
Exemplo n.º 10
0
# tests for the game module

import time
import numpy as np
from game import Config, State, StateReader
from test_state import TestState
from test_reader import TestStateReader

config = Config()
config.num_service = 4
config.num_viruses = 1
config.num_datadir = 1
config.num_nodes = 5
config.sparcity = 0.1
config.att_points = 100
config.def_points = 100

config.ratios = np.array([3, 3, 2], dtype=np.int)

# Generate a graph
test_case1 = TestState(config)

# Write the state to file
test_case2 = TestStateReader()
# test_case2.write_state(test_case1.state)

# Read the graph
# test_case1.state = test_case2.read_state()
test_case1.print_graph()
print(test_case1.state.graph_edges)