• entries
707
1173
• views
434666

# Updated AI code

336 views

I updated the AI Attempt code, now it uses a much nicer approach. Plus, with this approach I could extend it if I wanted.

-- INACTIVE LINK REMOVED BY AUTHOR --

Hey, that's pretty cool, but mabey you could fill me in on this strange code bit:

#define StateImpl(Name)
class Name##Impl : public State
{
public:
Name##Impl() : State(#Name){}
State* Process();
};



I'm not familiar with Name##. Is it a compiler directive or something? I think I see how it works in the other files though.

Thats the token pasting operator. It takes what name is and puts it in the macro. Here's a link
Thats from the MSDN. I've tried explaining it before and I didn't do too well.

Name## isn't the operator, ## is. This puts what Name is into the macro:
#define TPOperator(WhatEver, Value) int i##WhatEver = Value;

TPOperator(MyInt, 10)
TPOperator(YourInt, 21)

// These turn into
int iMyInt = 10;
int iYourInt = 21;

Another example:
#define TPOperator(WhatEver) class C##WhatEver##Impl{};

TPOperator(State)
TPOperator(Object)

// These turn into
class CStateImpl{};
class CObjectImpl{};

I just noticed a major flaw in my design. When the person is diseased, if they don't die they just search until they find it (instead of being able to die.) I could fix this by adding more variables or a FatalSearchImpl or something, but I'm too busy working on my entry.

Also, I could replace the entire system with a simple function binding method, but I had plans to extend the functionality of the whole thing. Then I decided to just stick with the simple design and finish it.