Archive for April, 2008

Thinking about special values

Thursday, April 17th, 2008

Is it good to have something like that:

code.jpg

To me -1 or -99999 is not a good way to express absence of item. Why? Because this is syntactical level which is rather concrete - which means it could change in unexpected way.

In case the function/method would return special values it will be better to have someting like this:

code1.jpg

then:

if ( table.IndexOf(column) == -1)
{
return ColumnIndex.NullIndex;
}

Looks better, but again not perfect. This approach now using semantical differences between ordinary index and NullIndex.
Another step - distinguish special empty class:

code2.jpg

But this is also not perfect…..

WPF Tic-Tac-Toe With Script.NET AI

Friday, April 4th, 2008

Today I published a Sample game application featuring several ideas:- Windows Presentation Foundation (WPF) UI,- Script.NET language to provide AI,- Min-max algorithm for playing Tic-Tac-Toe.The purpose of the sample is to demonstrate Script.NET language as a part of more complex .NET application. These toy application implements two players (user and computer) Tic-Tac-Toe game.The design of example is preatty simple:UI interface was created with Visual Studio 2008 Express using WPF designer.WPF Tic-Tac-ToeThe game’s logic (AI) is provided by external algorithm executed with Script.NET engine. This algorithm is implemented in AI.SDN file (this file should be located in the same dir as exe file).It may be modified and improved in certain way without recompiling the application. This may be a good excercise.The .NET application provides Script.NET Engine with reference to the UI interface, so it is able to modify a view state. It is implemented via single function SetPoint( index ). The example show interaction between .NET code and Script.NET engine via shared variables (references) and IInvokable interface.Prerequesties to run the application:- Windows XP or higher- .NET framework 2.0 and 3.5