Ejemplo n.º 1
0
        private void btnGridBackupParse_Click(object sender, EventArgs e)
        {
            if (btnGridBackupParse.Text.Equals("") || String.IsNullOrEmpty(btnGridBackupParse.Text) || btnGridBackupParse.Text == null)
            {
            }
            else
            {
                try
                {
                    string   pastedText = txtGridBackupPaste.Text;
                    string[] lines      = pastedText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                    //lblBackupStatus.Text = lines.Count().ToString();

                    List <GridBackup> Grids = new List <GridBackup>();

                    foreach (string s in lines)
                    {
                        //Retrieve gridname
                        int firstSpace = 0;
                        firstSpace = s.IndexOf(" ", 0);
                        int firstUnderscore = 0;
                        firstUnderscore = s.IndexOf("_");
                        string gridName = s.Substring((firstSpace + 1), (firstUnderscore - (firstSpace + 1)));

                        //Retrieve GridID
                        int    dash     = s.IndexOf("-", firstUnderscore);
                        string tempTemp = s.Substring(0, firstUnderscore);
                        int    lengthBeforeUnderscore = tempTemp.Length;
                        string GridIDstring           = s.Substring((firstUnderscore + 1), (dash - (firstUnderscore) - 2));

                        //Retrieve DateTime
                        string   dateTime = s.Substring((dash + 2), ((s.Length - dash) - 2));
                        DateTime theDate  = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH:mm:ss", null);

                        //Assign an object to these values
                        GridBackup grid = new GridBackup()
                        {
                            GridName = gridName,
                            GridID   = long.Parse(GridIDstring),
                            Date     = theDate
                        };
                        Grids.Add(grid);
                    }

                    GridBackupData newForm = new GridBackupData(Grids, getPlayer(), getSelectedServer());
                    newForm.Show();
                }
                catch (NullReferenceException ex)
                {
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public virtual int Solve(IGame game)
        {
            int numberOfSolutions = SolveToClipboard(game, true);

            if (numberOfSolutions > 0)
            {
                GridBackup.RestoreFromClipboardTo(game.Grid);
            }

            return(numberOfSolutions);
        }
Ejemplo n.º 3
0
        private int ApplyChangesAndRunRules(IGame game, bool isFirstCall, FieldsToChange <BimaruValue> changes)
        {
            bool hasChangedFieldValues = ApplyChangesAndRunNonTrialRules(game, isFirstCall, changes);

            if (!isFirstCall && !hasChangedFieldValues)
            {
                throw new InvalidOperationException(@"No field value has changed, which
                                                      could lead to an infinite recursion");
            }

            if (game.IsSolved)
            {
                GridBackup.CloneToClipboard(game.Grid);
                return(1);
            }

            return(RunTrialRule(game));
        }
Ejemplo n.º 4
0
        private int SolveToClipboard(IGame game, bool isFirstCall, FieldsToChange <BimaruValue> changes = null)
        {
            int numSolutions = 0;

            GridBackup.SetSavePoint(game.Grid);

            try
            {
                numSolutions = ApplyChangesAndRunRules(game, isFirstCall, changes);
            }
            catch (InvalidBimaruGame)
            {
            }
            finally
            {
                GridBackup.RestoreAndDeleteLastSavepoint(game.Grid);
            }

            return(numSolutions);
        }