Building a WPF Sudoku Game: Part 5 - The AI Battle: Loading and Comparing AI Plug-ins

Sign in to queue

The Discussion

  • User profile image
    Michael

    The finished product is quite nice, but you overlooked the most important aspect of a Sudoku puzzle: pencil marks.  I was thinking that it is something on feasible with a 9x9 grid.  So here is the question:  Can the game board be duplicated with 9x9 displays inside each square of the 9x9 grid, displayed on top with a very low transparency so that both the board and pencil marks are visible?  You might have to disable the validator on the pencil mark board and expose a TryValue that does validation on the game board without actually setting the value.  Also when a value is set in the game board, the pencil marks are removed, and the validation on the pencil mark board removes that value from the row, collumn, and owning square.

    I'm still learning WPF so I don't know how much I can do programmatically to control such elements as multiple layers on the display and altering who is in front and how is in back and how the transparency value changes as each move back and forth.

    My thought is that when I'm in pencil mark mode, the pencil mark view is in the back with full visibility and the value board being on top and transparent.  When you are back in normal mode, the two flip order and the pencil mark view returns to being transparent while the value board is full visible.  Some animation would make it even cooler...like the transparency between the two boards gradually shifts while there is a halo effect around the board.

  • User profile image
    Bruce

    Very fun game, and very fun tutorial.  However, I did find some erros in the logic of the generated numbers to begin a board.  It does not correctly evaluate if a number can be placed in a location without interfearing with the same value elsewhere.  I have not solve the logic yet... but I will update when I find/get around to it.

  • User profile image
    Denver

    Hello Lucas! i've enjoyed this walk through tutorial about wpf! thanks lot Smiley this last installment I managed to encounter an unhandled exception when i tried to benchmark the solver.

    Here's the details:

    System.Windows.Markup.XamlParseException was unhandled

     Message="Cannot find resource named '{BarColorConverter}'. Resource names are case sensitive.  Error at object 'System.Windows.Data.Binding' in markup file 'SudokuFX;component/graphcontrol.xaml' Line 13 Position 116."

     Source="PresentationFramework"

     LineNumber=13

     LinePosition=116

     NameContext="Tag"

     StackTrace:

          at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)

          at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)

          at System.Windows.Markup.BamlRecordReader.ThrowException(SRID id, String parameter)

          at System.Windows.StaticResourceExtension.ProvideValueInternal(IBamlReader bamlReader, Object targetObject, Object targetProperty, Boolean allowDeferredReference)

          at System.Windows.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)

          at System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(MarkupExtension markupExtension, Object obj, Object member)

          at System.Windows.Markup.BamlRecordReader.BaseReadOptimizedMarkupExtension(Object element, Int16 attributeId, PropertyDefinition propertyDefinition, Object value)

          at System.Windows.Markup.BamlRecordReader.ReadPropertyWithStaticResourceIdRecord(BamlPropertyWithStaticResourceIdRecord bamlPropertyWithStaticResourceIdRecord)

          at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)

          at System.Windows.StyleHelper.LoadOptimizedTemplateContent(DependencyObject container, ParserContext parserContext, OptimizedTemplateContent optimizedTemplateContent, FrameworkTemplate frameworkTemplate, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)

          at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)

          at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)

          at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)

          at System.Windows.FrameworkElement.ApplyTemplate()

          at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

          at System.Windows.UIElement.Measure(Size availableSize)

          at System.Windows.Controls.Border.MeasureOverride(Size constraint)

          at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

          at System.Windows.UIElement.Measure(Size availableSize)

          at System.Windows.Controls.Control.MeasureOverride(Size constraint)

          at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

          at System.Windows.UIElement.Measure(Size availableSize)

          at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)

          at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

          at System.Windows.UIElement.Measure(Size availableSize)

          at System.Windows.ContextLayoutManager.UpdateLayout()

          at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

          at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()

          at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

          at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

          at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

          at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

          at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

          at System.Windows.Threading.DispatcherOperation.InvokeImpl()

          at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)

          at System.Threading.ExecutionContext.runTryCode(Object userData)

          at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

          at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

          at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

          at System.Windows.Threading.DispatcherOperation.Invoke()

          at System.Windows.Threading.Dispatcher.ProcessQueue()

          at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

          at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

          at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

          at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

          at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

          at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

          at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

          at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

          at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

          at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

          at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

          at System.Windows.Threading.Dispatcher.Run()

          at System.Windows.Application.RunInternal(Window window)

          at System.Windows.Application.Run(Window window)

          at System.Windows.Application.Run()

          at SudokuFX.MyApp.Main() in D:\Documents and Settings\mon\Desktop\WPF Sudoku\262086_SudokuFX5\SudokuFX5\SudokuFX\obj\Debug\MyApp.g.cs:line 0

          at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)

          at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

          at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

          at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

          at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

          at System.Threading.ThreadHelper.ThreadStart()

    Any hint, about it? I've tried to find "{BarColorConverter}"  but couldn't find it.

    Hope you could extend your help about this, thanks! Smiley

  • User profile image
    daemon

    Hello Lucas! I'm having a problem following your tutorial on Sudoku harnessing WPF. Actually for several times all of the five source codes you provided was working well then just yesterday the designer on "Windows1.xaml" won't show up anymore. Here's the error provided by the editor.

    • Error 1 Assembly '' was not found. The 'clr-namespace' URI refers to an assembly that is not referenced by the project. D:\Documents and Settings\mon\Desktop\Sudoku Madness\Sudoku Madness\Window1.xaml 4 15 Sudoku Madness

    • Error 2 The type 'clr:MadBoard' was not found. Verify that you are not missing an assembly reference. D:\Documents and Settings\mon\Desktop\Sudoku Madness\Sudoku Madness\Window1.xaml 92 13 Sudoku Madness

    • Warning 3 The element 'DockPanel' in namespace 'https://schemas.microsoft.com/winfx/2006/xaml/presentation' has invalid child element 'MadBoard' in namespace 'clr-namespace:Sudoku_Madness'. List of possible elements expected: 'DockPanel.LastChildFill, DockPanel.Background, DockPanel.IsItemsHost, DockPanel.Style, DockPanel.OverridesDefaultStyle, DockPanel.Triggers, DockPanel.Resources, DockPanel.DataContext, DockPanel.Language, DockPanel.Tag, DockPanel.InputScope, DockPanel.LayoutTransform, DockPanel.Width, DockPanel.MinWidth, DockPanel.MaxWidth, DockPanel.Height, DockPanel.MinHeight, DockPanel.MaxHeight, DockPanel.Margin, DockPanel.FocusVisualStyle, DockPanel.Cursor, DockPanel.ForceCursor, DockPanel.ToolTip, DockPanel.ContextMenu, DockPanel.InputBindings, DockPanel.CommandBindings, DockPanel.AllowDrop, DockPanel.RenderSize, DockPanel.RenderTransform, DockPanel.RenderTransformOrigin, DockPanel.Opacity, DockPanel.OpacityMask, DockPanel.BitmapEffect, DockPanel.BitmapEffectInput, DockPanel.ClipToBounds, DockPanel.Clip, DockPanel.SnapsToDevicePixels, DockPanel.IsEnabled, DockPanel.IsHitTestVisible, DockPanel.Focusable, sgUIElement, sgFrameworkElement, sgShape, Ellipse, Line, Path, Polygon, Polyline, Rectangle, sgPanel, Canvas, DockP.... D:\Documents and Settings\mon\Desktop\Sudoku Madness\Sudoku Madness\Window1.xaml 92 13 Sudoku Madness

    I'm currently new to WPL and XAML, I tried to look for some clues on how to fix it but I can't avail anything. I'm using Visual Studio 2005 Pro, Running on Win XP SP2, I've installed also the extensions for Windows Workflow Foundation and the CTP 2006 of .NET 3.0

    I'm hoping you could help me address this issue and if you would be so kind at least elaborate why such thing happen. Thanks Smiley

    *I'm wondring if there is such compatibility issues between the cde generated by the Visual Studio Express edition and the Professional Edition which I'm using currently.

  • User profile image
    monz

    when i tried to benchmark the solvers, i got an exception about the bar color coverter, im quite sure i havent altered any line.

    any suggestion?

  • User profile image
    Clint
  • User profile image
    Software Information » Coding4Fun : Building a WPF Sudoku Game Part 1: Introduction to WPF …
  • User profile image
    Gavin

    Even over two years after this series of articles was published, it's still serving as a useful tutorial on WPF. Thanks for the good work in putting this together.

    A few people have commented on an exception being raised when you try to benchmark a solver plugin - static resource BarColorConverter could not be found.

    I've found that you need to move the two lines:

    <clr:BarColorConverter x:Key="BarColorConverter"/>

    <clr:ColorLightnessConverter x:Key="ColorLightnessConverter"/>

    from the position at the end of the <ListBox.Resources> declaration in GraphControl.xaml to the beginning of the <ListBox.Resources> declaration - I moved them to right under <ListBox.Resources>. I haven't experimented with any alternative locations.

    The above fix works for me. Hope it helps!

  • User profile image
    ge-force

    This is great - am working on enhancing it (3D bevel effect, even more custom controls, transparancy, ect.)

    I'm a newbe to WPF, but this tutorial really helped.

    Thanks!

    Ge-force

  • User profile image
    Martin Mason

    Great series of articles - taught me a lot about WPF. Just started work on the UI and downloaded the code for articles 1 and 2, but I cannot download the code for articles 3, 4 or 5. These three just give a"BlobNotFound" error msg. Can you direct me to the code downloads ?

Add Your 2 Cents