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
Warping multiple times in a specific radius
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic Printable version
 View previous topic  Buy.ini Post :: Post Football source up for grabs....  View next topic  
Author Message
Bak
?ls -s
0 in


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

PostPosted: Thu Sep 15, 2005 12:35 am    Post subject: Reply to topic Reply with quote

don't rely on a website to do math for you. You can learn it off a website and then apply it to your problem. That's how it's meant to be done anyways
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Thu Sep 15, 2005 4:15 pm    Post subject: Reply to topic Reply with quote

Yes, Im trying to do that. I know the math, but I'm having trouble putting it in the code... I have almost no idea how to do this besides making an equation.. I'm just trying to.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Thu Sep 15, 2005 10:40 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
void PickRandomSpotInCircle(int CircleX, int CircleY, int Radius, int &XCoord, int &YCoord)
{
   double theta, r;

   r = (double)rand() / RAND_MAX * Radius;
   theta = (double)rand() / RAND_MAX * 6.28319; /* aka: 2pi */

   XCoord = (int)(r * cos(theta)) + CircleX;
   YCoord = (int)(r * sin(theta)) + CircleY;
}
Back to top
View users profile Send private message Add User to Ignore List Send email
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Thu Sep 15, 2005 11:03 pm    Post subject: Reply to topic Reply with quote

is that a built in function?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Thu Sep 15, 2005 11:04 pm    Post subject: Reply to topic Reply with quote

ty for the help icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 3:07 pm    Post subject: Reply to topic Reply with quote

hey lol id you make that up yourself? looks cool lol seriously tongue.gif im looking up some things in that code to learn how it works hehe
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Bak
?ls -s
0 in


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

PostPosted: Fri Sep 16, 2005 3:42 pm    Post subject: Reply to topic Reply with quote

(shakes head)

stop triple posting. And only post relevant things, not "cool"
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 3:49 pm    Post subject: Reply to topic Reply with quote

lol sorry









(oops i did it again :/ )
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 5:28 pm    Post subject: Reply to topic Reply with quote

um.. im supposed to fill in the coords and stuff right?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Muskrat
Server Help Squatter


Age:38
Joined: Aug 24 2004
Posts: 829
Location: Swamp
Offline

PostPosted: Fri Sep 16, 2005 5:47 pm    Post subject: Reply to topic Reply with quote

That would have been a perfect opportunity to use the edit button.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Fri Sep 16, 2005 11:10 pm    Post subject: Reply to topic Reply with quote

Quan Chi2 wrote:
hey lol id you make that up yourself? looks cool lol seriously :P im looking up some things in that code to learn how it works hehe

Yes. A simple google search on polar to rectangular returned the exact math you needed. The original idea is what I posted back in my first message in this thread.
Quan Chi2 wrote:
um.. im supposed to fill in the coords and stuff right?

You'll need fill in three values, CircleX, CircleY, and Radius. These should be known values of the circle you want to warp into, as that is what you mentioned in the very first post. The XCoord and YCoord doesn't need to be set to anything, as the function sets the return values there.

Example usage:
int x,y;
PickRandomSpotInCircle(512, 512, 10, x, y);
sendMessage(playerID, "*warpto %d %d", x, y);

The sendMessage is different for each bot core. I don't use MERV at all, thus I don't know if it supports formatting or you guys just use the string class everywhere.
Back to top
View users profile Send private message Add User to Ignore List Send email
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Fri Sep 16, 2005 11:25 pm    Post subject: Reply to topic Reply with quote

ok.. i see what you're saying. in the first post i just didnt understand. i had done a google search on polar to rectangular but i didnt understand the math.. not quite at that level yet tongue.gif Thank you very much for the help
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Sun Sep 18, 2005 9:12 pm    Post subject: Reply to topic Reply with quote

Sample Code to warp pilot within a box size area
Code: Show/Hide

#include "time.h"

// do   srand(time(NULL));   when the bot logins or just once at any point before rand(); is called

void botInfo::PutPilotInGame(Player *p)
{
   // warp pilot into game, 100 square area from coordinate 450,450
   rand();

   int coordx = 450;
   int coordy = 450;

   coordx = (int) (100 * ((float)rand()/RAND_MAX)) + 450;
   coordy = (int) (100 * ((float)rand()/RAND_MAX)) + 450;

   // warpto
   sendPrivate(p,"*warpto " + (String) coordx + " " + (String) coordy);
}
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: Sun Sep 18, 2005 10:16 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
100 * ((float)rand()/RAND_MAX)

is equivilent to
Code: Show/Hide
rand() % 100


but I think mod is faster than division and multiplication.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:42
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sun Sep 18, 2005 10:48 pm    Post subject: Reply to topic Reply with quote

rand() is not a truly random number. The high-order bits are requested to be more random than the lower bits by the official standard. For the most part, most system's rand() is good enough that you can just mod the number you want, but to get a more random number, you should use the high-order bits, which involves using the methods Underlord and I both posted.

Doing a quick test on the standard deviation of rand() on different amounts with different sample sets shows that both methods on Windows 2000's stdlib work almost identical. On other system's implementation of rand, it maybe different.

And in the case of speed, the bot is usually not trying to be real-time, and spends most of its time idling. So in this case, its better to error on the side of more accurate than speed. And in the case where you are using the string class, the speed between these methods is the least of your worries.
Back to top
View users profile Send private message Add User to Ignore List Send email
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Wed Sep 21, 2005 4:48 am    Post subject: Reply to topic Reply with quote

Quote:
Do NOT use

y = rand() % M;

as this focuses on the lower bits of rand(). For linear congruential random number generators, which rand() often is, the lower bytes are much less random than the higher bytes. In fact the lowest bit cycles between 0 and 1. Thus rand() may cycle between even and odd (try it out). Note rand() does not have to be a linear congruential random number generator. It's perfectly permissible for it to be something better which does not have this problem.
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: Wed Sep 21, 2005 11:47 pm    Post subject: Reply to topic Reply with quote

learn something new every day...

This actually came up a day after reading MGB's responce. I made a c program for a microcontroller and it was supposed to chose a random color for a bi-color LED, red or green. However, it chose red 95% of the time. Thinking about what mgb said, I changed
Code: Show/Hide
rand() % 2

to
Code: Show/Hide
(rand() % 10000) / 5000

and it finally started picking green a lot more. Funny how this doesn't come up in years of programming until the day after someone tells it to you. Another option I was considering was to load an array with like 5 red and 5 green values, then doing a random shuffle on the data, so for any 10 tries you'd get 5 reds and 5 greens, but the order would be random.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Thu Sep 22, 2005 10:39 am    Post subject: Reply to topic Reply with quote

On all of the uCs I've programmed there hasn't been a rand() so I've always had to write my own psudeo-random number generator. Usually just a shift and xor does the trick.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Sat Sep 24, 2005 12:43 am    Post subject: Reply to topic Reply with quote

why did Underlord include time.h?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sat Sep 24, 2005 12:51 am    Post subject: Reply to topic Reply with quote

Probably because he used a function in time.h. Just a guess...
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Sat Sep 24, 2005 1:17 am    Post subject: Reply to topic Reply with quote

lol.. funny
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Bak
?ls -s
0 in


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

PostPosted: Sat Sep 24, 2005 4:11 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide
// do   srand(time(NULL));   when the bot logins or just once at any point before rand(); is called


time() is defined in time.h
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Maverick
broken record


Age:41
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Sun Oct 23, 2005 10:30 am    Post subject: Reply to topic Reply with quote

I would like to add to this topic that I have found a topic in another forum where this exact topic is discussed. Also MGB's code is discussed there.

http://gamedev.net/community/forums/topic.asp?topic_id=72305

It comes down to that MGB's code doesn't completely work (picks points to the center too much) and the following code does work:

(too bad the picture in the thread is gone)

Code: Show/Hide
#include <stdlib.h>
#include <time.h>
#include <math.h>

/* Call this somewhere */
srand(time(NULL));

/* Later on (Angle is in radians) */
int X, Y;
double Angle, Mag;

Angle = (rand()/RAND_MAX)*6.283185307;
Mag = sqrt(((float)rand())/(float)RAND_MAX)*radius;

X = (int)(cos(Angle) * Mag);
Y = (int)(sin(Angle) * Mag);

_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Quan Chi2
Member of "Sexy Teenagers that Code" Group
Member of


Age:35
Gender:Gender:Male
Joined: Mar 25 2005
Posts: 860
Location: NYC
Offline

PostPosted: Sun Oct 23, 2005 8:02 pm    Post subject: Reply to topic Reply with quote

I tried..


Code: Show/Hide

   case OP_Player:
      {   // Player-level commands
         if (c->check("about"))
         {
            sendPrivate(p, "I am a plain vanilla flavored bot.  Yup, just as plain and useless as can be.");
         }
         if (c->check("confuse"))
         {
            srand(time(NULL));

            int X, Y;
            double Angle, Mag;

            Angle = (rand()/RAND_MAX)*6.283185307;
            Mag = sqrt(((float)rand())/(float)RAND_MAX)*10;

            X = (int)(cos(Angle) * Mag);
            Y = (int)(sin(Angle) * Mag);
            {
               String s;
               s += "*warpto";
               s += " X Y";
               sendPrivate(p, s.msg);
               sendPrivate(p, "You have dodged your opponents weapons!  Now go for the kill!");
            }
         }
      }
   }
}


I think I made a good attempt though icon_smile.gif

It does the message but it doesnt do the warp.. anything wrong?
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sun Oct 23, 2005 8:41 pm    Post subject: Reply to topic Reply with quote

Yes, your bot will say exactly (no replacement) "*warpto X Y" The server doesn't know how to warp a player there.
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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: 44 page(s) served in previous 5 minutes.

phpBB Created this page in 0.460828 seconds : 49 queries executed (90.0%): GZIP compression disabled