Exemplo n.º 1
0
 public override QState GetNewState(QAction action)
 {
     return(new Count()
     {
         start = this.start, end = this.end, value = (action == UP? this.value + this.upIncrement:this.value - this.downIncrement), upIncrement = this.upIncrement, downIncrement = this.downIncrement
     });
 }
Exemplo n.º 2
0
        public override QState GetNewState(QAction action)
        {
            int newX = self.X, newY = self.Y;

            // Translate decision to new coordinate
            if (action == UP)
            {
                newY--;
            }
            else if (action == DOWN)
            {
                newY++;
            }
            else if (action == LEFT)
            {
                newX--;
            }
            else if (action == RIGHT)
            {
                newX++;
            }

            // Cannot go there
            if (newY < 0 || newX < 0 || newY >= height || newX >= width)
            {
                newX = self.X;
                newY = self.Y;
            }

            // Pass all variables to new state
            return(new Maze_With_No_Walls()
            {
                maze = maze, self = new Point(newX, newY), goal = goal, goalx = goalx, goaly = goaly, time = time + 1, width = width, height = height, score = score
            });
        }
Exemplo n.º 3
0
 // Features - aka characteristics - associated with a decision (state-action) and their values.  Used to determine similarity between different state-action pairs.  These should be estimated from a prior state.
 // Leave empty to not use and QLearner will judge each state independently with Equals.
 // Tip: Feature values should be defined as 1 or 0 (on/off) or try to normalize the value out of 1 as opposed to using infinite domain.
 public override Dictionary <QFeature, decimal> GetFeatures(QAction action)
 {
     { return(new Dictionary <QFeature, decimal>()
         {
             { new QFeature_String(ToString()), 1 }
         }); }
 }
Exemplo n.º 4
0
        public override QState GetNewState(QAction action = null)
        {
            if (action.ToString() != "")
            {
                string[] point  = action.ToString().Split(',');
                Point    newPos = new Point(Convert.ToInt32(point[0]), Convert.ToInt32(point[1]));

                List <Point> newSpaces = openSpaces.ToList();
                newSpaces.Remove(newPos);

                List <Point> newMoves = myMoves.ToList();
                newMoves.Add(newPos);

                TicTacToe newState = new TicTacToe()
                {
                    myMoves = newMoves, yourMoves = yourMoves.ToList(), me = me, you = you, random = random, gui = gui, openSpaces = newSpaces, score = score
                };

                // Pass all variables to new state
                return(newState);
            }
            else
            {
                return(this);
            }
        }
Exemplo n.º 5
0
 public override QState GetNewState(QAction action)
 {
     return(new Count_To_100()
     {
         value = (action == UP ? this.value + this.upIncrement : this.value - this.downIncrement), upIncrement = this.upIncrement, downIncrement = this.downIncrement
     });
 }
Exemplo n.º 6
0
        private static void InitFileMenu(QMenu rootMenu)
        {
            rootMenu.AddAction(MediaIconHelper.NewDocumentIcon, "New File");
            rootMenu.AddAction(MediaIconHelper.OpenDocumentIcon, "Open File");

            // create new Import sub menu
            //var importMenu = new QMenu("Import");
            var importMenu = rootMenu.AddMenu(MediaIconHelper.OpenDocumentIcon, "&Import");

            // add actions to menu
            importMenu.AddAction(new QAction("Import news feed...", null));
            importMenu.AddAction(new QAction("Import bookmarks...", null));
            importMenu.AddAction(new QAction("Import mail...", null));

            // add Import to main menu
            rootMenu.AddMenu(importMenu);

            // Add separator line
            rootMenu.AddSeparator();

            // create sub menu
            var quit = new QAction(MediaIconHelper.SystemLogOugIcon, "&Quit", rootMenu);

            // add it to main menu

            rootMenu.AddAction(quit);

            // Menus are displayed in created order
            quit.Triggered += Quit_Triggered;
        }
Exemplo n.º 7
0
 // Features - aka characteristics - associated with a decision (state-action) and their values.  Used to determine similarity between different state-action pairs.  These should be estimated from a prior state.
 // Leave empty to not use and QLearner will judge each state independently with Equals.
 // Tip: Feature values should be defined as 1 or 0 (on/off) or try to normalize the value out of 1 as opposed to using infinite domain.
 public virtual Dictionary <QFeature, decimal> GetFeatures(QAction action)
 {
     { return(new Dictionary <QFeature, decimal>()
         {
             { new QFeature_StateAction(new QStateActionPair(this, action)), 1 }
         }); }
 }
Exemplo n.º 8
0
        void HandleFormatMenuActionTriggered(QAction action)
        {
            var cursor = textEdit.TextCursor();

            QTextCharFormat fmt = new QTextCharFormat();

            if (action == m_ClearFormattingAction)
            {
                cursor.SetCharFormat(fmt);
                textEdit.SetCurrentCharFormat(fmt);
                return;
            }

            if (action == m_BoldAction)
            {
                fmt.SetFontWeight(action.Checked ? (int)QFont.Weight.Bold : (int)QFont.Weight.Normal);
            }
            else if (action == m_ItalicAction)
            {
                fmt.SetFontItalic(action.Checked);
            }
            else if (action == m_UnderlineAction)
            {
                fmt.SetFontUnderline(action.Checked);
            }
            else if (action == m_StrikethroughAction)
            {
                fmt.SetFontStrikeOut(action.Checked);
            }

            cursor.MergeCharFormat(fmt);
            textEdit.MergeCurrentCharFormat(fmt);
        }
Exemplo n.º 9
0
        public override void InitUI()
        {
            // var mediaPath = @"media\icons";

            // load icons
            // NOTE : all icons in project should have "Copy to Output Directory" set to Copy...;

            //var filepix = new QIcon($@"{mediaPath}\preferences-system.png");
            //var importpix = new QIcon($@"{mediaPath}\package-x-generic.png");

            // Create main menu
            var menuToolbar = new QMenuBar(this);
            var file        = menuToolbar.AddMenu("&File");

            file.AddAction(MediaIconHelper.NewDocumentIcon, "New File");
            file.AddAction(MediaIconHelper.OpenDocumentIcon, "Open File");

            // create new Import sub menu
            //var importMenu = new QMenu("Import");
            var importMenu = file.AddMenu(MediaIconHelper.OpenDocumentIcon, "&Import");

            importMenu.AddAction(new QAction("Import news feed...", null));
            importMenu.AddAction(new QAction("Import bookmarks...", null));
            importMenu.AddAction(new QAction("Import mail...", null));

            // create sub menu
            var quit = new QAction(MediaIconHelper.SystemLogOugIcon, "&Quit", null);

            // add it to main menu
            file.AddAction(quit);

            // Menus are displayed in created order
            quit.Triggered += Quit_Triggered;
        }
Exemplo n.º 10
0
        public MainWindow()
        {
            QAction quit = new QAction("&Quit", this);
            quit.triggered.connect(QApplication.instance(), "quit()");
            QAction open = new QAction("&Open", this);
            open.triggered.connect(this, "open()");

            QMenu file = menuBar().addMenu("&File");
            file.addAction(open);
            file.addAction(quit);

            treeView = new QTreeView();
            listView = new QTreeView();
            listView.setUniformRowHeights(true);
            listView.setRootIsDecorated(false);
            listView.setAllColumnsShowFocus(true);

            QDockWidget dockWidget = new QDockWidget("Tree");
            dockWidget.setWidget(treeView);
            addDockWidget(com.trolltech.qt.core.Qt.DockWidgetArea.TopDockWidgetArea, dockWidget);

            QDockWidget listDockWidget = new QDockWidget("List View");
            listDockWidget.setWidget(listView);
            addDockWidget(com.trolltech.qt.core.Qt.DockWidgetArea.TopDockWidgetArea, listDockWidget);

            treeMap = new TreeMapWidget();
            setCentralWidget(treeMap);
        }
Exemplo n.º 11
0
        protected virtual void QUpdate(int n, QState currentState, QAction action, QState newState, decimal reward)
        {
            QStateActionPair p    = new QStateActionPair(currentState, action);
            decimal          maxQ = GetMaxValue(newState);

            QValues[p] = (1 - learn) * GetQValue(p) + learn * (reward + discount * maxQ);
            UpdateLearningTable(n, currentState, action, QValues[p]);
        }
Exemplo n.º 12
0
        void HandleCategoryAdded(string category)
        {
            QAction action = new QAction(category, m_FeedFilterMenu);

            action.Checkable = true;
            action.Checked   = true;
            m_FeedFilterMenu.AddAction(action);
        }
Exemplo n.º 13
0
        public void ActionChangeReader()
        {
            QAction sender    = (QAction)Sender();
            string  newReader = sender.Text;

            log.Info("ActionChangeReader " + newReader);
            UpdateSelectedReader(newReader);
        }
Exemplo n.º 14
0
        void HandleNewTab(QAction action)
        {
            var tab   = new EmptyTab();
            int index = m_Tabs.CurrentIndex + 1;

            index = m_Tabs.InsertTab(index, tab, tab.WindowIcon, "New Tab");
            m_Tabs.SetCurrentIndex(index);

            TabAdded();
        }
Exemplo n.º 15
0
        public override void InitUI()
        {
            var toolbar = new QToolBar(this);

            toolbar.AddAction(MediaIconHelper.NewDocumentIcon, "New File");
            toolbar.AddAction(MediaIconHelper.OpenDocumentIcon, "Open File");
            toolbar.AddSeparator();
            QAction quit = toolbar.AddAction(MediaIconHelper.SystemLogOugIcon, "Quit Application");

            quit.Triggered += Quit_Triggered;
        }
Exemplo n.º 16
0
        private void InitUI(QToolBar toolbar, Dictionary <string, QAction> actions)
        {
            toolbar.AddAction(MediaIconHelper.NewDocumentIcon, "New File");
            toolbar.AddAction(MediaIconHelper.OpenDocumentIcon, "Open File");
            toolbar.AddSeparator();
            toolbar.AddAction(actions["About"]);

            QAction quit = toolbar.AddAction(MediaIconHelper.SystemLogOugIcon, "Quit Application");

            quit.Triggered += Quit_Triggered;
        }
Exemplo n.º 17
0
 void HandlePresenceMenuTriggered(QAction action)
 {
     if (action.Text != "Offline")
     {
         m_Account.Status = new ClientStatus(action.Text, String.Empty);
     }
     else
     {
         m_Account.Status = null;
     }
 }
Exemplo n.º 18
0
 void HandleToolbarActionTriggered(QAction action)
 {
     if (action == m_GoAction)
     {
         RequestUrl(new Uri(m_AddresCombo.LineEdit().Text));
     }
     else if (action == m_HomeAction)
     {
         RequestUrl(m_HomeUri);
     }
 }
Exemplo n.º 19
0
 public override Dictionary<QFeature, decimal> GetFeatures(QAction action)
 {
     int newVal = value;
     if (action == UP) newVal++;
     else newVal--;
     return QFeature_String.FromStringDecimalDictionary(new Dictionary<string, decimal>() {
         //{value.ToString()+"_"+action, 1}, // Identity for sanity check
         //{"Distance", (decimal)Math.Abs(end-newVal)}
         {"Distance_Change", Math.Abs(end-newVal)-Math.Abs(end-value)}
     });
 }
Exemplo n.º 20
0
        void HandleCloseTab(QAction action)
        {
            int index  = m_Tabs.CurrentIndex;
            var widget = m_Tabs.CurrentWidget();

            widget.Close();
            if (widget is EmptyTab)
            {
                m_Tabs.RemoveTab(index);
                TabClosed();
            }
        }
Exemplo n.º 21
0
 // This runs a single trial/instance of the QState problem.  QLearner will automatically run many times for learning or once to apply what has been learned.
 // Must return the final state
 public override QState Run(QState currentState, int trialNum, decimal learn, decimal discount, decimal explore)
 {
     while (!currentState.IsEnd() && currentState.GetActions().Length > 0 && isRunning)
     {
         QAction action   = currentState.GetActions().ElementAt(r.Next(currentState.GetActions().Length));
         QState  newState = currentState.GetNewState(action);
         newState.Inherit(currentState);
         newState.Step();
         WriteOutput((CurrentMode == LEARN ? "Trial " + trialNum + ", " : "") + ": '" + action + "' @ " + currentState.ToString());
         currentState = newState;
     }
     return(currentState);
 }
Exemplo n.º 22
0
        public void ActionAddContact()
        {
            QAction sender = (QAction)Sender();

            if (sender.ObjectName == "fileadd")
            {
                PopupFileAdd();
            }
            else if (sender.ObjectName == "simadd")
            {
                PopupSimAdd();
            }
        }
Exemplo n.º 23
0
        public void ActionDelContact()
        {
            QAction sender = (QAction)Sender();

            if (sender.ObjectName == "filedel")
            {
                PopupFileDel();
            }
            else if (sender.ObjectName == "simdel")
            {
                PopupSimDel();
            }
        }
Exemplo n.º 24
0
        public void ActionCopyContact()
        {
            QAction sender = (QAction)Sender();

            if (sender.ObjectName == "filecopy")
            {
                PopupFileMoveToSim();
            }
            else if (sender.ObjectName == "simcopy")
            {
                PopupSimMoveToFile();
            }
        }
Exemplo n.º 25
0
        // Update the weights of each feature based on their contribution to the reward
        protected override void QUpdate(int n, QState currentState, QAction action, QState newState, decimal reward)
        {
            decimal          maxQ = GetMaxValue(newState);
            QStateActionPair p    = new QStateActionPair(currentState, action);
            Dictionary <QFeature, decimal> features;

            if (featureCache.ContainsKey(p))
            {
                features = featureCache[p];
            }
            else
            {
                features        = currentState.GetFeatures(action);
                featureCache[p] = features;
            }
            decimal currentQ   = GetQValue(p);
            decimal difference = reward + discount * maxQ - currentQ;

            foreach (KeyValuePair <QFeature, decimal> feature in features)
            {
                try
                {
                    if (!QWeights.ContainsKey(feature.Key))
                    {
                        QWeights[feature.Key] = 0;
                    }
                    decimal oldWeight = QWeights[feature.Key];
                    decimal newWeight = oldWeight + learn * difference * feature.Value;
                    if (Math.Abs(newWeight) <= 1000000)
                    {
                        QWeights[feature.Key] = newWeight;
                    }
                    else
                    {
                        WriteOutput("Warning: Weights diverging. Check that your features are valid and measured consistently with everything else.", true);
                    }
                }
                catch (Exception e)
                {
                    WriteOutput("Exception: " + e + "\n*Check that your features are valid and measured consistently with everything else.*", true);
                    Abort();
                    break;
                }
            }

            // Output
            foreach (QFeature f in features.Keys)
            {
                UpdateLearningTable(-1, f.ToString(), QWeights[f].ToString(), features[f]);
            }
        }
Exemplo n.º 26
0
        private QAction GetAboutActions(MainWindow mainWindow)
        {
            var aboutAction = new QAction(media.MediaIconHelper.InformationIcon, "&About", null);

            //aboutAction.SetShortcuts(QKeySequence.Open);
            aboutAction.StatusTip  = "Show about dialog";
            aboutAction.Triggered += AboutAction_Triggered;

            //aboutAction(openAct, SIGNAL(triggered()), this, SLOT(open()));

            //fileMenu->addAction(openAct);
            //fileToolBar->addAction(openAct);
            return(aboutAction);
        }
Exemplo n.º 27
0
        public double Query(QState s, QAction a)
        {
            if (!_table.ContainsKey(s))
            {
                return(defr);
            }
            var qa = _table[s];

            if (!qa.ContainsKey(a))
            {
                return(defr);
            }
            return(qa[a]);
        }
Exemplo n.º 28
0
        void HandleRosterMenuTriggered(QAction action)
        {
            var settingsService = ServiceManager.Get <SettingsService>();

            if (action == m_ShowOfflineAction)
            {
                m_RosterModel.ShowOffline = action.Checked;
                settingsService.Set("RosterShowOffline", m_RosterModel.ShowOffline);
            }
            else if (action == m_ShowTransportsAction)
            {
                m_RosterModel.ShowTransports = action.Checked;
                settingsService.Set("RosterShowTransports", m_RosterModel.ShowTransports);
            }
        }
Exemplo n.º 29
0
    public override void OnActionTaken(QAgent agent, QAction action, QState state)
    {
        var car = (SlotCar)agent;

        if (!car.OnTrack && !_isCrashing)
        {
            _isCrashing = true;
            _crashes++;
        }
        else if (car.OnTrack && _isCrashing)
        {
            _isCrashing = false;
        }
        _maxDist = car.DistanceTravelled - car.StartPosition;
    }
Exemplo n.º 30
0
        public void Add(QState s, QAction a, double v)
        {
            SerializableDictionary <QAction, double> qa;

            if (!_table.ContainsKey(s))
            {
                qa = new SerializableDictionary <QAction, double>();
                _table.Add(s, qa);
            }
            else
            {
                qa = _table[s];
            }
            qa[a] = v;
        }
Exemplo n.º 31
0
        public override QState Run(QState currentState, int trialNum, decimal learn, decimal discount, decimal explore)
        {
            this.learn = learn; this.discount = discount; this.explore = explore;
            decimal score        = 0;
            int     actionsTaken = 0;

            while (!currentState.IsEnd() && GetOutcomes(currentState).Count > 0 && isRunning)
            {
                actionsTaken++;
                QAction a;
                bool    exp;
                if (explore > 0 && (decimal)random.NextDouble() <= explore)
                {
                    a   = GetRandomAction(currentState);
                    exp = true;
                }
                else
                {
                    a   = GetBestAction(currentState);
                    exp = false;
                }
                QState newState = currentState.GetNewState(a);
                WriteOutput((CurrentMode == LEARN ? "Trial " + trialNum + ", " : "") + "#" + actionsTaken + " " + (exp ? "Explore" : "Action") + ": '" + a + "' @ " + currentState.ToString());
                newState.Inherit(currentState);
                newState.Step();
                decimal r = GetReward(currentState, newState);
                score += r;
                QUpdate(actionsTaken, currentState, a, newState, r);
                WriteOutput((CurrentMode == LEARN ? "Trial " + trialNum + ", " : "") + "#" + actionsTaken + " Gain " + Math.Round(r, 4) + ",  Total " + Math.Round(score, 4));

                foreach (KeyValuePair <QStateActionPair, QState> kv in newState.GetObservedStates(currentState, a))
                {
                    QState  observedPriorState = kv.Key.state;
                    QAction observedAction     = kv.Key.action;
                    QState  observedState      = kv.Value;
                    decimal observedR          = GetReward(observedPriorState, observedState);
                    QUpdate(actionsTaken, observedPriorState, observedAction, observedState, observedR);
                    WriteOutput((CurrentMode == LEARN ? "Trial " + trialNum + ", " : "") + "#" + actionsTaken + " Observed: '" + observedAction + "' @ " + observedPriorState.ToString() + " | Gain " + Math.Round(observedR, 4));
                }

                currentState = newState;
            }
            if (isRunning)
            {
                WriteOutput("Trial " + trialNum + ": " + Math.Round(score, 4) + " in " + actionsTaken + " step" + (actionsTaken == 1 ? "" : "s") + ".");
            }
            return(currentState);
        }
Exemplo n.º 32
0
        void RosterViewActionGroupTriggered(QAction action)
        {
            if (action == m_ListModeAction)
            {
                rosterGrid.ListMode   = action.Checked;
                rosterViewButton.icon = new QIcon(new QPixmap("resource:/view-list.png"));
            }
            else if (action == m_GridModeAction)
            {
                rosterGrid.ListMode   = !action.Checked;
                rosterViewButton.icon = new QIcon(new QPixmap("resource:/view-grid.png"));
            }
            var settingsService = ServiceManager.Get <SettingsService>();

            settingsService.Set("RosterListMode", m_ListModeAction.Checked);
        }
Exemplo n.º 33
0
        public override QState GetNewState(QAction action)
        {

            int newX = self.X, newY = self.Y;

            // Translate decision to new coordinate
            if (action == UP) newY--;
            else if (action == DOWN) newY++;
            else if (action == LEFT) newX--;
            else if (action == RIGHT) newX++;

            // Cannot go there
            if (newY < 0 || newX < 0 || newY >= height || newX >= width)
            {
                newX = self.X;
                newY = self.Y;
            }

            // Pass all variables to new state
            return new Maze_With_No_Walls() { maze = maze, self = new Point(newX, newY), goal = goal, goalx = goalx, goaly = goaly, time = time + 1, width = width, height = height, score = score};
        }
Exemplo n.º 34
0
 // Update the weights of each feature based on their contribution to the reward
 protected override void QUpdate(int n, QState currentState, QAction action, QState newState, decimal reward)
 {
     decimal maxQ = GetMaxValue(newState);
     QStateActionPair p = new QStateActionPair(currentState, action);
     Dictionary<QFeature, decimal> features;
     if (featureCache.ContainsKey(p)) features = featureCache[p];
     else
     {
         features = currentState.GetFeatures(action);
         featureCache[p] = features;
     }
     decimal currentQ = GetQValue(p);
     decimal difference = reward + discount * maxQ - currentQ;
     foreach (KeyValuePair<QFeature, decimal> feature in features)
     {
         try
         {
             if (!QWeights.ContainsKey(feature.Key)) QWeights[feature.Key] = 0;
             decimal oldWeight = QWeights[feature.Key];
             decimal newWeight = oldWeight + learn * difference * feature.Value;
             if (Math.Abs(newWeight) <= 1000000)
             {
                 QWeights[feature.Key] = newWeight;
             }
             else WriteOutput("Warning: Weights diverging. Check that your features are valid and measured consistently with everything else.", true);
         }
         catch (Exception e)
         {
             WriteOutput("Exception: " + e + "\n*Check that your features are valid and measured consistently with everything else.*", true);
             Abort();
             break;
         }
     }
     
     // Output
     foreach (QFeature f in features.Keys)
     {
         UpdateLearningTable(-1, f.ToString(), QWeights[f].ToString(), features[f]);
     }
 }
Exemplo n.º 35
0
        public MainWindow()
        {
            QAction quit = new QAction("&Quit", this);
            quit.triggered.connect(QApplication.instance(), "quit()");
            QAction open = new QAction("&Open", this);
            open.triggered.connect(this, "open()");
            QAction native = new QAction("&Use native object", this);
            native.triggered.connect(this, "native()");

            QMenu file = menuBar().addMenu("&File");
            file.addAction(open);
            file.addAction(native);
            file.addAction(quit);

            webView = new QWebView();

            webView.page().mainFrame().javaScriptWindowObjectCleared.connect(this, "frame_javaScriptWindowObjectCleared()");
            addNativeObject();

            webView.load(QUrl.fromLocalFile(@"C:\Users\chambers\Development\NDirStat\NDirStatQtWeb\NDirStat.html"));
            setCentralWidget(webView);
        }
Exemplo n.º 36
0
Arquivo: Query.cs Projeto: Zexks/QLite
 public Query()
 {
     Variables = new List<QueryVariable>();
     Action = new QAction();
 }
Exemplo n.º 37
0
 // Features - aka characteristics - associated with a decision (state-action) and their values.  Used to determine similarity between different state-action pairs.  These should be estimated from a prior state.
 // Leave empty to not use and QLearner will judge each state independently with Equals.
 // Tip: Feature values should be defined as 1 or 0 (on/off) or try to normalize the value out of 1 as opposed to using infinite domain.
 public override Dictionary<QFeature, decimal> GetFeatures(QAction action)
 {
     { return new Dictionary<QFeature, decimal>() { { new QFeature_String(ToString()), 1 }}; }
 }
Exemplo n.º 38
0
 // Returns the other observable QStates to learn from, such as moves it could have done or what opponents did
 public override Dictionary<QStateActionPair, QState> GetObservedStates(QState prevState, QAction action)
 {
     return new Dictionary<QStateActionPair, QState>() { };
 }
Exemplo n.º 39
0
 public override QState GetNewState(QAction action)
 {
     return new Count() { start = this.start, end=this.end, value = (action==UP? this.value + this.upIncrement:this.value - this.downIncrement), upIncrement = this.upIncrement, downIncrement = this.downIncrement};
 }
Exemplo n.º 40
0
 public override QState GetNewState(QAction action)
 {
     return new Count_To_100() { value = (action == UP ? this.value + this.upIncrement : this.value - this.downIncrement), upIncrement = this.upIncrement, downIncrement = this.downIncrement };
 }
Exemplo n.º 41
0
        public override QState GetNewState(QAction action)
        {
            
            int newX = self.X, newY = self.Y;

            // Translate decision to new coordinate
            if (action == UP) newY--;
            else if (action == DOWN) newY++;
            else if (action == LEFT) newX--;
            else if (action == RIGHT) newX++;

            Point newPos = new Point(newX, newY);

            // Cannot go there
            if (newY < 0 || newX < 0 || newY >= height || newX >= width || walls.Contains(newPos))
            {
                newX = self.X;
                newY = self.Y;
                newPos = new Point(newX, newY);
            }

            // Pass all variables to new state
            return new Maze() { maze = maze, self = newPos, goal = goal, width=width, height=height, walls=walls, score=score-1, opponent = opponent.ToList(), opponents=opponents, random=random, opponentDifficulty=opponentDifficulty};
        }
Exemplo n.º 42
0
    public void SetupUi(QMainWindow MainWindow)
    {
        if (MainWindow.ObjectName == "")
        MainWindow.ObjectName = "MainWindow";
        QSize Size = new QSize(631, 570);
        Size = Size.ExpandedTo(MainWindow.MinimumSizeHint());
        MainWindow.Size = Size;
        MainWindow.MinimumSize = new QSize(600, 550);
        MainWindow.WindowIcon = new QIcon(":/main/resources/Images/comex_256.png");
        action_Open = new QAction(MainWindow);
        action_Open.ObjectName = "action_Open";
        action_Open.icon = new QIcon(":/main/resources/Images/document-open.png");
        action_Close = new QAction(MainWindow);
        action_Close.ObjectName = "action_Close";
        action_Close.Enabled = false;
        action_Close.icon = new QIcon(":/main/resources/Images/document-close.png");
        action_Exit = new QAction(MainWindow);
        action_Exit.ObjectName = "action_Exit";
        action_Exit.icon = new QIcon(":/main/resources/Images/application-exit.png");
        action_Info = new QAction(MainWindow);
        action_Info.ObjectName = "action_Info";
        action_Info.icon = new QIcon(":/main/resources/Images/dialog-information.png");
        action_ATR = new QAction(MainWindow);
        action_ATR.ObjectName = "action_ATR";
        action_ATR.icon = new QIcon(":/main/resources/Images/quickopen.png");
        action_Exec_Command = new QAction(MainWindow);
        action_Exec_Command.ObjectName = "action_Exec_Command";
        action_SerialSettings = new QAction(MainWindow);
        action_SerialSettings.ObjectName = "action_SerialSettings";
        action_SerialSettings.icon = new QIcon(":/main/resources/Images/configure.png");
        centralwidget = new QWidget(MainWindow);
        centralwidget.ObjectName = "centralwidget";
        gridLayout = new QGridLayout(centralwidget);
        gridLayout.ObjectName = "gridLayout";
        FrameATR = new QGroupBox(centralwidget);
        FrameATR.ObjectName = "FrameATR";
        QSizePolicy sizePolicy = new QSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed);
        sizePolicy.SetHorizontalStretch(0);
        sizePolicy.SetVerticalStretch(0);
        sizePolicy.SetHeightForWidth(FrameATR.SizePolicy.HasHeightForWidth());
        FrameATR.SizePolicy = sizePolicy;
        gridLayout1 = new QGridLayout(FrameATR);
        gridLayout1.ObjectName = "gridLayout1";
        TxtATR = new QLineEdit(FrameATR);
        TxtATR.ObjectName = "TxtATR";
        TxtATR.StyleSheet = "color: rgb(30, 109, 30);";
        TxtATR.ReadOnly = true;

        gridLayout1.AddWidget(TxtATR, 0, 0, 1, 1);

        gridLayout.AddWidget(FrameATR, 0, 0, 1, 1);

        FrameFile = new QGroupBox(centralwidget);
        FrameFile.ObjectName = "FrameFile";
        gridLayout2 = new QGridLayout(FrameFile);
        gridLayout2.ObjectName = "gridLayout2";
        LstCommands = new QListWidget(FrameFile);
        LstCommands.ObjectName = "LstCommands";
        LstCommands.EditTriggers = Qyoto.Qyoto.GetCPPEnumValue("QAbstractItemView", "NoEditTriggers");

        gridLayout2.AddWidget(LstCommands, 0, 0, 1, 1);

        gridLayout.AddWidget(FrameFile, 1, 0, 1, 1);

        FrameExchange = new QGroupBox(centralwidget);
        FrameExchange.ObjectName = "FrameExchange";
        sizePolicy.SetHeightForWidth(FrameExchange.SizePolicy.HasHeightForWidth());
        FrameExchange.SizePolicy = sizePolicy;
        gridLayout3 = new QGridLayout(FrameExchange);
        gridLayout3.ObjectName = "gridLayout3";
        LblCommand = new QLabel(FrameExchange);
        LblCommand.ObjectName = "LblCommand";

        gridLayout3.AddWidget(LblCommand, 0, 0, 1, 1);

        TxtCmd = new QLineEdit(FrameExchange);
        TxtCmd.ObjectName = "TxtCmd";
        TxtCmd.StyleSheet = "color: rgb(30, 109, 30);";

        gridLayout3.AddWidget(TxtCmd, 0, 1, 1, 1);

        BtnSend = new QPushButton(FrameExchange);
        BtnSend.ObjectName = "BtnSend";
        BtnSend.icon = new QIcon(":/main/resources/Images/arrow-right.png");

        gridLayout3.AddWidget(BtnSend, 0, 2, 1, 1);

        LblResponse = new QLabel(FrameExchange);
        LblResponse.ObjectName = "LblResponse";

        gridLayout3.AddWidget(LblResponse, 1, 0, 1, 1);

        TxtResp = new QLineEdit(FrameExchange);
        TxtResp.ObjectName = "TxtResp";
        TxtResp.StyleSheet = "color: rgb(0, 0, 255);";
        TxtResp.ReadOnly = true;

        gridLayout3.AddWidget(TxtResp, 1, 1, 1, 1);

        gridLayout.AddWidget(FrameExchange, 2, 0, 1, 1);

        MainWindow.SetCentralWidget(centralwidget);
        menubar = new QMenuBar(MainWindow);
        menubar.ObjectName = "menubar";
        menubar.Geometry = new QRect(0, 0, 631, 24);
        menu_File = new QMenu(menubar);
        menu_File.ObjectName = "menu_File";
        menu_Reader = new QMenu(menubar);
        menu_Reader.ObjectName = "menu_Reader";
        menu_About = new QMenu(menubar);
        menu_About.ObjectName = "menu_About";
        MainWindow.SetMenuBar(menubar);
        statusbar = new QStatusBar(MainWindow);
        statusbar.ObjectName = "statusbar";
        MainWindow.SetStatusBar(statusbar);
        toolBar = new QToolBar(MainWindow);
        toolBar.ObjectName = "toolBar";
        toolBar.Movable = false;
        toolBar.ToolButtonStyle = Qt.ToolButtonStyle.ToolButtonTextBesideIcon;
        toolBar.Floatable = false;
        MainWindow.AddToolBar(Qt.ToolBarArea.TopToolBarArea, toolBar);

        menubar.AddAction(menu_File.MenuAction());
        menubar.AddAction(menu_Reader.MenuAction());
        menubar.AddAction(menu_About.MenuAction());
        menu_File.AddAction(action_Open);
        menu_File.AddAction(action_Close);
        menu_File.AddSeparator();
        menu_File.AddAction(action_SerialSettings);
        menu_File.AddSeparator();
        menu_File.AddAction(action_Exit);
        menu_About.AddAction(action_Info);
        toolBar.AddAction(action_Open);
        toolBar.AddAction(action_Close);
        toolBar.AddAction(action_SerialSettings);
        toolBar.AddAction(action_ATR);
        toolBar.AddAction(action_Info);
        toolBar.AddSeparator();
        toolBar.AddAction(action_Exit);

        RetranslateUi(MainWindow);

        QMetaObject.ConnectSlotsByName(MainWindow);
    }
Exemplo n.º 43
0
        public override Dictionary<QStateActionPair, QState> GetObservedStates(QState prevState, QAction action)
        {
            Maze m = (Maze)prevState;
            Dictionary<QStateActionPair, QState> otherMoves = new Dictionary<QStateActionPair, QState>();
            foreach (QAction a in prevState.GetActions())
            {
                Maze potentialMove = (Maze)m.GetNewState(a);
                potentialMove.opponent = opponent.ToList();
            }

            return otherMoves;
        }
Exemplo n.º 44
0
 protected virtual void QUpdate(int n, QState currentState, QAction action, QState newState, decimal reward)
 {
     QStateActionPair p = new QStateActionPair(currentState, action);
     decimal maxQ = GetMaxValue(newState);
     QValues[p] = (1 - learn) * GetQValue(p) + learn * (reward + discount * maxQ);
     UpdateLearningTable(n, currentState, action, QValues[p]);
 }
Exemplo n.º 45
0
        public override Dictionary<QFeature, decimal> GetFeatures(QAction action)
        {
            Point self = ((Maze_With_No_Walls)GetNewState(action)).self;
            QSearch qsearch = new QSearch(this);
            Maze_With_No_Walls simpleMaze = new Maze_With_No_Walls() { maze = maze, self = self, goal = goal, width = width, height = height };
            QSearchResult bestPath = qsearch.AStar(simpleMaze);

            return QFeature_String.FromStringDecimalDictionary(new Dictionary<string, decimal>() {
                //{this.GetHashCode().ToString()+"_"+action, 1}, // Identity to convert this back to QLearning
                {"Goal", goal==self? 1:0},
                {"Distance_To_Goal", bestPath==null? 1:(decimal) bestPath.Count / (decimal)(width * height)},
            });
        }
Exemplo n.º 46
0
        public override Dictionary<QStateActionPair, QState> GetObservedStates(QState prevState, QAction action)
        {
            TicTacToe stateAfterMyMove = (TicTacToe)prevState.GetNewState(action);
            TicTacToe stateFromOpponentsView = new TicTacToe() { myMoves = stateAfterMyMove.yourMoves.ToList(), yourMoves = stateAfterMyMove.myMoves.ToList(), me = you, you = me, random = random, gui = gui, openSpaces = stateAfterMyMove.openSpaces.ToList(), score = stateAfterMyMove.score };
            TicTacToe stateNowFromOpponentsView = new TicTacToe() { myMoves = yourMoves.ToList(), yourMoves = myMoves.ToList(), me = you, you = me, random = random, gui = gui, openSpaces = openSpaces.ToList(), score = stateAfterMyMove.score };
            
            foreach (Point x in stateNowFromOpponentsView.myMoves)
                if (!stateFromOpponentsView.myMoves.Contains(x)) 
                    return new Dictionary<QStateActionPair, QState>() {
                        {new QStateActionPair(stateFromOpponentsView, new QAction_String(x.X + "," + x.Y)), stateNowFromOpponentsView}
                    };

            return new Dictionary<QStateActionPair, QState>();
        }
Exemplo n.º 47
0
        public override QState GetNewState(QAction action = null)
        {
            if (action.ToString() != "")
            {
                string[] point = action.ToString().Split(',');
                Point newPos = new Point(Convert.ToInt32(point[0]), Convert.ToInt32(point[1]));

                List<Point> newSpaces = openSpaces.ToList();
                newSpaces.Remove(newPos);

                List<Point> newMoves = myMoves.ToList();
                newMoves.Add(newPos);

                TicTacToe newState = new TicTacToe() { myMoves = newMoves, yourMoves = yourMoves.ToList(), me = me, you = you, random = random, gui = gui, openSpaces = newSpaces, score = score };

                // Pass all variables to new state
                return newState;
            }
            else return this;
        }
Exemplo n.º 48
0
        public override Dictionary<QFeature, decimal> GetFeatures(QAction action)
        {
            Point self = ((Maze)GetNewState(action)).self;
            QSearch qsearch = new QSearch(this);
            Maze simpleMaze = new Maze() { maze = maze, self = self, goal = goal, width = width, height = height, walls = walls.ToArray() };
            QSearchResult bestPath = qsearch.AStar(simpleMaze);

            List<Point> bestOppMoves = new List<Point>();
            foreach (Point o in opponent)
            {
                bestOppMoves.Add(o);
                bestOppMoves.Add(new Point(o.X + 1, o.Y));
                bestOppMoves.Add(new Point(o.X - 1, o.Y));
                bestOppMoves.Add(new Point(o.X, o.Y + 1));
                bestOppMoves.Add(new Point(o.X, o.Y - 1));
            }
            foreach (Point o in bestOppMoves.ToArray())
            {
                bestOppMoves.Add(new Point(o.X + 1, o.Y));
                bestOppMoves.Add(new Point(o.X - 1, o.Y));
                bestOppMoves.Add(new Point(o.X, o.Y + 1));
                bestOppMoves.Add(new Point(o.X, o.Y - 1));
            }
            Maze safeMaze = new Maze() { maze = maze, self = self, goal = goal, width = width, height = height, walls = walls.Concat(bestOppMoves).ToArray() };
            QSearchResult safePath = qsearch.AStar(safeMaze);
            Dictionary<string, decimal> features = new Dictionary<string, decimal>() {
                //{this.GetHashCode().ToString()+"_"+action, 1}, // Identity to convert this back to QLearning
                {"Goal", goal==self? 1:0},
                {"Direct_Distance_To_Goal", bestPath==null? 1:(decimal) bestPath.Count / (decimal)(width * height)},
                {"Safe_Distance_To_Goal", (safePath==null? 1: (decimal)safePath.Count/ (decimal)(width * height))}
            };

            decimal distanceToOpponent = decimal.MaxValue;
            if (opponent.Any())
            {
                features["Opponent"] = goal!=self && opponent.Where(p => (Math.Abs(p.X - self.X) <= 1 && p.Y == self.Y) || (Math.Abs(p.Y - self.Y) <= 1 && p.X == self.X)).Any() ? 1 : 0;

                distanceToOpponent = opponent.Select(o => qsearch.AStar(new Maze() { maze = maze, self = self, goal = o, width = width, height = height, walls = walls })).Select(x=>x==null? width*height:x.Count).Min();
                features["Distance_To_Opponent"] = distanceToOpponent>=5? 1:distanceToOpponent / (decimal)(width * height);

                if (goal != self)
                {
                    Maze deadEnd = new Maze() { maze = maze, self = self, goal = goal, width = width, height = height, walls = walls.Concat(new Point[] { new Point(this.self.X - 1, this.self.Y), new Point(this.self.X + 1, this.self.Y), new Point(this.self.X, this.self.Y - 1), new Point(this.self.X, this.self.Y + 1) }).ToArray() };
                    QSearchResult deadPath = qsearch.Depth_First(deadEnd);
                    if (deadPath == null)
                    {
                        features["Dead_End"] = 1;
                    }
                }
            }

            

            return QFeature_String.FromStringDecimalDictionary(features);
        }
Exemplo n.º 49
0
 // Returns the new state you get to from here if you take a certain action
 // This should only reflect the new action taken (independent variables update) and the most immediate unconditional effects of the independent action (no adversary, random environmental change, gui updates, etc). It should be quick to calculate, so that algorithms can use this for calculating estimates of solutions (with environment unchanging).  See the next method for applying the changes by environment/adversaries and gui updates.
 // Make sure to actually return a new instance with deep-copied properties, as opposed to just passing references.
 public override QState GetNewState(QAction action)
 {
     return null;
 }