.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   joebot xp code released (http://forums.bots-united.com/showthread.php?t=3376)

@$3.1415rin 09-01-2005 21:05

joebot xp code released
 
quote from http://joebot.bots-united.com

January 8th, 2005

Happy new year everyone. Currently most of the bot developers here at bots united are working on bots for HL2 based mods. If you wanna see what's currently been worked on look here.

And I have a little christmas present for you. Since some of us are working on engine indep parts of the bot code, and it's often not published, I decided to upload the source for those who are interested. you can download it here. But this code isnt by far finished :)

/@$3.1415rin

stefanhendriks 09-01-2005 22:07

Re: joebot xp code released
 
w00t w00t w00t. Another code release! :D

Pierre-Marie Baty 09-01-2005 22:37

Re: joebot xp code released
 
yay, downloading now. I bet there are lots of cool stuff inside :P

@$3.1415rin 09-01-2005 22:48

Re: joebot xp code released
 
i already talked about stefan about this. We were all working on some engine indep stuff. and then I think it's only logical to make this stuff public. For the United Bot we have to agree on something and then it's nice to know some alternatives.

stefanhendriks 09-01-2005 23:30

Re: joebot xp code released
 
yes. Knowing several methods is better and it also gives you a feeling how it will be if you work with such a style of programming ;) (or design)... :D

Pierre-Marie Baty 10-01-2005 05:48

Re: joebot xp code released
 
er, asp... your zip is corrupt it seems :|

Cpl. Shrike 10-01-2005 10:40

Re: joebot xp code released
 
Zip works for me.

Pierre-Marie Baty 10-01-2005 14:51

Re: joebot xp code released
 
strange...
if I download it using my download manager, the archive is corrupt (I tried twice), but if I download it using the IE download box, it works. Bah, nevermind. Sorry for the fuss.

Zacker 10-01-2005 19:08

Re: joebot xp code released
 
Very nice with yet another quality bot going open source!

Quote:

Originally Posted by Pierre-Marie Baty
strange...
if I download it using my download manager, the archive is corrupt (I tried twice), but if I download it using the IE download box, it works. Bah, nevermind. Sorry for the fuss.

Same problem here, except that it was the Mozilla download manager which worked;)

@$3.1415rin 10-01-2005 19:22

Re: joebot xp code released
 
Quote:

Originally Posted by Zacker
Very nice with yet another quality bot going open source!


Same problem here, except that it was the Mozilla download manager which worked;)

well, half - open source, because the development will be still closed source I guess. It doesnt make much sense at the moment to work with others on the main part of the code, becausae I havnt published / written down all the ideas I wanna implement.

about downloading ... opera downloads it fine, IE does, ... but everybody has a valid zip file now ?!

dub 10-01-2005 21:02

Re: joebot xp code released
 
nice code & getright worked fine.

Black_Hunter 10-01-2005 22:43

Re: joebot xp code released
 
can someone compile the src i wanna test it????

Cpl. Shrike 12-01-2005 18:10

Re: joebot xp code released
 
We could, but it's up to aspirin to release a binary for public test.

But i think he did only the source because he's not quite finished with it.


Quote:

Quote @$3.1415rin
well, half - open source, because the development will be still closed source I guess. It doesnt make much sense at the moment to work with others on the main part of the code, becausae I havnt published / written down all the ideas I wanna implement.


stefanhendriks 12-01-2005 18:35

Re: joebot xp code released
 
i can't help it, but i really have to laugh about all those Astar files... rofl. My own astar routine is like 40 lines of code at max; its even in the UBBOT frame work alpha , which i released on the SDK 2 board...

though, yours is way more object oriented and written in coolish C++ class style... :P

@$3.1415rin 12-01-2005 19:32

Re: joebot xp code released
 
well, there is also this AStarTaskManager, which does the slicing to avoid lags when having to calculate for a long time ... and it's sort of plugin based, you can write a "plugin" for differerent heuristics / costs, therefore there's another .cpp and .h ... maybe I should put all those 'plugins' into one file :)

about releasing binaries ... well, you can compile it, you can play with the bots, but there's still a lot not complete, like team level task coordination, or even nonrandom navigation, so I havnt released anything yet. The basis for all those things is set, but i'm too busy with other stuff at the moment.

btw, about that object oriented ( at least a bit ) stuff : I wanted to implement this correction for moving targets with that old aiming algorithm, and well, in old joebot it's quite more complicated than I thought. in 'JoebotXP' all that relevant stuff is in one class, and there shouldnt be direct changes on the variables from the outside, so implementing new aiming there was really easy :)

€: changed the memorypool.h in the archive, the free function was just returning without doing anything :D

Whistler 13-01-2005 08:03

Re: joebot xp code released
 
I had errors while compiling it, not sure if this "Destroy" is M$ specific thing:
Quote:

Originally Posted by GNU C++ Compiler 2.95
g++ -march=i586 -O2 -D__JOEBOTXPDLL=1 -D__HLENGINE=1 -I../hlsdk -I../dlls -I../
NNSim -I../NNSim/SOM -c BaseBot.cpp -o BaseBot.o
BaseBot.cpp: In method `CBaseBot::~CBaseBot()':
BaseBot.cpp:58: `Destroy' undeclared (first use this function)
BaseBot.cpp:58: (Each undeclared identifier is reported only once
BaseBot.cpp:58: for each function it appears in.)
BaseBot.cpp:58: parse error before `*'
BaseBot.cpp:59: parse error before `*'
make: *** [BaseBot.o] Error 1


@$3.1415rin 13-01-2005 17:13

Re: joebot xp code released
 
havnt compiled it for some time on a gcc, but that Destroy stuff is already pretty old, so I havnt changed much there. it isnt btw anything M$ specific, plain C++, just look it up in the util.h

i'm gonna check that, thx

Whistler 14-01-2005 04:07

Re: joebot xp code released
 
I changed to GCC 3.4.3 and it worked with some other changes to the bot :)
looks like it's FSF's fault

Pierre-Marie Baty 14-01-2005 06:05

Re: joebot xp code released
 
shhhh... don't give people the club to beat you like that (well, unless you insist :P)

Whistler 14-01-2005 06:56

Re: joebot xp code released
 
well it's already *FIXED* in the latest version so it's okay now :D

Whistler 14-01-2005 14:49

Re: joebot xp code released
 
here's some errors I've seen in the code:

- Single-player fix not applied correctly. This isn't important for CS bots, but as this new version of Joebot supports Half-Life it's important now :)
PHP Code:

unsigned long pfnFunctionFromName( const char *pName )
{
#ifdef DEBUGENGINE
    
if (debug_engine) { fp=fopen("bot.txt","a"); fprintf(fp,"pfnFunctionFromName:\n"); fclose(fp); }
#endif
    
return (*g_engfuncs.pfnFunctionFromName)(pName);
}
const 
char *pfnNameForFunctionunsigned long function )
{
#ifdef DEBUGENGINE
    
if (debug_engine) { fp=fopen("bot.txt","a"); fprintf(fp,"pfnNameForFunction:\n"); fclose(fp); }
#endif
    
return (*g_engfuncs.pfnNameForFunction)(function);


...if use this those ones in namefunc.cpp won't be used. You also need to change this to:

PHP Code:

unsigned long pfnFunctionFromName( const char *pName )
{
#ifdef DEBUGENGINE
    
if (debug_engine) { fp=fopen("bot.txt","a"); fprintf(fp,"pfnFunctionFromName:\n"); fclose(fp); }
#endif
    
return FUNCTION_FROM_NAME(pName);
}
const 
char *pfnNameForFunctionunsigned long function )
{
#ifdef DEBUGENGINE
    
if (debug_engine) { fp=fopen("bot.txt","a"); fprintf(fp,"pfnNameForFunction:\n"); fclose(fp); }
#endif
    
return NAME_FOR_FUNCTION(function);


- Server_GetBlendingInterface() not exported
PHP Code:

DLLEXPORT Server_GetBlendingInterface(int version,
        
struct sv_blending_interface_s **ppinterface,
        
struct engine_studio_api_s *pstudio,
        
float (*rotationmatrix)[3][4],
        
float (*bonetransform)[MAXSTUDIOBONES][3][4]) 


this has the same bug as which Jozef Wagner pointed out to PMB. look at the RACC forum for "Bug in RACC Template 2".
the correct one is:
PHP Code:

extern "C" EXPORT int Server_GetBlendingInterface(int version,
        
struct sv_blending_interface_s **ppinterface,
        
struct engine_studio_api_s *pstudio,
        
float (*rotationmatrix)[3][4],
        
float (*bonetransform)[MAXSTUDIOBONES][3][4]) 


Note: to use the EXPORT macro should #include util.h and cbase.h


also this one:
PHP Code:


class CBitField  
{
public:
    
friend class CBitProxy;
    
friend class CBFIterator;

    class 
CBitProxy
    
{
    public:
        
CBitProxy(CBitField &array, long pos):m_Array(array), m_Pos(pos){}
        
        
CBitProxy &operator=(bool value){
            
m_Array.setBit(m_Posvalue);
            return *
this;
        }

        
CBitProxy &operator=(const CBitProxy &that){
            
m_Array.setBit(m_Posthat.m_Array.getBit(that.m_Pos));
            return *
this;
        }

        
operator bool() const{
            return 
m_Array.getBit(m_Pos);
        }
    private:
        
CBitField    &m_Array;
        
long        m_Pos;
    };

    
// a iterator class for bitfields ... the typedef shit is just because there is somewhere an iterator
    // struct in std ... so we had to do something to stop the compiler nagging around
    
typedef class CBFIterator{
    public:
        
CBFIterator(){
            
m_pBField 0;
        }
        
CBFIterator(const CBFIterator &P){
            
m_lBit P.m_lBit;
            
m_lOffset P.m_lOffset;
            
m_lPos P.m_lPos;
            
m_pBField P.m_pBField;
        }
        
// calculate offset and bit from m_lPos
        
void calcPos(void){
            
m_lOffset m_lPos / (sizeof(long) * 8);
            
m_lBit m_lPos m_lOffset * (sizeof(long) * 8);
        }
        
// set pointer to new Bitfield and reset counter
        
void initialize(CBitField &PBitField){
            
m_lPos 0;
            
m_pBField = &PBitField;
            
// calcPos();        // doing this directly might be faster
            
m_lOffset 0;
            
m_lBit 0;
        }
        
// set iterator to some position
        
void setPos(long lPPos){
            
m_lPos lPPos;
            
calcPos();
        }
        
// where are we
        
long getPos(void){
            return 
m_lPos;
        }
        
// read the bit there
        
bool getBit(void){
            
assert(inRange());

            
long lSet;

            
lSet m_pBField->m_plData[m_lOffset];
            
lSet>>=m_lBit;

            return (
lSet&1);
        }
        
// only predecrement ... is postdecrement really needed ?!
        
const CBFIterator operator ++(){
            
m_lPos ++;
            
m_lBit ++;
            if(
m_lBit >= (sizeof(long) * 8)){
                
m_lBit 0;
                
m_lOffset ++;
            }
            return ((const 
CBFIterator &)(*this));
        }
        
// check if the iterator is still valid
        
bool inRange(void){
            if(
m_lPos m_pBField->m_lBits)
                return 
true;
            return 
false;
        }

        
CBFIterator &operator =(CBitField &bitfield){
            
initialize(bitfield);

            return ((
CBFIterator &)(*this));
        }
        
/*~CBFIterator(){
        }*/
    
private:
        const 
CBitField *m_pBField;

        
long m_lPos;
        
long m_lOffset;    // at which element of the array are we ?!
        
long m_lBit;    // and which bit ?
    
}bf_iterator;

    
CBitField(){
        
// nothing here yet
        
m_plData 0;
        
m_lBits 0;
    }

    
CBitField(long lBits){    // we want a bitfield with lBits bits please
        
long lSize lBits/sizeof(long)/8+1;

        
m_plData = new long[lSize];
        
m_lBits lBits;
        
memset(m_plData,0,sizeof(long)*lSize);
    }

    
CBitField(const CBitField &param){        // heyho, just copy that
        
long lSize param.m_lBits sizeof(long) / 1;

        
m_plData = new long[lSize];
        
m_lBits param.m_lBits;

        
memcpy(m_plData,param.m_plData,sizeof(long)*lSize);
    }
    
virtual ~CBitField();

    
void load(FILE *);
    
void save(FILE *);

    
long bits(void){
        return 
m_lBits;
    }

    
void setBit(long lBit,bool bSet){
        
// set a bit ... or delete it
        
assert(lBit m_lBits);

        
long lIndex,lShift,lSet;

        
lIndex lBit / (sizeof(long) * 8);
        
lShift lBit lIndex * (sizeof(long) * 8);

        
lSet = (1<<lShift);

        if(
bSet){
            
m_plData[lIndex] |= lSet;
        }
        else{
            
m_plData[lIndex] &=~ lSet;
        }
    }

    
void zero(void){
        
// reset the whole bitfield
        
long lSize m_lBits/sizeof(long)/8+1;

        
memset(m_plData,0,sizeof(long)*lSize);
    }

    
bool getBit(long lBit) const{
        
// read some bit
        
assert(lBit m_lBits);
        
long lIndex,lShift,lSet;

        
lIndex lBit / (sizeof(long) * 8);
        
lShift lBit lIndex * (sizeof(long) * 8);

        
lSet m_plData[lIndex];
        
lSet>>=lShift;

        return (
lSet&1);
    }

    
void negate(void){
        
// true <=> false for each entry
        
long l,lMax;

        
lMax m_lBits sizeof(long) / 1;

        for(
l=0;lMaxl++){
            
m_plData[l] = ~m_plData[l];
        }
    }

    
/*CBitField operator~(){
    CBitField ret;

    ret = *this;

    ret.negate();

    return ret;
    }*/

    
CBitField &operator &= (const CBitField &param){
        
long l,lMax;
        if(
m_lBits<=param.m_lBits){                    // take the smallest bitfield
            
lMax m_lBits sizeof(long) / 1;
        }
        else{
            
lMax param.m_lBits sizeof(long) / 1;
        }
        for(
l=0;lMaxl++){
            
m_plData[l] &= param.m_plData[l];
        }
        return ((
CBitField &)(*this));
    }

    
CBitField &operator |= (const CBitField &param){
        
long l,lMax;
        if(
m_lBits<=param.m_lBits){                    // take the smallest bitfield
            
lMax m_lBits sizeof(long) / 1;
        }
        else{
            
lMax param.m_lBits sizeof(long) / 1;
        }
        for(
l=0;lMaxl++){
            
m_plData[l] |= param.m_plData[l];
        }
        return ((
CBitField &)(*this));
    }

    
CBitField &operator ^= (const CBitField &param){
        
long l,lMax;
        if(
m_lBits<=param.m_lBits){                    // take the smallest bitfield
            
lMax m_lBits sizeof(long) / 1;
        }
        else{
            
lMax param.m_lBits sizeof(long) / 1;
        }
        for(
l=0;lMaxl++){
            
m_plData[l] ^= param.m_plData[l];
        }
        return ((
CBitField &)(*this));
    }

    
CBitField &operator = (const CBitField &param){
        
// copy data from parameter to here
        
long lSize param.m_lBits sizeof(long) / 1;
        if(
param.m_lBits != m_lBits){
            
delete [] m_plData;
            
m_plData = new long[lSize];
            
m_lBits param.m_lBits;
        }
        
memcpy(m_plData,param.m_plData,sizeof(long)*lSize);

        return ((
CBitField &)(*this));
    }

    
CBitField &partialCopy(const CBitField &param){
        
long lIndex;
        if(
param.m_lBits == m_lBits){                                // sizes are the same ...
            
lIndex param.m_lBits / (sizeof(long) * 8)+1;            // only copy the data
            
memcpy(m_plData,param.m_plData,sizeof(long)*lIndex);
        }
        else if(
param.m_lBits m_lBits){                            // copy only the data that fits in there
            
lIndex m_lBits / (sizeof(long) * 8)+1;
            
memcpy(m_plData,param.m_plData,sizeof(long)*lIndex);
        }
        else{                                                        
// copy as much as possible
            
lIndex param.m_lBits / (sizeof(long) * 8)+1;
            
memcpy(m_plData,param.m_plData,sizeof(long)*lIndex);
            
/*
            lIndex = param.m_lBits / (sizeof(long) * 8);
            memcpy(m_plData,param.m_plData,sizeof(long)*lIndex);
            for(long lschl = lIndex * sizeof(long) * 8; lschl < param.m_lBits; lschl ++){
                setBit(lschl,param.getBit(lschl));
            }*/
        
}
        
//m_lBits = param.m_lBits;
        
return ((CBitField &)(*this));
    }

    
bool operator == (const CBitField &param){
        
// check sizes
        
if(param.m_lBits != m_lBits)
            return 
false;

        
// dont rely on getBit here, it's too slow

        
long lSizeFull param.m_lBits sizeof(long) / 8;

        
// check first bytes
        
for(long l lSizeFull 2>= 0l--){
            if(
m_plData[l] != param.m_plData[l])
                return 
false;
        }
        
// and check if there are the last bits still unchecked bits at the end
        
long lUnchecked m_lBits lSizeFull*sizeof(long)*8;
        if(!
lUnchecked)        // no more bits to check
            
return true;

        
long lMask 0;        // first the mask is 0

        /*for(;lUnchecked > 0;lUnchecked--){
            lMask <<= 1;
            lMask |= 1;
        }*/
        
lMask 1;
        
lMask <<= lUnchecked;
        
lMask --;

        
// lSizeFull-1 is last element of the array
        
if((m_plData[lSizeFull-1]&lMask) != (param.m_plData[lSizeFull-1]&lMask))
            return 
false;

        return 
true;
    }

    
bool operator != (const CBitField &param){
        return !(*
this == param);
    }

    
CBitProxy operator[](long pos){
        
assert(pos>-&& pos m_lBits);
        return 
CBitProxy(*thispos);
    }

    const 
CBitProxy operator[](long pos) const{
        
assert(pos m_lBits);
        return 
CBitProxy(const_cast<CBitField &>(*this), pos);
    }

    
long getSet(void){        // just return an index to a bit which is set
        
long lSizeFull m_lBits sizeof(long) / 8;
        
long lStart 0;
        for(
lStart 0;lStart lSizeFulllStart ++){
            if(
m_plData[lStart])
                break;
        }
        if(
lStart != lSizeFull){
            
lStart *= (sizeof(long)*8);
            
/*for(;lStart < m_lBits; lStart ++){
                if(getBit(lStart))
                    return lStart;
            }*/
            
bf_iterator iter;
            
iter.initialize(*this);
            
iter.setPos(lStart);
            while(
iter.inRange()){
                if(
iter.getBit())
                    return 
iter.getPos();
                ++
iter;
            }
        }
        return -
1;
    }

    
long countSet(void){        // just return an index to a bit which is set
        
long lCount 0;

        
bf_iterator iter;
        
iter.initialize(*this);
        while(
iter.inRange()){
            if(
iter.getBit())
                
lCount ++;
            ++
iter;
        }
        return 
lCount;
    }

    
void setSize(long lNewBits){
        if(
lNewBits == m_lBits)
            return;

        
long lSize lNewBits sizeof(long) / 1;

        
delete [] m_plData;
        
m_lBits lNewBits;
        
m_plData = new long[lSize];
    }

private:
    
long *m_plData;
    
long m_lBits;
}; 

... doesn't compile fine with MSVC 6.0 and GCC 2.95 due to bugs in the compilers, it only works with GCC 3.4.3. They just complains "can't access private member" so perhaps you can move the 2 classes out or remove the "private:" before the last 2 variables.

@$3.1415rin 14-01-2005 15:04

Re: joebot xp code released
 
thx for pointing out that errors / glitches. havnt bothered much with engine interface functions since I initially wanted to port it to metamod anyway and as long as it works it's fine. The little time I currently have, I better like to spend on higher level problems :)

which one of that private is causing errors and in which function ? maybe you could post or pm just that error log. moving that classes out of there won't be much help I guess.

Whistler 15-01-2005 02:22

Re: joebot xp code released
 
--------------------Configuration: bot - Win32 Debug--------------------
Compiling...
AStarGoalHide.cpp
d:\jbxp124\dlls\bitfield.h(82) : error C2248: 'm_plData' : cannot access private member declared in class 'CBitField'
d:\jbxp124\dlls\bitfield.h(390) : see declaration of 'm_plData'
d:\jbxp124\dlls\bitfield.h(99) : error C2248: 'm_lBits' : cannot access private member declared in class 'CBitField'
d:\jbxp124\dlls\bitfield.h(391) : see declaration of 'm_lBits'
Error executing cl.exe.

AStarGoalHide.obj - 2 error(s), 0 warning(s)

@$3.1415rin 18-01-2005 15:09

Re: joebot xp code released
 
ok, thx

since server-one is down for maintenance, the url isnt working. try http://filebase.bots-united.com/inde...on=file&id=261 instead


All times are GMT +2. The time now is 05:17.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.