Re: My thoughts on C# and gaming.

Bill Kelly <[email protected]>
Newsgroups gmane.games.devel.sweng
Message-ID <[email protected]>
Richard wrote:
> In article <[email protected]>,
>     Bill Kelly <[email protected]>  writes:
>>
>> However, it's unlikely I would have used that library in this case,
>> [...]
> 
> I only see this snippet out of context and compared with a ruby
> equivalent in the comments.  What I got out of the discussion was a
> lamentation that you couldn't be as concise in C++.  If I wrote the
> ruby code in the equivalent low-level algorithms as the C++ code, I'm
> guessing it wouldn't be a one-liner anymore either.
> 
> So the comparison seems a bit off to me.  Its like comparing a big
> number crunching set of formulas from Mathematica to the equivalent
> naked C++ with no library support.  The reason something like
> Mathematica or ruby is more concise within a particular problem domain
> is that the framework is there to support that problem domain.  If you
> remove that problem domain support and compare apples to apples in
> terms of algorithms, then C++ starts to look more reasonable by
> comparison.

I agree about the pastebin code.  In my enthusiasm last night,
I had overlooked the fact that I had indeed deprived myself of
higher level C++ libraries that I might otherwise ordinarily
have used to make the parsing job simpler.

Unfortunately this gaffe has rather distracted from my claims
that I feel more productive in Ruby for certain tasks than C++.


I don't know if this example will help, but at least it's game-
related.

Here we're starting an interactive Ruby prompt, opening a UDP
socket, and querying a Quake II server for its public status.

 $ irb --simple-prompt
 >> require 'socket'
 => true
 >> sock = UDPSocket.open
 => #<UDPSocket:fd 4>
 >> sock.send("\xFF\xFF\xFF\xFFstatus\0", 0, "tastyspleen.net", 27912)
 => 11
 >> result = sock.recvfrom(65536)
 => ["\xFF\xFF\xFF\xFFprint\n...", ["AF_INET", 27912, "tastyspleen.net", "74.54.186.226"]]
 >> print result[0]
     print
 \Q2Admin\1.17.44-tsmod-2\mapname\ranbase2\anticheat\1\sv_noobquad\0
 \gamedate\Aug  2 2009\gamename\baseq2\maxspectators\8\sv_handicap\1
 \INFO2\NO BOTS, HACKS, CHEATS PLEASE\INFO1\All Skill Levels Welcome
 \cheats\0\timelimit\15\fraglimit\30\dmflags\16404\deathmatch\1\
 version\R1Q2 b7864 i386 Oct  1 2008 Linux
 \hostname\tastyspleen.net::vanilla\maxclients\32
 2 56 "Quahog "
 0 7 "WallFly[BZZZ]"
 13 43 "the.swine.cru"
 12 88 "Pittybull"
 20 59 "Festus"
 18 177 "[XZ]MAYARA"
 9 29 "mojoe"
 1 19 "crusty-cru"
 16 32 "Daemos"
 11 220 "Alice"
 13 227 "Bradley"
 15 150 "[XZ]Zeppelin"
 => nil
 >> sock.close
 => nil

# to me the above is already pretty neat, but for fun i'll go
# ahead and parse the player info results into a data structure:
# (the [4..-1] below is trimming off the leading 0xFF bytes)

 >> lines = result.first[4..-1].split(/\n/)
 >> player_lines = lines[2..-1]
 >> PlayerStatus = Struct.new(:name, :score, :ping)
 >> players = player_lines.map {|info| info =~ /^(\d+) (\d+) "(.*)"$/ && PlayerStatus.new($3, $1.to_i, $2.to_i)}

# done.  we now have the player data parsed into an array of
# instances of our new PlayerStatus class.  The player data is
# currently unsorted, or, rather, retains the ordering from the
# status response, which is probably implicitly by client-ID on
# the server:

 >> players.first.name
 => "Quahog "
 >> players.first.score
 => 2
 >> players.first.ping
 => 56

# we can see that indeed Quahog was the first entry in
# the unparsed server response up above.
# now, let's sort the players by highest score...

 >> sorted_players = players.sort_by {|pl| -pl.score}

# done.

 >> sorted_players.first.name
 => "Festus"
 >> sorted_players.first.score
 => 20


I've just never had a programming experience in C++ that was
anywhere near as facile as that.


Regards,

Bill


_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.