protected void brainWorker() { bool brainActive = true; while (brainActive) { // Get current pos int currY = lab.height - (int)position_y - 1, currX = (int)position_x - lab.x - 1; // Calculate matrix row to get right coord of Q matrix int row = 0; for (int i = 0; i < currY; i++) { row += lab.width - 1; } row += currX; // Select better action to reach the goal int selectedAction; Array actionsArray = Enum.GetValues(typeof(actions)); int[] moreConvenientActions = Q.getMaxValueArrayFromRow(row); if (moreConvenientActions.Length == 0) { selectedAction = random.Next(actionsArray.Length); } else { selectedAction = (int)A.getValue(row, moreConvenientActions[random.Next(0, moreConvenientActions.Length)]); } actions action = (actions)actionsArray.GetValue(selectedAction); GetType().GetMethod(action.ToString()).Invoke(this, null); // Get next pos int nextY = (lab.height - (int)position_y - 1), nextX = (int)position_x - lab.x - 1; // Calculate matrix column to get right coord of Q matrix int column = 0; for (int i = 0; i < nextY; i++) { column += lab.width - 1; } column += nextX; // Angent changed position -> update Q if (currY != nextY || currX != nextX) { // Update Q Q.setValue(row, column, game.getR().getValue(row, column) + learning_rate * Q.getMaxFromRow(column)); // Update A A.setValue(row, column, selectedAction); if (fastLearning && game.getGeneration() <= 250) { Thread.Sleep(3); } else { Thread.Sleep(100); } } // If agent reaches the goal stop brain if (position_x == lab.x + lab.width - 1 && position_y == lab.y + lab.height - 1) { game.newGeneration(); brainActive = false; } } }
private void saveKey(actions actionName, string keyName) { PlayerPrefs.SetString(actionName.ToString(), keyName); }
//********** RUN x BROWSE void doAction(actions action) { try { vsNetServer.log.clear(); adjustFileContext(ref actCtx); if (actCtx == null) return; switch (action) { case actions.xref: break; case actions.browse: progressStart(); try { var html = vsNetServer.getHtmFromTemplate(actCtx); var fn = Path.GetTempPath() + "page.htm"; File.WriteAllText(fn, html, Encoding.UTF8); if (!vsNetServer.log.hasError) navigate(fn, null); } finally { progressEnd(); } break; case actions.saveHtml: vsNetServer.saveHtmlData(actCtx); break; case actions.addEx: new AddExForm(action, actCtx, addExs).ShowDialog(); break; case actions.build: DeployForm.show(actCtx); //using (var str = File.OpenWrite(@"d:\temp\prod.zip")) vsNetServer.build(str, actCtx); break; default: new AddForm(action, actCtx, addFolder).ShowDialog(); break; } } catch (Exception exp) { vsNetServer.log.ErrorLineFmt(action.ToString(), "SolutionToolbarPackage.doAction, {0}", LowUtils.ExceptionToString(exp) ); } if (vsNetServer.log.hasError) { var fn = Path.GetTempPath() + "error.htm"; File.WriteAllText(fn, vsNetServer.log.LogHtml(), Encoding.UTF8); navigate(fn, null); } }
private KeyCode setKey(actions actionName, string keyName) { return((KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString(actionName.ToString(), keyName))); }
void queryAction(object sender, actions action) { try { var cmd = sender as OleMenuCommand; if (cmd == null) return; adjustFileContext(ref actCtx); cmd.Visible = actCtx != null && actCtx.hasAction(action); } catch (Exception exp) { vsNetServer.log.ErrorLineFmt(action.ToString(), "SolutionToolbarPackage.queryAction, {0}", LowUtils.ExceptionToString(exp)); } }