David
David

Reputation: 2569

Libraries/Algorithms for complex if/else problems in C#

I have to implement a questionnaire engine, where each answer to a single question can end up in a completely different result.

So, if we have 10 question with 10 answers each, we'd have a 10 to the power of 10 possibilities.

This should be something like a scripted-AI i guess...

So, what kind of rule engine or implementation method would I use for a problem like this?

I guess this kind of algorithm is a little bit too straightforward?

if (x==1)
  if (y==1)
  {
    if (z==1 || z==2)
      // do sth
    if (z==3)
      // do sth different
   }

Thanks for any advice on this.

Upvotes: 2

Views: 452

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564631

There are libraries that can be used to implement this form of "rules engine".

For example, Windows Workflow Foundation allows basic rules to be determined via FlowDecision activities and other related classes.

Other alternatives are rules engines, such as Drools.Net.

That being said, for simple routines like above, I'd recommend trying to refactor your algorithm to avoid lots of criteria. By pushing this into multiple methods, you could create a series of clean conditions that would be much simpler to follow.

Upvotes: 4

Related Questions