public void ExtractRow() { var RowRules = new List<List<int>>(); var ColumnRules = new List<List<int>>(); var model = new NonogramModel(3, 3, RowRules, ColumnRules); model[2, 0].State = BoardItemState.Marked; model[1, 1].State = BoardItemState.Marked; model[2, 1].State = BoardItemState.Marked; model[0, 2].State = BoardItemState.Marked; model[2, 2].State = BoardItemState.Marked; CollectionAssert.AreEqual(model.ExtractRow(0), new List<int> { 1 }); CollectionAssert.AreEqual(model.ExtractRow(1), new List<int> { 2 }); CollectionAssert.AreEqual(model.ExtractRow(2), new List<int> { 1, 1 }); }
public void ExtractColumnWithBlocked() { var RowRules = new List<List<int>>(); var ColumnRules = new List<List<int>>(); var model = new NonogramModel(3, 3, RowRules, ColumnRules); model[0, 0].State = BoardItemState.Blocked; model[1, 0].State = BoardItemState.Free; model[2, 0].State = BoardItemState.Marked; model[0, 1].State = BoardItemState.Blocked; model[1, 1].State = BoardItemState.Marked; model[2, 1].State = BoardItemState.Marked; model[0, 2].State = BoardItemState.Marked; model[1, 2].State = BoardItemState.Blocked; model[2, 2].State = BoardItemState.Marked; CollectionAssert.AreEqual(model.ExtractColumn(0), new List<int> { 1 }); CollectionAssert.AreEqual(model.ExtractColumn(1), new List<int> { 1 }); CollectionAssert.AreEqual(model.ExtractColumn(2), new List<int> { 3 }); }
private void GenerateBoard(NonogramModel model) { // The Width and the Height of the board is not always the same. for (int i = 0; i < model.Columns; i++) { this.MyBoard.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); } for (int i = 0; i < model.Rows; i++) { this.MyBoard.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); } for (int column = 0; column < model.Columns; column++) { for (int row = 0; row < model.Rows; row++) { var button = new Button(); button.Command = new BoardClickCommand(model, column, row); button.SetValue(Grid.ColumnProperty, column); button.SetValue(Grid.RowProperty, row); var img = new Image(); img.Width = 16; img.Height = 16; button.Content = img; Binding myBinding = new Binding(); myBinding.Source = model[column, row]; myBinding.Path = new PropertyPath("State"); myBinding.Mode = BindingMode.OneWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; myBinding.Converter = new BoardItemStateToImage(); BindingOperations.SetBinding(img, Image.SourceProperty, myBinding); MyBoard.Children.Add(button); } } }
public static NonogramModel GenerateRandom(int width, int height) { var model = new NonogramModel(width, height); Random rnd = new Random(); for (int row = 0; row < height; row += 1) { for (int column = 0; column < width; column += 1) { if (rnd.Next(2) == 0) { model[column, row] = new BoardItem { State = BoardItemState.Marked }; } } } for (int i = 0; i < width; i += 1) { model.ColumnRules.Add(model.ExtractColumn(i)); } for (int i = 0; i < height; i += 1) { model.RowRules.Add(model.ExtractRow(i)); } model.ClearBoard(); return model; }
private void RenderBoard(NonogramModel model) { this.ClearBoardAndRules(); this.GenerateBoard(model); this.GenerateRowRules(model); this.GenerateColumnRules(model); }
private void GenerateRowRules(NonogramModel model) { var highest = model.RowRules.Select(r => r.Count).Max(); for (int column = 0; column < highest; column++) { RowRules.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); } for (int row = 0; row < model.Rows; row++) { RowRules.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); } for (int row = 0; row < model.Rows; row++) { for (int column = 0; column < model.RowRules[row].Count; column++) { var textbox = new TextBlock(); textbox.Padding = new Thickness(2.0, 0, 2.0, 0); textbox.SetValue(Grid.ColumnProperty, column + (highest - model.RowRules[row].Count)); textbox.SetValue(Grid.RowProperty, row); textbox.Text = model.RowRules[row][column].ToString(); RowRules.Children.Add(textbox); } } }
public void IsComplete_1_Test() { var RowRules = new List<List<int>> { new List<int>{1}, new List<int>{2}, new List<int>{1} }; var ColumnRules = new List<List<int>> { new List<int>{1}, new List<int>{1}, new List<int>{2} }; var model = new NonogramModel(3, 3, RowRules, ColumnRules); model[2, 0].State = BoardItemState.Marked; model[1, 1].State = BoardItemState.Marked; model[2, 1].State = BoardItemState.Marked; model[0, 2].State = BoardItemState.Marked; Assert.IsTrue(model.IsComplete()); }
public void IsComplete_2_Test() { var RowRules = new List<List<int>> { new List<int>{4}, new List<int>{4}, new List<int>{4}, new List<int>{5}, new List<int>{1} }; var ColumnRules = new List<List<int>> { new List<int>{4}, new List<int>{4}, new List<int>{4}, new List<int>{4}, new List<int>{2} }; var model = new NonogramModel(5, 5, RowRules, ColumnRules); model[0, 0].State = BoardItemState.Marked; model[0, 1].State = BoardItemState.Marked; model[0, 2].State = BoardItemState.Marked; model[0, 3].State = BoardItemState.Marked; model[1, 0].State = BoardItemState.Marked; model[1, 1].State = BoardItemState.Marked; model[1, 2].State = BoardItemState.Marked; model[1, 3].State = BoardItemState.Marked; model[2, 0].State = BoardItemState.Marked; model[2, 1].State = BoardItemState.Marked; model[2, 2].State = BoardItemState.Marked; model[2, 3].State = BoardItemState.Marked; model[3, 0].State = BoardItemState.Marked; model[3, 1].State = BoardItemState.Marked; model[3, 2].State = BoardItemState.Marked; model[3, 3].State = BoardItemState.Marked; model[4, 3].State = BoardItemState.Marked; model[4, 4].State = BoardItemState.Marked; Assert.IsTrue(model.IsComplete()); }