What are you working on? V4 (HTML ISN'T PROGRAMMING)
2,003 replies, posted
[QUOTE=TehDoomCat;18098251]stuff[/QUOTE]
gravity you say, I did that in 3d a while back
you can do something like this: (pseudocode)
[code]
//object is the thing being affected by gravity
difference = normalisedVector2(gravitySource.origin - object.origin);
distance = distancev2(gravitySource.origin, object.origin);
distance *= distance; //square it
object.momentum += difference * (arbitraryValue / distance);
[/code]
then add the objects momentum to its origin
[b]edit:[/b] post count
[QUOTE=NovembrDobby;18098488]gravity you say, I did that in 3d a while back
you can do something like this: (pseudocode)
[code]
//object is the thing being affected by gravity
difference = normalisedVector2(gravitySource.origin - object.origin);
distance = distancev2(gravitySource.origin, object.origin);
distance *= distance; //square it
object.momentum += difference * (arbitraryValue / distance);
[/code]
then add the objects momentum to its origin
[b]edit:[/b] post count[/QUOTE]
Okay, I don't get that...
In a 2D space, what's the difference between... well, an objects origin subtracted from another, and their distance apart?
'distancev2' sounds like a function which returns the difference between two objects' origins as it is...
Also, is this point gravity? I was going for 'fall to the floor' gravity, but then I changed my mind and decided I wanted it to be point gravity 'cause I could develop on it...
[QUOTE=Giraffen93;18098377][media]http://www.youtube.com/watch?v=f4pp7AbaNKM[/media]
Better video.[/QUOTE]
Not sure what you're showing us.
[QUOTE=gngbng;18097567]how are you parsing incoming irc commands? my php irc class using some god awful regex that breaks half the time for god knows what reason.[/QUOTE]
[lua]
function ircm:Think( )
-- Thanks to RabidToaster for showing me how my parsing was carp
local read = self.Socket:receive( "*line" )
if not read then
return
end
local split = explode( " ", read )
local prfx, user, cmd, args, optfarg = "", "", "", "", ""
if #split < 2 then
return
end
for k,v in pairs( split ) do
split[ k ] = trim( v )
end
if left( split[ 1 ], 1 ) == ":" then
prfx = string.sub( split[ 1 ], 2 )
table.remove( split, 1 )
end
cmd = trim( split[ 1 ] )
table.remove( split, 1 )
local gotargs = false
if left( split[ 1 ], 1 ) ~= ":" then
user = split[ 1 ]
table.remove( split, 1 )
end
-- Optional second user argument and command arguments
for k,v in pairs( split ) do
if left( v, 1 ) ~= ":" and not gotargs then
optfarg = optfarg .. " " .. v
elseif not gotargs then
gotargs = true
args = string.sub( v, 2 )
else
args = args .. " " .. v
end
end
self:Parse( prfx, user, cmd, args, trim( optfarg ) )
end
[/lua]
This is how my last IRC thingy did it.
ps optfarg
[QUOTE=gngbng;18098373]no i mean stuff like ":guy!~teh@isp.com PRIVMSG #somechat :hi", unless that's what that code you pasted does (in that case your code is awful).
also, why are you using inis?
[b]edit:[/b] after closer looking i have determined that your code is fucking atrocious.[/QUOTE]
I've always failed at good code
[CODE]
<?php
$Explosion = explode(" ", $data, 5);
$Seperate = explode("!", $Explosion[0]);
$Nick = str_replace(array(chr(10), chr(13), chr(32), chr(58)), "", $Seperate[0]);
$Channel = str_replace(array(chr(10), chr(13), chr(32), chr(58)), "", $Explosion[2]);
$Message = substr(str_replace(array(chr(10), chr(13)), "", $Explosion[3]),1)." ".RL($Explosion[4])." ".RL($Explosion[5])." ".RL($Explosion[6]);
$Time = gmdate("H:i");
if ($Explosion[1] == "JOIN") {
if ($Nick != GetINI("Bot.ini","Nick") && $Nick != GetINI("Bot.ini","AltNick") ) {
fputs($socket, "PRIVMSG $Channel :Welcome to $Channel, $Nick.\n");
}
echo "[$Time] $Nick has joined: $Channel.\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick has joined: $Channel.</pre>\n");
} elseif ($Explosion[1] == "PART") {
echo PQ("P", $Nick, $Channel, RL($Explosion[3]), RL($Explosion[4]), RL($Explosion[5]));
LogThis(gmdate("jS"), PQF("P", $Nick, $Channel, RL($Explosion[3]), RL($Explosion[4]), RL($Explosion[5])));
} elseif ($Explosion[1] == "QUIT") {
echo PQ("Q", $Nick, $Channel, RL($Explosion[3]), RL($Explosion[4]), RL($Explosion[5]));
LogThis(gmdate("jS"), PQF("Q", $Nick, $Channel, RL($Explosion[3]), RL($Explosion[4]), RL($Explosion[5])));
} elseif ($Explosion[1] == "PRIVMSG") {
if ($Explosion[2] == GetINI("Bot.ini","Nick")) {
echo "[$Time] $Nick (Personal): $Message\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick (Personal): ".htmlspecialchars($Message, ENT_QUOTES)."</pre>\n");
} else {
echo "[$Time] $Nick ($Channel): $Message\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick ($Channel): ".htmlspecialchars($Message, ENT_QUOTES)."</pre>\n");
}
} elseif ($Explosion[1] == "NOTICE") {
echo "[$Time] $Nick (Personal): $Message\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick (Personal): ".htmlspecialchars($Message, ENT_QUOTES)."</pre>\n");
} elseif ($Explosion[1] == "MODE"){
echo "[$Time] $Nick ($Channel): Changed mode for ".RL($Explosion[4]).". (".RL($Explosion[3]).").\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick ($Channel): Changed mode for ".RL($Explosion[4]).". (".RL($Explosion[3]).").</pre>\n");
} elseif ($Explosion[0] == "PING") {
} elseif ($Explosion[1] == "NICK") {
echo "[$Time] $Nick has changed their nickname to ".str_replace(array(chr(10), chr(13), chr(58)), "", $Explosion[2]).".\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick has changed their nickname to ".str_replace(array(chr(10), chr(13), chr(58)), "", $Explosion[2]).".</pre>\n");
} else {
echo "[$Time] $Nick $Explosion[1] $Explosion[2] $Explosion[3] $Explosion[4]\n";
LogThis(gmdate("jS"), "<pre>[$Time] $Nick ".htmlspecialchars($Explosion[1], ENT_QUOTES)." ".htmlspecialchars($Explosion[2], ENT_QUOTES)." ".htmlspecialchars($Explosion[3], ENT_QUOTES)." ".htmlspecialchars($Explosion[4], ENT_QUOTES)."</pre>\n");
}
?>
[/CODE]
That's the code for displaying it.
Ok, now you can see the bots fight!
[url=http://www.robertandsherman.co.uk/uploads/bots/0/]SimpleBot vs Scavenger[/url]
Would anyone be interested in a competition to make the best bot? And is there anything else I should add to the map apart from ammo and health?
[QUOTE=TehDoomCat;18098701]Also, is this point gravity? I was going for 'fall to the floor' gravity, but then I changed my mind and decided I wanted it to be point gravity 'cause I could develop on it...[/QUOTE]
Yep
[QUOTE=TehDoomCat;18098701]In a 2D space, what's the difference between... well, an objects origin subtracted from another, and their distance apart?
'distancev2' sounds like a function which returns the difference between two objects' origins as it is...[/quote]
origin minus origin gives a two-part vector showing the x/y difference, and the distance between two origins gives a single number.
distancev2 just calculates the single number for a distance between them
[QUOTE=Robert64;18099257]Ok, now you can see the bots fight!
[url=http://www.robertandsherman.co.uk/uploads/bots/0/]SimpleBot vs Scavenger[/url]
Would anyone be interested in a competition to make the best bot? And is there anything else I should add to the map apart from ammo and health?[/QUOTE]
Scavenger won after a 2 minute battle of just collecting health all the time. Jeez. I love the idea though, you should make it so everyone can test their own code.
Edit: Scavenger won again.
[QUOTE=AzzyMaster;18099231]I've always failed at good code
code
That's the code for displaying it.[/QUOTE]
[php]<?php
class IRC {
function __construct($server, $port) {
$this->Server = $server;
$this->Connected = false;
$this->Socket = stream_socket_client("tcp://{$this->Server}:$port", $errno, $errstr, 30);
}
private function Parse($input) {
// broken regex ahoy
// someone fix this for me :C
$regex = '/(?::(\S+)\s)?(\d{3}|[a-zA-Z]+)(?:\s((?:[^\0\n\r :][^\0\n\r ]*)(?:\s[^\0\n\r :][^\0\n\r ]*){0,13}))?(?:\s:([^\0\n\r]*))?/';
preg_match($regex, $input, $matches);
if(!$matches) { return array(); }
return array('prefix' => $matches[1],
'command' => $matches[2],
'params' => $matches[3],
'data' => $matches[4] );
}
public function ParseName($input) {
$regex = "/(.+)!(.+)@(.+)/";
preg_match($regex, $input, $matches);
if(!$matches) { return array(); }
$output = array('nick' => $matches[1],
'user' => $matches[2],
'host' => $matches[3] );
return $output;
}
function Send($command, $params = false, $data = false) {
$final = "$command";
if($params) $final .= " $params";
if($data) $final .= " :$data";
$final .= "\r\n";
fwrite($this->Socket, $final);
}
function Recieve() {
$get = fread($this->Socket, 1500);
if(!$get) $this->Message = false;
$this->Message = $this->Parse($get);
}
function Connect() {
$this->Connected = true;
$this->Send("NICK", $this->Nickname);
$this->Send("USER", "teh \"teh\" \"{$this->Server}\"", "teh");
}
function SetNickname($nick) {
if($this->Connected)
$this->Send("NICK", false, $nick);
else
$this->Nickname = $nick;
}
}
?>[/php]
[php]<?php
require("irc.php");
$irc = new IRC("irc.gamesurge.net", 6667);
$irc->SetNickname("GERTY");
$irc->Connect();
while($irc->Connected) {
$irc->Recieve();
if($irc->Message) {
switch ($irc->Message["command"]) {
case "PING":
$irc->Send("PONG", false, $irc->Message["data"]);
break; case "001":
// on connect
$irc->Send("JOIN", "#somechan");
break; case "PRIVMSG":
// code to handle shit
break; default:
//echo "Unhandled command {$irc->Message["command"]}.\n";
break;
}
}
}
?>[/php]
have fun. it's also incomplete.
[QUOTE=Maurice;18099400]Scavenger won after a 2 minute battle of just collecting health all the time. Jeez. I love the idea though, you should make it so everyone can test their own code.
Edit: Scavenger won again.[/QUOTE]
Scavenger has better tactics, it scavenges for health and then ammo until it has full of both, then uses all of its ammo at once on the other bot so it doesn't have time to heal.
I'll start building a site for people to upload their bots now.
[QUOTE=Jallen;18094378]I'm at home for the weekend on my Eee PC, My desktop is at my university room.
Need an idea for something to occupy me... I was thinking something using SFML and maybe Box 2D, Also want to try out some 2D smoke effects with sprites some time. I could do a GUI type thing like some of you guys have done.
Dunno what to make :sigh:[/QUOTE]
Make a fancy screensaver.
[QUOTE=noctune9;18099656]Make a fancy screensaver.[/QUOTE]
I've always gone for the blank screensavers.
It seems the opposite of sensible to use a 3D or somehow processing intensive screensaver since it's the thing that shows when you aren't using your computer. It wastes power and produces heat :/
But I don't have a better idea :(
[QUOTE=Robert64;18099512]Scavenger has better tactics, it scavenges for health and then ammo until it has full of both, then uses all of its ammo at once on the other bot so it doesn't have time to heal.
I'll start building a site for people to upload their bots now.[/QUOTE]
That is really awesome!
Robert64: Very nice, it's like we're working on two twin projects!
Scavenger is canny!
I noticed your scripting language is a bit unusual, Had I noticed your post earlier, I would've advised you to use something like [url=http://code.google.com/p/as3scriptinglib/]this[/url] instead, you can have a generic bot class and pass it as the "this" object to the bot's code, which would run as standard ECMA Script.
Great work, I'd write some kickass AI right now, but I'm a little busy with my own project. :eng99:
[QUOTE=gngbng;18097567]how are you parsing incoming irc commands? my php irc class using some god awful regex that breaks half the time for god knows what reason.[/QUOTE]
[url]http://github.com/TheLinx/Juiz/blob/master/juiz[/url]
Line 143 - 189
[QUOTE=gngbng;18099008]
the first step at reverse engineering the steam protocol.[/QUOTE]
[url]http://github.com/koraktor/steam-condenser[/url]
[QUOTE=thelinx;18099949][url]http://github.com/TheLinx/Juiz/blob/master/juiz[/url]
Line 143 - 189
[url]http://github.com/koraktor/steam-condenser[/url][/QUOTE]
first of all, i'm using php/pcre.
second of all, steam condenser is totally irrelevant and high-level compared to what i am attempting.
[QUOTE=thelinx;18099949][url]http://github.com/TheLinx/Juiz/blob/master/juiz[/url][/QUOTE]
Jesus, can't you assign some more things in a single line? Those first couple are a bit short.
You're also doing a lot of pattern matching, that can be done much simpler.
In processdata you're calling lower on the same strings over and over, seems awfully redundant.
For a supposed highly modular bot, you've got a lot of hard coded responses in that parsing method of yours.
And finally, a single file for the whole parser / bot control thing is insane, write your IRC library separately as a module.
[QUOTE=Robert64;18099257]Ok, now you can see the bots fight!
[url=http://www.robertandsherman.co.uk/uploads/bots/0/]SimpleBot vs Scavenger[/url]
Would anyone be interested in a competition to make the best bot? And is there anything else I should add to the map apart from ammo and health?[/QUOTE]
haha that's brilliant!
[QUOTE=Robert64;18099512]I'll start building a site for people to upload their bots now.[/QUOTE]
Ok, finished the basic site: [url]http://www.robertandsherman.co.uk/botbattle/[/url]
You make an account then upload the bots you make. At the moment you can test against yourself or against a random other bot, and the outcome of the match isn't stored.
I'll explain the syntax of the bot's language later if anyone is interested.
Edit: Adding an update and a delete button for your bots now.
[QUOTE=Robert64;18102666]Ok, finished the basic site: [url]http://www.robertandsherman.co.uk/botbattle/[/url]
You make an account then upload the bots you make. At the moment you can test against yourself or against a random other bot, and the outcome of the match isn't stored.
I'll explain the syntax of the bot's language later if anyone is interested.
Edit: Adding an update and a delete button for your bots now.[/QUOTE]
You can abuse "move: forward;" to create faster bots :).
[code]
move: forward;
move: forward;
move: forward;
[/code]
[QUOTE=Aertz;18103141]You can abuse "move: forward;" to create faster bots :).[/QUOTE]
The game runs 4 commands per frame, so you can put four "move: forward;"s or "shoot;"s in a row for maximum speed. This is a valid tactic (my bot #3 uses this for shooting).
But if you do that you're sacrificing if statements etc, so your bot isn't as smart. You have to balance speed and intelligence to make the best bot.
[QUOTE=Robert64;18103224]The game runs 4 commands per frame, so you can put four "move: forward;"s or "shoot;"s in a row for maximum speed. This is a valid tactic (my bot #3 uses this for shooting).
But if you do that you're sacrificing if statements etc, so your bot isn't as smart. You have to balance speed and intelligence to make the best bot.[/QUOTE]
Ahhh nice.
Is there a way to get the closest distance of a health or ammo?
[QUOTE=Jawalt;18103487]Is there a way to get the closest distance of a health or ammo?[/QUOTE]
[code]health_x // x position of closest health
health_y // y position to nearest health
health_dir // relative direction to direction of bot to nearest health
health_dist // distance to nearest health[/code]
And same for enemy_ and ammo_
Be careful, if statements are very strict. Separate each part with a space like this:
[code]if: health_dist + 16 < ammo_dist * 2;[/code]
And you can only have one operator in the middle out of:
[code]> = <[/code]
edit:
And valid colours are as follows ;)
[code]white, grey, black, red, orange, yellow, green, blue, purple, brown, pink[/code]
[QUOTE=Jawalt;18103487]Is there a way to get the closest distance of a health or ammo?[/QUOTE]
Without knowing exactly what you want can I suggest the following.
Check all of the items within a range of co-ordinates to see if they match what you want (maybe a range of two or three rooms if doing a roguelike for example). If there is more than one then find which is closer, if there aren't any then make the range slightly larger and repeat until you have the closest desired item.
Or you could simply go through every item of the desired type and calculate the distance to it and take the one with the shortest distance.
That's the best I can suggest though having never done anything similar and not knowing what your making (haven't really been reading all the posts recently).
I'm going to sleep. The update button doesn't work and there are a pair of null bots (6 and 13? I think).
I'll fix these tomorrow
Edit: And FYI my latest bot was Scavenger M2
[QUOTE=Ortzinator;18098800]Not sure what you're showing us.[/QUOTE]
[I]The game[/I] i made on the previous page..
[QUOTE=Robert64;18104142]I'm going to sleep. The update button doesn't work and there are a pair of null bots (6 and 13? I think).
I'll fix these tomorrow
Edit: And FYI my latest bot was Scavenger M2[/QUOTE]
I'll beat it!
My latest robot stands still on start and dies.
I made what I believe to be a completely unbeatable robot (like 90% of the time) it's code is as small as possible with as little logic as possible, and it's only goal is to collect ammo then kill. It's called ScavangerAdvanced.
Sorry, you need to Log In to post a reply to this thread.