public Pattern(Pattern p) { this.row = p.row.Table.NewRow(); this._repeat_count = p._repeat_count; this.algorithm = p.algorithm; // clone the original data row. DataRow row = p.row; for (int n = 1; n < p.row.ItemArray.Length; n++) { // don't copy the primary key. if (p.row.Table.Columns[n].AutoIncrement) { continue; } this.row[n] = p.row[n]; } // clone all the loaded masks. this.masks = new List <System.Collections.Specialized.BitVector32>(); foreach (System.Collections.Specialized.BitVector32 bits in p.masks) { this.masks.Add(new System.Collections.Specialized.BitVector32(bits)); } this.sub_patterns = new List <Pattern>(); foreach (Pattern pattern in p.sub_patterns) { sub_patterns.Add(pattern); } // create a new name based on the old name. this.row[XDataTable.Name(row.Table)] = this.Name = "Copy of " + p.Name; this._mode_mod = p._mode_mod; this.pattern_list = p.pattern_list; this.changed = true; retry_name: try { p.row.Table.Rows.Add(this.row); } catch (ConstraintException ce) { if (ce.Message.IndexOf("pattern_name") >= 0) { this.row[XDataTable.Name(row.Table)] = this.Name = "Copy of " + this.Name; goto retry_name; } } UpdateRow(); }
public Pattern(ScheduleDataSet schedule, Patterns pattern_data) { ID = Guid.Empty; row = schedule.patterns.NewRow(); Name = QueryNewName.Show("Enter new pattern name"); if (Name == null || Name == "") { throw new NullReferenceException("Name cannot be blank."); } _repeat_count = 1; algorithm = 0; _mode_mod = mode_modifications.NoExpansion; masks = new List <System.Collections.Specialized.BitVector32>(25); sub_patterns = new List <Pattern>(); //row["pattern_name"] = Name; changed = true; this.pattern_list = pattern_data; //pattern_data = schedule.pattern_data; schedule.patterns.Rows.Add(row); UpdateRow(); }
int[] ExpandMods(mode_modifications mod , List <System.Collections.Specialized.BitVector32> masks) { mode_modifications this_mod = (mod & mode_modifications.mask_mod); bool anywhere = (this_mod == mode_modifications.Anywhere || this_mod == mode_modifications.AnywhereHardway || this_mod == mode_modifications.AnyWhereAnyDirection || this_mod == mode_modifications.AnyWhereAnyDirectionHardway || this_mod == mode_modifications.MirrorAnywhere || this_mod == mode_modifications.MirrorAnywhereHardway || this_mod == mode_modifications.MirrorAnyWhereAnyDirection || this_mod == mode_modifications.MirrorAnyWhereAnyDirectionHardway) ; bool mirror = (this_mod == mode_modifications.MirrorAnywhere || this_mod == mode_modifications.MirrorAnywhereHardway || this_mod == mode_modifications.MirrorAnydirection || this_mod == mode_modifications.MirrorAnydirectionHardway || this_mod == mode_modifications.MirrorAnyWhereAnyDirection || this_mod == mode_modifications.MirrorAnyWhereAnyDirectionHardway) ; bool anydirection = (this_mod == mode_modifications.Anydirection || this_mod == mode_modifications.AnydirectionHardway || this_mod == mode_modifications.AnyWhereAnyDirection || this_mod == mode_modifications.AnyWhereAnyDirectionHardway || this_mod == mode_modifications.MirrorAnydirection || this_mod == mode_modifications.MirrorAnydirectionHardway || this_mod == mode_modifications.MirrorAnyWhereAnyDirection || this_mod == mode_modifications.MirrorAnyWhereAnyDirectionHardway) ; List <int> output = new List <int>(); if (mod == mode_modifications.NoExpansion) { foreach (System.Collections.Specialized.BitVector32 mask in masks) { output.Add(mask.Data); } return(output.ToArray()); } if (anywhere && !anydirection) { bool skip_easy = (mod == mode_modifications.AnywhereHardway); int m; bool[,] layout = new bool[5, 5]; for (m = 0; m < masks.Count; m++) { int r, c; // setup layout array.... for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[r, c] = true; } else { layout[r, c] = false; } } } ExpandByMoveSingleMask(layout, output, skip_easy); } } if (anydirection) { bool skip_easy = (this_mod == mode_modifications.AnydirectionHardway) || (this_mod == mode_modifications.AnywhereHardway) || (this_mod == mode_modifications.AnyWhereAnyDirectionHardway) || (this_mod == mode_modifications.MirrorAnydirectionHardway) || (this_mod == mode_modifications.MirrorAnywhereHardway) || (this_mod == mode_modifications.MirrorAnyWhereAnyDirectionHardway); int m; bool[,] layout = new bool[5, 5]; for (m = 0; m < masks.Count; m++) { int r, c; // setup layout array.... for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[r, c] = true; } else { layout[r, c] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[c, 4 - r] = true; } else { layout[c, 4 - r] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[4 - r, 4 - c] = true; } else { layout[4 - r, 4 - c] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[4 - c, r] = true; } else { layout[4 - c, r] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } if (mirror) { // setup layout array.... for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[c, r] = true; } else { layout[c, r] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[4 - r, c] = true; } else { layout[4 - r, c] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[4 - c, 4 - r] = true; } else { layout[4 - c, 4 - r] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } for (r = 0; r < 5; r++) { for (c = 0; c < 5; c++) { if ((masks[m].Data & (1 << (c * 5 + r))) != 0) { layout[r, 4 - c] = true; } else { layout[r, 4 - c] = false; } } } if (anywhere) { ExpandByMoveSingleMask(layout, output, skip_easy); } else { ConvertSingleMask(layout, output); } } } } return(output.ToArray()); }
void CommonInit(DataRow row, Patterns pattern_list) { this.row = row; //this.pattern_data = pattern_data; //this.pattern_sub_pattern = pattern_sub_pattern; this.pattern_list = pattern_list; int col_count = row.Table.Columns.IndexOf("count"); int col_match = row.Table.Columns.IndexOf("match"); //ID = Convert.ToInt32( row[XDataTable.ID( row.Table )] ); ID = row[XDataTable.ID(row.Table)]; Name = (String)row[XDataTable.Name(row.Table)]; if (col_count >= 0) { if (row[col_count].GetType() == typeof(DBNull)) { _repeat_count = 1; } else { _repeat_count = Convert.ToInt32(row[col_count]); } if (_repeat_count == 0 && col_match >= 0) { // this causes the row that selected this to change. row[col_count] = row[col_match]; if (row[col_match].GetType() == typeof(DBNull)) { _repeat_count = 1; } else { _repeat_count = Convert.ToInt32(row[col_match]); } } } else { _repeat_count = (int)row["match"]; } _crazy_hardway = (bool)row["crazy_hardway"]; if (row.Table.Columns.IndexOf("mode") >= 0) { algorithm = (row["mode"].Equals(DBNull.Value) ? PatternDescriptionTable.match_types.Normal : (PatternDescriptionTable.match_types)row["mode"]); } else { algorithm = (row["real_mode"].Equals(DBNull.Value) ? PatternDescriptionTable.match_types.Normal : (PatternDescriptionTable.match_types)row["real_mode"]); } _mode_mod = (mode_modifications)row["mode_mod"]; object o = row["pattern_board_size"]; board_size = (o == DBNull.Value)?0:Convert.ToInt32(o); if ((_mode_mod & mode_modifications.eCube) != 0) { _mode_mod -= mode_modifications.eCube; eCube = true; } if ((_mode_mod & mode_modifications.max_mod) != 0) { _mode_mod -= mode_modifications.max_mod; _repeat_no_overlap = true; } if (_mode_mod == mode_modifications.NoOverlap) { _repeat_no_overlap = true; } sub_patterns = new List <Pattern>(); { DataRow[] sub_pattern_rows = row.GetChildRows("pattern_has_sub_pattern"); foreach (DataRow pattern in sub_pattern_rows) { Pattern sub = null; foreach (Pattern p in pattern_list) { if (p.ID.Equals(pattern[PatternDescriptionTable.PrimaryKey])) { sub = p; break; } } if (sub == null) { bool created2; sub = pattern_list.GetPattern(pattern.GetParentRow("sub_pattern_is_pattern"), out created2); } this.sub_patterns.Add(sub); } } masks = new List <System.Collections.Specialized.BitVector32>(); // these aren't really changes. changed = false; }