Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Well... Not much happened in terms of development... but lots have been happening on the Magic front? Exile... and no more combat damage stacks?

Well, that's one of those things... we'll see how I go about exile, as it's only cosmetic, but it's nice being able to do cosmetic.

Anyway, so I am now trying to convert my code to git. Not just because, but also just because. I want to learn git, and DA is a good place to learn it on, and networking (with my starting over from scratch the whole time) would work really well with git.

I'm getting ready for some more coding, but I am hoping to get a wireless network adapter for my PC soon, and this will ease my network coding. I also now have a 2nd pc (laptop) to my disposal which also will make coding easier.

Unfortunately though July is a new financial year, and quite a lot of prep will have to go into my budget for work. Hopefully not too long after that, I'll be able to add some code to my brand new (now not existing) git repository.

Ok... So the last commit had some networking code in the release notes, but I have a feeling most of that will be lost. I have never truly felt comfortable with the solution I had, in terms of elegance and scalability, and network effeciency etc.

I asked myself, how can I get it right? Well, I decided I needed to look at as much of other people's network code as I can get. Unfortunately I've not found a great deal, but I did find Almindor's (the guy who wrote lnet, which I use for networking) Lentilwars code. This has some elegant solutions to some problems I wasn't sure how to get through. The other piece of code is called DataPacker - written by Theo Lustenberger, which will be able to compress the data I send (zip), and make it easy for me to incrementally "decipher" the messages that was sent.

So generally I have hope to get the networking fully going, but for now it's still far off. I'm trying to get at least 30m of programming in a day. Obviously some days it'll be more, and others will be less. But 30m of DA focus a day... (even if it's more research).

Well, this post is all about how I am programming the networks, and hopefully, how I think I am being "smart". Hopefully it doesn't all backfire into my face.

First of all... the way that the server and the client will be "sending" messages will be very, very similar. Thus, if the messages what they send will be similar, so will the messages they receive. The BIG difference comes in how they respond once the message is received.

For instance. The Client will request "DrawCard","Library" (Because I want the commands to look similar I added Library... Library is actually "Implied" with "DrawCard".) Then the server will send a reply "DrawCard","Forest"... In this case the "implied" position (the hand) is not used. So the message sent was the same, but the server will respond differently than the client will...

So what I've done to help me code cleanly, and hopefully smartly, is I've used the Lazarus feature of "including" files. So my generic send code can be used (NetSend.inc) for both the server and the client... both have "command","parameter" sending, it's just that the client is saying "DrawCard","Library", whilst the server is saying "DrawCard","Forest"... but they both use the exact (letter for letter) same code.

Even the receiving (NetReceive.inc) code can be reused, up to the point where the *interpretation* of "DrawCard" needs to happen. That then is seperated into the server's code, and the Client's code.

It does mean though that I'll have some "dead" commands on both sides... like "RequestNewTable"... the Server won't be sending a table request back... It does something else. This is few and far between though, so hopefully not too many dead alleys in my code.

Looking forward to hopefully be able to do some connecting to tables, and talking away soon. (And after that... who knows? Drawing and playing cards!)

Hi all,

I want to apologize that February is (likely) not going to make it. However I am going through all the code at the moment and noticing where I can improve. So in a lot of instances it's a rewrite (well, not complete) of the existing code. It is because the old code was geared at getting single player working, but now I need slightly more abstract code to deal with multi player and single player.

For instance, as it is at the moment, creating a token, and playing a card doesn't use any of the same code (it's pretty much copied and pasted and then modified). However for internet play, it would be much cleaner if I could just have
"Playcard('Atog',X,Y,Facing)"
and
"Playcard('Saproling token',X,Y,Facing)" (the problem is that DA doesn't "know" Saproling token, but it knows Atog).

But that's not how it works at the moment... and that's the type of thing I need to fix. Basically playing a token will tell DA (not forever, just for now) that Saproling token, is a 1/1 green card with the name "Saproling token".

So far I've therefor implemented the "hand" actions, and looked through the "zone" actions, but they all indirectly reference stuff that falls in the "in-play" actions, where I've not yet got.

I am not going to put a target date down (again), but know that I am working on DA almost daily at the moment, so we'll be getting there sooner rather than later.

So that means only 2.33 months left to program the game into alpha testing for net play. (I've told some of the people who follow the game that I want to be able to have it playable by the end of 2008) Oooh... I am putting pressure on myself. But it's a good thing.

Anyway, at the moment, with the new compiler, DA for linux is not even getting to the main screen. So my first priority is to get that working again. Also on linux Lazarus default development widgetset is gtk2, which will give me a sexier interface than gtk1, but that might be the blame for the non-starting too.

On windows my SVN lazarus (I am going to continue to use lazarus SVN now, as well as glscene SVN) is not rebuilding yet. It is because the compiler is trying to recompile stuff where he only needs to look at the .ppu files. Anyway, so I have some groundwork to be done to actually get it working.

On my wishlist for the deckeditor is the same ol', same ol' mana curve. Hopefully making it look pretty with GLScene, and some cool stacked graphs etc. Anyway... another is to incorporate my Excel "combo" calculator.

For this however, I had to implement the Hyper Geometric Distribution in pascal... I read the wikipedia article... My statistics are a little bit rusty, and I was really struggling. However, I followed the external links, to nerdbucket. He has an implementation for C++ as well as one for Ruby. But what *really* interested me, was the exponent / ln mathematics.

This enabled me to create a decent implementation of Hyper Geometric Distribution for Pascal... and here it follows:

Function lnFactorial(N:Integer):Double;
var i : integer;
aValue : double;
begin
if N = 0 then begin result := 1; exit; end;
aValue := 0;
for i := 1 to N do
aValue := aValue + ln(i);
Result := aValue;
end;


function BinomialCoef(n,k:integer):double;
var aValue : double;
begin
aValue := exp(lnFactorial(n) - (lnFactorial(k) + lnFactorial(n-k)));
BinomialCoef:=aValue;
end;

Function HypGeomDist(RequiredHits, PopulationSize, Targets, Attempts:integer):double;
begin
Result :=
BinomialCoef
(Targets,RequiredHits)
*
BinomialCoef
(PopulationSize-Targets,Attempts - RequiredHits)
/
BinomialCoef
(PopulationSize,Attempts);
end;

Please consider the code as public domain.

I hate to use this as my excuse, but it really is my main motivator (demotivator?) that I am not continuing at the moment...

Lazarus 0.9.26 is a week or two away, and I'll be getting it when it's hot to start developing Daring Apprentice 0.9.26... (or whatever I'll call the first "release").

I am fairly happy with the way the design of the network play is going now... except for the decks... at first I wanted the server to keep track of the decks, but now I think I'll only let the tournament server do that... You don't want the player in the 1-on-1 game to know your deck just because he's the server.

For the tournament server, you'll need to log in and select your deck from your own little profile thingy on the server. (Which you uploaded)

Although I still don't mind the idea that you can get the other guy's deck if you want it... But functionality must be very limited as it is probably a vulnerability.

For this revision, I've added a very cool feature - tilting the camera - and I enabled the docking of the player 2 hand (at the moment it is not optional). The draw card functionality etc. has now shifted a little in the user interface, so that the opponent hand and the player hand works the same way. I've added a screenshot:

In the background I've been working on my test application for networking code, and I made great progress last night. As soon as I have a prototype, I'll post more on it here. You can have a look at the concept here.


Revision 94:
UF : Player2's hand now docks. (This may change for network!)
F : Random Discard implemented
F : You can now change the angle of the camera as well
M : Found the textures readme again

If someone can figure out a better way of displaying card's names, I'll be SO glad to hear. I don't want to have the cadencer running the whole time, as well as the fact that it doesn't work on linux at all (and not on Windows at the moment).

I've thought about adding a sprite above the card (ala Quake3 when you pummel someone) but I fear that it will get smaller the further away you move the card, as well as get some anti-aliasing done onto it, so it won't be so legible.

Older Posts Home

Blogger Template by Blogcrowds.