Pathfinding and environmental awareness

We’ve produced a very short devlog about the pathfinding / environmental awareness part of the AI development process for Virtual Warfighter. It describes how we’ve solved the problem of allowing AI soldiers to make different pathfinding choices, more intelligent than just take the shortest path.

We will probably expand upon this in the future by describing more, such as how to make the AI avoid exposed routes in favor of more concealed ones, if possible.

All this is part of the work being done for our upcoming coop game mode.

Advertisements changes UI daily

Whats going on with We use it for issue tracking, version control and as a general CI platform. They literary change the UI every week and even daily. It’s very frustrating that you can not be granted to learn the UI and become efficient with it before they change it partially or entirely.

Microsoft, if you read this, continuous delivery is great but changing the UI at this rate is not productive for anyone.

</rant over>

Z-Wave – A system architects view

I’ve been looking into smart home systems lately. Z-Wave seemed like a popular choice and I liked the possible scenarios you could achieve with it. So I have played around with it for a few days now, and my final verdict on it, looking through my system architect eyes is that the entire thing must been developed by hackers, at least the software stack. Let me tell you why… (more…)

Virtual Warfighter

We have been working on a product of our own for the past months, a game for the OpenVR platform (HTC Vive, etc). The game will release this Friday, please check it out here!

Also I might once in a while write game/VR related blogs here, but its still mainly a blog about enterprise business code bases.

SQL CE and namespaces

We use SQL CE in our unit test project to test our EF6 queries. This works pretty well and Code first setup makes sure each test gets a fresh CE database to work with.

We ran into a problem where two EF types had the same table name but inside different schemas. CE does not support schemas and this resulted in naming conflicts when setting up database. My solution was to create a little convention.

public class BakeSchemaIntoTableNameConvention : IStoreModelConvention<EntityType>
    public void Apply(EntityType item, DbModel model)
        var entitySet = model.StoreModel.Container.EntitySets.Single(es => es.ElementType == item);
        entitySet.Table = $"{entitySet.Schema}_{entitySet.Table}";

It bakes the schema into the table name like dbo_MyTable. You add the convention like.

protected override void OnModelCreating(DbModelBuilder modelBuilder)

    modelBuilder.Configurations.AddFromAssembly(typeof (MyContext).Assembly);

You do not want to add this for production code so what I did was create a public event on the context. And call it from the OnModelCreating method.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    ModelCreating?.Invoke(this, modelBuilder);

    modelBuilder.Configurations.AddFromAssembly(typeof (MyContext).Assembly);

Call it from your Unittest project like.

ctx.ModelCreating += (s, e) => e.Conventions.Add<BakeSchemaIntoTableNameConvention>();

Microsoft.Rest.ServiceClient opt out retry

If you use Swagger generated REST proxies then you have probably come across the pretty new Microsoft.Rest namespace and namely the abstract class ServiceClient. I noticed a strange behavior when using clients that subclass this base class. The default behavior for this class is to retry when a 500 status code is returned.
I can not understand the reason for this being Opt out, its obvious a feature like this should be Opt in. So keep in mind when using this class you must always call SetRetryPolicy to disable the retry strategy.

var service = new MyService(uri, credentials);
service.SetRetryPolicy(new RetryPolicy(new HttpStatusCodeErrorDetectionStrategy(), 0));

Task.WhenAny with take predicate

Not a very common scenario but still it happens, you want to execute a request to several Services, and only one has the correct data. The built in Task.WhenAny only supports to await the first Task complete. That wont do if you want to wait for the first Task to complete that satisfy a specific condition.

Nito.AsyncEx is a helper library for Task programming, it comes with an extension method called OrderByCompletion. It takes a collection of Task<T> and return a new collection that will be ordered on completion status. Using this method its a simple task to create a WhenAny based on a predicate.

public async static Task<TResult> First<TResult>(this IEnumerable<Task<TResult>> source, Predicate<TResult> predicate)
    var ordered = source

    foreach (var task in ordered)
        var result = await task;
        if (predicate(result)) return result;

    throw new Exception("Sequence contains no matching element");

Used like

var result = await services
   .Select(s => s.GetFooAsync())
   .First(f => f.IsSuccess);

Mini test suite for async CQS backend

Our backend consists of a WebApi backend sporting an async CQS API (Not involving Event sourcing). I wanted a fluent syntax setup for our scenario tests, here is an actual example from the resulting code. (Code removed that are customer specific)

public class When_doing_a_complete_booking : BusinessTest
	private Booking _result;
	private DateTime _date;

	public void Context()
		Guid bookingKey = Guid.Empty;
		_date = DateTime.Now.AddDays(5);

		_result = Given(db => /* Setup here */)
			.When(() => new SearchQuery{ Date = _date, ...})
			.And(result =>
				bookingKey = result.First().BookingKey;
				return new ReserveCommand { BookingKey = bookingKey, ... };
			.And(() => new ConfirmCommand
				BookingKey = bookingKey, 
			.Then(db => db.Set<Booking>().FirstOrDefaultAsync(b => b.BookingKey == bookingKey));

	public void It_should_book_correctly ()


Client server event aggregation with Angular

I dont fancy Angular much, its slow and Knockout with its MVVM approach is much cleaner, and faster since computed and observables only mutate and change view state when they actually need to (That will change with Angular 2.0). Anyway, my current customer sports Angular and then you just have to form inline 😀 We needed immediate update and you know I love event aggregation and probably know that I have a library for it, you can read more about it here!

I created a little wrapper for the the vanilla javascript client, install it using nuget
Install-Package SignalR.EventAggregatorProxy.Client.Angular

Basically it works by extending the Angular $rootScope and adds a eventAggregator function to all scopes. The eventAggregator function resolves the scope and then creates a closure with two methods, subscribe and publish. You can now listen to a event like (Serverside or client side event).

$scope.eventAggregator().subscribe(MyApp.MyEvent, onEvent);