def driver(self): result = [] f = FrontEnd() json_string = f.input_receiver() json_list = list(f.parser(json_string)) for i,read in enumerate(json_list): if len(read) == 19: board = read result.append(self.check_the_score(board)) elif len(read) == 2: stone, move = read[0], read[1] self.stone_checker(stone) if move == "pass": result.append(True) elif isinstance(move,list): point, boards = move[0], move[1] row, col = self.point_parser(point) self.coord_checker(row,col) latest_board = boards[0] occupied = Go_Board(latest_board).is_occupied(row,col) if occupied is True: result.append(False) else: result.append(GoRuleChecker(boards).sixth_resolve_history(stone, row, col)) return json.dumps(result)
def makePlayerMove(self, inputJouer, client): '''Impact the Server's Labi with the player input from his Labi Entry's widget''' nomClient = self.ClientsDico[client] mvt = FE.nextMvt(inputJouer) if mvt is not False: FE.move(self.Labi, nomClient, mvt) self.send_labiStr_to_allClients() if len(list(self.ClientsDico.keys())) > 1: self.send_Turn_to_ActivePlayer() self.nextPlayerTurn() self.send_Turn_to_ActivePlayer() if self.Labi.getPlayerPos( self.ClientsDico[client]) == self.Labi.Exit: self.send_Turn_to_ActivePlayer() self.sendWinnerMsg(client)
def driver(self): output_list = [] input = FrontEnd().getJson() for i,json_data in enumerate(input): output = self.send_and_receive(json_data) if output and output != "GO has gone crazy!": output_list.append(output) elif output == "GO has gone crazy!": output_list.append(output) self.conn.close() return json.dumps(output_list) self.conn.close() return json.dumps(output_list)
def __init__(self, mazeName): # creating a RunningLabiServer instance starts the Thread-Server, we never starts it manually self.Begun = False self.EndOfGame = False Thread.__init__(self) self.server = Server() self.ActivePlayer = "" #contains the client socket of the active player (the player who can play his turn) self.Connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.Connexion.bind((self.Host, self.Port)) self.Connexion.listen(5) print("Server started") print("Please do NOT close this window") self._labi = FE.labi(mazeName) self.start()
def fetch_config(self): json_string = FrontEnd().input_receiver('go.config') python_obj = json.loads(json_string) return python_obj["IP"], python_obj["port"], python_obj["default-player"]
def __init__ (self): self.device_parameter_defaults = { # Device defaults. 'comms_baud_rate': 57600, 'timing_info_flag' : 0, 'time_step' : 0.2, # Simulation defaults. 'simulation_number_of_channels': 1, 'simulation_peltier_power_ratio': 8.0, 'simulation_hsk_temp_variation_active': False, 'simulation_hsk_temp_variation_amplitude': 0.5, 'simulation_hsk_temp_variation_period': 40.0, 'simulation_display_hsk_temp': False, # Channel defaults. # Logging 'stop_logging_at_profile_end_flag' : [1, 1, 1, 1], 'start_logging_at_profile_start_flag' : [1, 1, 1, 1], 'logging_rate' : [1, 5, 5, 5], # Plotting 'enable_plotting_flag' : [1, 0, 0, 0], 'plot_update_rate' : [5, 5, 5, 5], 'plot_span' : [2000, 2000, 2000, 2000], # Video 'webcam_image_file_format': '.jpg', 'webcam_available_dimensions' : ["320x240", "640x480", "800x600", "1280x720"], 'webcam_default_dimensions': ["640x480", "320x240", "320x240", "320x240"], 'log_video_split_flag' : [0, 0, 0, 0], # Control 'drive_mode' : [2, 2, 2, 2], 'default_pid_coefficients': [{'P' : 0.0, 'I': 0.0, 'D': 0.0, 'power_multiplier': 1.0}, {'P' : 0.0, 'I': 0.0, 'D': 0.0, 'power_multiplier': 1.0}, {'P' : 0.0, 'I': 0.0, 'D': 0.0, 'power_multiplier': 1.0}, {'P' : 0.0, 'I': 0.0, 'D': 0.0, 'power_multiplier': 1.0}], 'user_pid_coefficients_filepath': ['./calibrations/*/channel_' + str(i) + '/user_pid_coefficients.csv' for i in range(4)], 'max_temperature_limit': [30.0, 30.0, 30.0, 30.0], 'min_temperature_limit': [-45.0, -45.0, -45.0, -45.0], 'overload_fault_threshold_seconds': 10.0, # Calibration: 'tc_calibration_time_step': 0.2, 'tc_calibration_logging_rate': 5, 'auto_range_max_throttle': 100.0, 'auto_range_min_cooling_rate_per_min': -1.0, 'calibration_fit_polynomial_order': 7, 'auto_calibration_temperature_steps': 10, 'prt_calibration_coeffs_filepath' : ['./calibrations/*/channel_' + str(i) + '/prt_calibration_coeffs.csv' for i in range(4)], 'tc_calibration_temp_data_filepath': ['./calibrations/*/channel_' + str(i) + '/tc_calibration_log_data_TEMP.csv' for i in range(4)], 'tc_calibration_final_data_filepath': ['./calibrations/*/channel_' + str(i) + '/tc_calibration_log_data.csv' for i in range(4)], 'tc_calibration_coeffs_filepath' : ['./calibrations/*/channel_' + str(i) + '/tc_calibration_coeffs.csv' for i in range(4)], 'calibrated_temp_limits_filepath': ['./calibrations/*/channel_' + str(i) + '/calibrated_temp_limits.csv' for i in range(4)], # Ramping 'path_to_ramp_profile' : ["./ramp_profile.csv" for i in range(4)], 'ramp_repeats' : [1, 1, 1, 1] } self.start_up_config = StartUpConfig.StartUpConfig(self.device_parameter_defaults) self.action = self.start_up_config.action.get() if self.action == 'start': self.comms_baud = self.device_parameter_defaults['comms_baud_rate'] self.comms_unique_id = self.start_up_config.device_unique_id.get() self.comms_port = self.start_up_config.device_port.get() self.num_channels = self.start_up_config.device_number_of_channels.get() self.video_device_id = [int(self.start_up_config.camera_id.get()), 0, 0, 0] self.video_enabled = [not bool(self.start_up_config.video_disabled_flag.get()), 0, 0, 0] self.timing_flag = self.device_parameter_defaults['timing_info_flag'] self.time_step = self.device_parameter_defaults['time_step'] self.plotting_enabled = self.device_parameter_defaults['enable_plotting_flag'] self.drive_mode = self.device_parameter_defaults['drive_mode'] if self.num_channels < 1: self.num_channels = 1 elif self.num_channels > 4: self.num_channels = 4 # Replace wildcards (*) in the default paths with unique device identifier. self.device_parameter_defaults['prt_calibration_coeffs_filepath'] = [self.device_parameter_defaults['prt_calibration_coeffs_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['prt_calibration_coeffs_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.device_parameter_defaults['tc_calibration_temp_data_filepath'] = [self.device_parameter_defaults['tc_calibration_temp_data_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['tc_calibration_temp_data_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.device_parameter_defaults['tc_calibration_final_data_filepath'] = [self.device_parameter_defaults['tc_calibration_final_data_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['tc_calibration_final_data_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.device_parameter_defaults['tc_calibration_coeffs_filepath'] = [self.device_parameter_defaults['tc_calibration_coeffs_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['tc_calibration_coeffs_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.device_parameter_defaults['calibrated_temp_limits_filepath'] = [self.device_parameter_defaults['calibrated_temp_limits_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['calibrated_temp_limits_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.device_parameter_defaults['user_pid_coefficients_filepath'] = [self.device_parameter_defaults['user_pid_coefficients_filepath'][i].split('*')[0] + str(self.comms_unique_id) + self.device_parameter_defaults['user_pid_coefficients_filepath'][i].split('*')[1] for i in range(self.num_channels)] self.simulation_flag = (self.comms_port == 'none') # Create a root tkinter window, and then hide it. self.root_tk = tk.Tk() self.root_tk.withdraw() # Warn user if calibration files absent. self.CheckCalibrationFiles(self.num_channels, self.comms_unique_id) # Data queues. self.mq_front_to_back = [Queue() for i in range(self.num_channels)] self.mq_back_to_front = [Queue() for i in range(self.num_channels)] self.mq_back_to_vlogger = [Queue() if self.video_enabled[i] == True else None for i in range(self.num_channels)] # Image queue(s). self.mq_vlogger_to_front = [Queue() if self.video_enabled[i] == True else None for i in range(self.num_channels)] # Video fault multiprocessing event. self.event_vlogger_fault = [Event() if self.video_enabled[i] == True else None for i in range(self.num_channels)] # Calibration logging trigger multiprocessing event. self.event_back_to_front = [{'calibration_zeroed_flag': Event(), 'gradient_detect_flag': Event(), 'ramp_running_flag': Event()} for i in range(self.num_channels)] # Timestamp queue. self.InitialiseTimingMonitors(self.timing_flag) # Spawn required video handler processes. self.process_vlogger = [Process(target = VideoHandler.VideoHandler, args = (i, self.simulation_flag, self.device_parameter_defaults, self.mq_back_to_vlogger[i], self.mq_vlogger_to_front[i], self.mq_timestamp[i], self.event_vlogger_fault[i], self.timing_flag, self.video_device_id[i])) for i in range(self.num_channels) if self.video_enabled[i] == True] for current_vlogger in self.process_vlogger: current_vlogger.start() # Create instance(s) of the front end object and create a Tkinter variable that it can set when it/they close(s). # These will be polled to determine when all front end windows are closed so we can end the root window mainloop(). self.close_action = [tk.StringVar(self.root_tk) for i in range(self.num_channels)] self.front_ends = [FrontEnd.FrontEnd(self, self.root_tk, self.device_parameter_defaults, self.num_channels, i, self.comms_unique_id, self.close_action[i], self.mq_front_to_back[i], self.mq_back_to_front[i], self.mq_vlogger_to_front[i], self.event_back_to_front[i], self.timing_flag, self.timing_monitor[i], self.timing_monitor_kill[i], self.mq_timestamp[i], self.time_step, self.video_enabled[i], self.plotting_enabled[i]) for i in range(self.num_channels)] # Setup a process to run the back end. Pass Queue()s, Event()s etc to allow inter-process communication. self.process_back_end = Process(target = BackEnd.BackEnd, args = (self.device_parameter_defaults, self.num_channels, self.mq_front_to_back, self.mq_back_to_front, self.mq_back_to_vlogger, self.mq_timestamp, self.event_vlogger_fault, self.event_back_to_front, self.video_enabled, self.comms_unique_id, self.time_step, self.timing_flag, self.drive_mode)) self.process_back_end.start() # First call of the function that polls to check if all front end windows have been closed, then spin the root # Tkinter window mainloop() to generate and begin servicing the GUI elements. self.ClosePoll() self.root_tk.mainloop() # That's it, we're live folks! # When the user exits and the tkinter mainloop quits, having sent the appropriate shutdown command # to the back end, we wait for it and the video handler to complete, rejoin them, and finish. for current_vlogger in self.process_vlogger: current_vlogger.join() self.process_back_end.join() print('Application closed.') else: print('Application closed.')
elif command_or_query[0] == "place": return board_obj.place(command_or_query[1], row, col) elif command_or_query[0] == "remove": return board_obj.remove(command_or_query[1], row, col) elif command_or_query[0] == "get-points": return board_obj.get_points(command_or_query[1]) def question(self, list_of_list): result = [] for index, el_list in enumerate(list_of_list): board = el_list[0] command_or_query = el_list[1] if command_or_query[0] not in ("occupied?", "occupies?", "reachable?", "place", "remove", "get-points"): raise TypeError("Please type valid query or command") row, col = self.extract_coordinate(board, command_or_query) result.append( self.answer_command_query(board, command_or_query, row, col)) return json.dumps(result) if __name__ == '__main__': f = FrontEnd() json_string = f.input_receiver() json_list = list(f.parser(json_string)) go_board = Go_Board() print(go_board.question(json_list))
from FrontEnd import * from DPLL import * from BackEnd import * FrontEnd('Sample.txt', 'Input For DPLL.txt', 'Table.txt') dp('Input For DPLL.txt', 'Input For Backend.txt') Input = 'Input For Backend.txt' Table = 'Table.txt' backend(Input, Table)