The official Fatica Labs Blog! RSS 2.0
# Sunday, 27 November 2011

In this post Ayende talk about when we should use NHibernate and he point that in almost read only scenario other approach can be preferred. I think he forget to mention the fact that even in such a scenario we can leverage a very reliable multi DB abstraction offered by NH that can help us if we think to target different data platforms. In order to me we should say that the point of decision to choose fro NH to another approach is the ability to create an entity model, and an entity model helpful to our objectives. This can also depends on how much we are confortable with the technology. Another interesting extension of the argument is, if we should not  use NH what can we use instead ? Well not for sure EF, since the reason of renounce to NH in a project should be the same to avoid EF. The NOSql solutions works only if we can completely avoid a relational database, and the pure crude ADO.NET is just ugly. An option could be Dapper,  a lightweight OR/M ( not exactly an OR/M, but almost ) that remove all the ugliness of ADO.NET and does not change the performance in comparison on using the manual data access approach. I did not tried it myself, but one of its users is stackoverlow, so this should be by itself a guarantee.

Sunday, 27 November 2011 08:56:37 (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
CodeProject | NHibernate | ORM

# Saturday, 26 November 2011

I decide to publish my chess engine plays on bitbucket. Well it is almost a redo from scratch of a complete but buggy chess engine I wrote in the past that I decided to rewrite just because it was difficult to stack into the old code what I learned. The version present when I write this post contains just the move generator and the complete test for it ( I used an other nice engine: roce to compare my perft test results against. What is a perft test ? Well it is a test to prove our engine produces, from a starting board, all the possible different boards in a certain number of ply, accordingly to the chess game rules. This test also give an idea on how fast is the strategy we use to generate moves, even if this can affect just in part the overall performance of the alpha/beta pruning, we should not write a slow blobby monster. Lets see below a session of the test working:


The strange string showing the position are board situations expressed in FEN Notation, that is almost the standard notation we use to talk about board situations. How many test does FelpoII move generator passes ? Well here is the file containing the FEN boards, with the depth plies move counts shown, there is a lot of positions, even tricky and generally challenging positions ( in term of rules ).

What is the performance ? Since almost all chess engine are written in C++ or in C, can a C# engine works at the same level of magnitude of performance ? Here below the performance we have for the starting position:

Depth: 6 119060324 moves 5,34 seconds. 22283422,048 Move/s. Hash Hit=1400809

The same test with roce ( that is a C++ chess engine ):

Perft (6): 119060324, Time: 4.208 s

So almost the same, that is good if we remember that we wrote in C# Smile We just used a little hack: as you probably know ( or will know if you will start playing with chess engines development ) chess engines uses hash tables to store information about a board ( by using hashes against Zobrist Keys ) this tabled is sored in an unamanaged big memory array, this achieved a really sensible increase in performances.

Well some more details about the engine:

  • It uses a 0x88 board representation
  • It uses object oriented code ( so it is easier to understand compared to traditional C++ engines )
  • The internal random numbers for the zobrist key are generated by a Mersenne Twister Generator, that really solved some nasty bug due to wrong hash conflicts when I used the standard random algo of c#.
  • It uses a trasposition table in unmanaged memory to increase performance.
  • It has a performance comparable ( at least in move generation ) with traditional C/C++ engines


What we can do next ?

Complete the engine with a good working Negamax alpha – beta pruning algorithm.

What can we do with the code as is ?

We can use the move generator as is to validate game moves in a two human player UI, or generating fancy images from FEN positions, write a WPF ( another ) chess board ( winboard compatible? so a lot of engines are already written for it) and so on.


Saturday, 26 November 2011 10:11:13 (GMT Standard Time, UTC+00:00)  #    Comments [3] - Trackback
CodeProject | CSharp | Games

# Thursday, 17 November 2011

Even if Linq To NHibernate provider allow us to write query in a strongly type manner, it is sometimes needed to works with property names literally. For example in a RIA application a service can receive a column as a string containing the name of the property to order by. Since Linq to NHibernate is a standard Linq provider, we can leverage a standard dynamic linq parser. This is achieved by using an old code by MS, known as System.Linq.Dynamic. By following the link you will find a download location that point to an almost just a sample project that eventually contains the file Dynamic.cs that contains some extension method allowing to merge literal parts in a type safe linq query.

Let’see an example:

var elist = session.Query<MyEntity>()
              .OrderBy(“Name descending”)

I supposed we have a property called Name on the class MyEntity. The OrderBy taking a string as a parameter is an extension method provided by Dynamic.cs, and in order to have it working you just need to merge the file dynamic.cs in your project and import System.Linq.Dynamic. Of course you will have extension for Where and for other linq operators too.

Thursday, 17 November 2011 13:15:19 (GMT Standard Time, UTC+00:00)  #    Comments [5] - Trackback
CodeProject | NHibernate

# Thursday, 03 November 2011

As we know the Caliburn Micro library implements a screen conductor to handle multiple screen models with only one active, typically used for tabbed views, that is easy to implement by deriving your model from Conductor<IScreen>.Collection.OneActive. This works out of the box with the standard tab control, but it is not possible to use it for example with the tabbed documents in AvalonDock. The only solution I found, that for some reason I will say below, is this one. I don’t like this solution because it force to write code inside the view, that is not acceptable in a pure MVVM solution, so I preferred to insulate the code in an attached behavior. In addition the presented solution will works correctly with the Activate/Deactivate/CanClose strategy on each document. We just need to modify the view markup as in the example below:

As you can see we just added an attached property UseConductor.DocumentConductor that we bind to the current model. Of course the model is a OneActive screen conductor. The behavior take care to connect the document items of the DocumentPane with the screen conductor items. If each screen implements IScreen, the proper Activate/Deactivate/CanClose are called, so we can even handle the case of canceling the close of a dirty document. Here the attached behavior code: An example MainModel can be the following one:

( we just add some random document to see how it behave )

And here below an example of a single screen  model:

So we have the conductor, without touching the view code, and without creating a custom screen conductor.

Thursday, 03 November 2011 19:52:59 (GMT Standard Time, UTC+00:00)  #    Comments [6] - Trackback
Caliburn | WPF | CodeProject

# Wednesday, 02 November 2011

Sometimes when we use mapping by code we want to see the generated HBM, just to understand if all is working as expected. I did this in some my old posts by dumping the hbm with an helper method, but I simply miss that the function exists as an extension method. Here below an example:

 var compiled = mapper.CompileMappingForAllExplicitlyAddedEntities();


We simply need to include the following using:

using NHibernate.Mapping.ByCode;

Here I use the AsString method that serialize in a string the compiled mapping.
Wednesday, 02 November 2011 14:39:29 (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
NH Mapping By Code | NHibernate

# Tuesday, 01 November 2011

In order to start with Azure we need to prepare our Visual Studio with the azure SDK. Even if the Windows Azure tools for Microsoft Visual Studio is only supported by Visual Studio 2010 & Visual Studio 2010 SP1 editions, you can download a standalone SDK providing low level tools, the API ( ie the client dll ) the documentation and the samples we need for start.

So the first step is downloading the Windows Azure SDK and install it. After the installation is complete you will see this in your Server Explorer:


So the new computer and barrels painted in azure means that we have the emulators for the compute service and storage locally running, this mean we can start to try something without buy a real account in the cloud with jus few differences. First time you expand the Storage a backend for it is created under SQL Express, but you can use another SQL server instance by following these instructions.

Another gift from Visual Studio Tools are the new application templates:


This is enough to get the environment ready on.

Tuesday, 01 November 2011 08:34:48 (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
azure | cloud

My Stack Overflow

Send mail to the author(s) E-mail

profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Felice Pollano
Sign In
Total Posts: 157
This Year: 0
This Month: 0
This Week: 0
Comments: 127
This blog visits
All Content © 2019, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano
Nike Winkels Nederland Outlet Nike Nederland Store Outlet Nike Nederland 2015 Outlet Nike Outlet Online Nike Sneakers Outlet