Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Voting tutorial...

 
Post new topic   Reply to topic Printable version
 View previous topic  Linkedlist Post :: Post Mervbot c->final  View next topic  
Author Message
tansey
Novice


Joined: Nov 03 2004
Posts: 53
Offline

PostPosted: Thu Feb 24, 2005 10:47 am    Post subject: Voting tutorial... Reply to topic Reply with quote

I've had several people ask me in game for how to make a bot take a vote. Since I can't spare the hours ( days ) it would take to teach people about object oriented design and then show them how my bot does it, I wrote a tutorial using only the 3 files most people use in MERV. Lemme know what you guys think:

http://www.sectionops.net/er/voting.html

--tansey
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Feb 24, 2005 11:42 am    Post subject: Reply to topic Reply with quote

Another way to do it would be to keep track of the votes using the player tags mervbot provides:

Code: Show/Hide

#define VOTING_TAG      6326
enum _VotePossibilities
{
   VOTE_Obstain,  // leave this one at the start

   // add whatever you want here
   VOTE_Dodgeball, // 1
   VOTE_Football, // 2
   VOTE_Hockey, // 3

   VOTE_Count // leave this one at the end
};

struct VoteResults
{
    int results[VOTE_Count];
};

void botInfo::vote(int value, Player *p)
{
     if (value > 0 && value < VOTE_Count);
         set_tag(p,VOTING_TAG,value);
}

void botInfo::resetVotes()
{
    for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next)
    {
        set_tag(parse->item,VOTING_TAG,VOTE_Obstain);
    }
}

VoteResults botInfo::getResults()
{
     VoteResults vr;

     for (int x = 0; x < VOTE_Count;++x)
        vr.results[x] = 0;

     for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next)
     {
         if (parse->item != me)
         {
              int vote = get_tag(parse->item,VOTING_TAG);

              vr.results[vote]++;
         }
     }

    return vr;
}



_________________
SubSpace Discretion: A Third Generation SubSpace Client


Last edited by Bak on Thu Feb 24, 2005 12:05 pm, edited 4 times in total
Back to top
View users profile Send private message Add User to Ignore List AIM Address
tansey
Novice


Joined: Nov 03 2004
Posts: 53
Offline

PostPosted: Thu Feb 24, 2005 11:55 am    Post subject: Reply to topic Reply with quote

No, I'm not. countVotes() calls votes.clear(), which blows away all the nodes in the list.
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Thu Feb 24, 2005 3:09 pm    Post subject: Reply to topic Reply with quote

I would think all you really have to do is modify the elim plugin, because it has voting built in
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Fri Feb 25, 2005 12:04 am    Post subject: Reply to topic Reply with quote

this is wrong.. way wrong. icon_lol.gif


I wasn't happy w/ something someone brought to my attention so ill post my suggested edits:

spawn.h
Code: Show/Hide
VoteResults getResults();


replace with

Code: Show/Hide
VoteResults* botInfo::getResults();


spawn.cpp
Code: Show/Hide
VoteResults* botInfo::getResults()
{
     VoteResults vr;

     for (int x = 0; x < VOTE_Count;++x)
        vr.results[x] = 0;

     for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next)
     {
         if (parse->item != me)
         {
              int vote = get_tag(parse->item,VOTING_TAG);

              vr.results[vote]++;
         }
     }

    return &vr;
}

I'm still debating whether or not to mention anything about having the linked list in a for-statement. Not that it's "wrong". Just... meh.

Example Use
Code: Show/Hide
VoteResults *vr = getResults();
int res1 = vr->results[0];

_________________
Performance is often the art of cheating carefully. - James Gosling


Last edited by CypherJF on Fri Feb 25, 2005 10:00 am, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Fri Feb 25, 2005 9:35 am    Post subject: Reply to topic Reply with quote

see the problem with that Cypher is it doesn't work. VoteResults is a declared in the scope of the function getResults. After the function the memory it used may be used for other things, so if you use a pointer to it, there's no guarentee it hasn't changed (in fact, it probably has). You could declare it on the heap and force the user to free() or delete the memory after, but I'm just as happy returning the array.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Feb 25, 2005 9:39 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide
{
VoteResults vr;

return &vr;
}


Yes. Very bad.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Fri Feb 25, 2005 9:59 am    Post subject: Reply to topic Reply with quote

oh duh me rotfl... doh doh doh haaha... i even just answered this one the one exam i just took explainin how the scope would affect such an object. tongue.gif
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Feb 25, 2005 5:11 pm    Post subject: Reply to topic Reply with quote

@Bak: That won't work if he wants to save a player's vote after he leaves.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Fri Feb 25, 2005 5:29 pm    Post subject: Reply to topic Reply with quote

@~: You're right, but if you're voting on what game the bot will host next, do you really want to use a player's vote if he or she is not going to play?

Here's a version that doesn't return the array, use would be like
Quote:

int results[VOTE_Count];
int winner = getResults(results);


Code: Show/Hide

#define VOTING_TAG      6326
enum _VotePossibilities
{
   VOTE_Obstain,  // leave this one at the start

   // add whatever you want here
   VOTE_Dodgeball, // 1
   VOTE_Football, // 2
   VOTE_Hockey, // 3

   VOTE_Count // leave this one at the end
};

void botInfo::vote(int value, Player *p)
{
     if (value > 0 && value < VOTE_Count);
         set_tag(p,VOTING_TAG,value);
}

void botInfo::resetVotes()
{
    for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next)
    {
        set_tag(parse->item,VOTING_TAG,VOTE_Obstain);
    }
}

// get the winner, and the results where results is an int array at least as big as VOTE_Count
int botInfo::getResults(int* results)
{
    int winner = 0;
    int winnerCount = 0;

     for (int x = 0; x < VOTE_Count;++x)
        (*results)[x] = 0;

     for (_listnode <Player> *parse = playerlist->head; parse; parse = parse->next)
     {
         if (parse->item != me)
         {
              int vote = get_tag(parse->item,VOTING_TAG);
              int count = (*results)[vote] + 1;
              if (count > winnerCount)
              {
                   count = winnerCount;
                   winner = vote;
              }

              (*results)[vote] = count;
         }
     }

    return winner;
}
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Feb 26, 2005 12:58 am    Post subject: Reply to topic Reply with quote

@Tansey: You might want to post that on the Wiki's example code page.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 178 page(s) served in previous 5 minutes.

phpBB Created this page in 0.531053 seconds : 35 queries executed (91.6%): GZIP compression disabled