Saturday, January 30, 2010

network congestion and other issues

I have been pondering on the exact nature of issues being seen everytime we host a tourny on Rounders. Well, the issue of server marking client as disconnected is the crux of the matter, but why would server mark some client disconnected? the answer lies in the fact that due to n/w congestion packet loss starts accumulating and so after one move miss by a client, the server earnestly marks it as disconnected and stops listening from or writing to this client, leading to mayhem.
learnt a good funda of settcpnodelay function. You see during computer engineering classes, I had gone thru Nagle's algorithm which was designed to reduce load on network. In the client and server code here, I had found that settcpnodelay was set to false effectively enabling Nagle's algo. This led to a situation where packets would come from server only when the buffer was reasonably full and not immediately. This was leading to reduced load on network but other issues like moves not coming in from client etc etc started cropping up. So I disabled nagle's algo and so the packets started flying like crazy and soon due to n/w congestion packets started getting dropped and all hell broke loose, not a very good sign if one's job is at stake :-)
So now back to thinking about a proper solution and then implementing it so that we can host proper tournament on Rounders.
BTW for the Battleship game, I also made the cpu a lot more intelligent in attacking and destroying ships. It is not artificial intelligence, but I seriously thought about it :-) But then quickly dropped it. I have to first make tourny run on Rounders and then also use wxmac library to run vc app on mac. and on top of that, Kush is pestering me to create a game of Tom and Jerry, simple game but still sprites who have to move and run and jump. Good next level challenge :-)

Sunday, January 24, 2010

why tourny on rounders always spells trouble

Some time back, when AN was around, we had tested a holdem tournament on Rounders and it had gone well, so much so that i had even announced that tournament is working fine on Rounders. When this issue was raised again as to why work is not complete i was very very surprised. But then I tested a 2 table tournament and immediately saw the issues. The client would show the table to be hung, moves won't come on time, moves won't go to server, you name it...
Anyways so when I was given the go ahead to salvage the situation, i started looking at it from 2 perspectives - why is client not in sync with server and if client determines that it is out of sync, why can't it connect back with the server?
You see, I always was a sucker for school of thought of planning my work before hand and so after going thru the logs I noted that these 2 issues were of prime importance and went after my job. The 2nd issue of why client was unable to reconnect back was solved easily. The handler id was being removed from registry on the event of disconnection which was absurd. So fixed one issue. The other issue was a really tough nut to crack. After poring thru 80 mb of logs for one round of tournament and another 80 mb of logs for 2nd round of tournament i zeroed upon the issue. For some reason packets from client were getting dropped but packets from server were able to reach the client. In this event there is no I/O exception at the socket level so client is blissfully unaware that it is out of sync with server. Meanwhile server marks the client as disconnected. So now server won't let the client makes its moves, server wont even send moves to the client and all hell breaks loose. Well I thought that I have finally cracked the code. So I put in changes in a jiffy and started one table tournament. That went amazingly fine. So then 2 table tournament. Well for the first 20 minutes, it was w/o any issues. I almost thought that the major problem is solved. But then all the clients went into disconnection mode and couldn't connect back to server. Immediately I knew the reason. The check in java client was not good enough :-(
Well anyways, the new java client is ready. And one more round of tourny testing on Monday awaits me :-)
My 3 months of probation are complete here. I haven't yet talked to boss about it. I am waiting for them to make their first move. Will there be any hike, any promotion? The only hint that came was from AS who repeated what boss had mentioned some time back, that i will be getting some stock option in Mar/Apr. Well, that would be great, but what i need right now is cash to repay loans. The stock option would be great, but it is the cash which is the ultimate king. Need to seriously plan my finances.

Sunday, January 17, 2010

All is well

Sometime back, I was in a highly creative state where in I was able to really apply myself and force myself to think about a problem from different perspectives. At that time I hadn't watched 3 Idiots or read Chetan Bhagat's book. But I was ruminating on a new catch phrase that I wanted other people to use. And I zeroed upon e=m * c squared. Now what is this, you may ask? And the question is valid. This equation has been immortalized by Albert Einstein and every one who has had the misfortune to go thru relativity would know about this equation. But the way I conjured it up was in the sense of comical relief. Suppose some one asks me " how are you" and I reply back "e = m * c squared". That person will surely take it that I have completely lost my mental balance. If he/she were an acquaintance, the first thought would invariably be " i knew he was a little crazy, now it is confirmed". But suppose this person actually sees the smirk on my face and adds 2 and 2 and figures out that this particular response is something that is just meant in a comical sense and suppose that this person actually likes it so much that this person also starts using it, this thing could become a rage. Imagine for a moment that this particular thing becomes so big that it takes a life of its own. People would nod at each other and say " e = m...". Their eyes will meet in a crowded metro and they would immediately murmur "e = m...". Ha, won't that be really droll !!!!
So anyways I was conjuring up this scenario while lazing on my sofa. And then I watched 3 idiots. It is a good movie but there were some really really boring sequences, which spoilt my mood. But I must add there are some sequences which are really really funny. The movie deserves its success, controversy or no controversy. However I was talking about a catch phrase. And that phrase is, you guessed it right, All izzz well !!!! it has really become a nation wide rage. the phrase has been taken up by youngsters as well as older people. it is all around me and i love it. You can never guess what happens to your idea once it is taken up by masses. It just becomes bigger than you. The movie has raked millions. I am sure that there will be companies who has ridden on the crest of such phenomenon. I would really love to be at the helm of such a company !!!! Meanwhile all is well. Battleship game is almost done. The only issue that remains is that the game is not getting over. I will look at it tomorrow.

Battleship game for mobile

In December last year, I saw Kush playing battleship on the Active whizkid channel. I loved the game and so did Kush. But soon after the game was removed. I promised Kush that I will develop our own battleship game and he could play it on the mobile for as long as he wanted. Now when I made that promise I didn't realize the time it would take or how busy I would be in December. So one weekend, I thought about the game and crafted the first draft of design. Then Kush's nanaji came to visit us and the entire project was sidelined. Come January and the code is still not complete. When I got a much needed 3 days break because of boss's marriage, I vowed that I will take out the time needed to finish the game once and for all. I spent 1/2 a day on Friday wrapped up with macbook and then another 2/3 day on Saturday, which led to huge back ache and some back spasms. I requested Meetu to rub Moov cream but that didn't ameliorate the pain. Come Sunday I am still fixing bugs. At present, the grids are ready, the battleships can be hidden, the hit grid box show up as Red and the player can play the game for some time. Unfortunately it sometimes crashes and i am trying to find them and to fix them. I don't know if I can do it today or if my poor back will be able to bear the strain. Coming next week, we have lot of work on our plate and things are looking pretty grim these days. I have finally understood the main reason of why employees are making a beeline towards exiting this venture. I will elaborate on that some time later. But now I am back to the battleship game.
BTW I also spent some time going thru the algo book that i had bought. Went thru the greedy algorithm and absolutely loved it. Will definitely use it for allocating task items to resources for the next project plan :-)

Saturday, January 9, 2010

smorgasbord

This week started with a complaint by RN that her performance review was due and she was very scared that she would be getting a very bad rating. You see there is no data being maintained here to track performance of any employee and every thing is impression based. How do you counter that? AKB who was supposed to run the show on ground floor was highly incompetent fellow who didn't have the guts to ruffle feathers. Well, I had always wanted to know about how the PMS happened over here and I used this opportunity to raise this issue. I had expected bad news but what i got was a complete howler. No one, it seems and I repeat no one has ever bothered to even think on those terms. Well, if I was so keen on getting processes here, why not throw my hand and do my bit? And so I volunteered. It is still a work under progress, so more on that later. Suffice it to say that the moment news spread that I was going to do it for my team, I got buried under an avalanche of advise and indignant protests of how things had been in complete shambles before. RN got an email from Boss after my talk with Arin which was very surprising. Good for her. She deserves the hike.
On the work front, I realized that the mpp was a tough nut to crack. It is easy to create one. It is very difficult to update it. You see if the project plan were fixed, there won't be any issues. But at our workplace, things happen, work items get added, prev fixed bugs re-appear in a new avatar. And so it is almost impossible to track the activities of team members. Anyways, I have decided to do this on a weekly basis, to save some time for me.
I had been trying to fix an issue of total loss amount not matching the rake when only the bots were playing. Ideally the amount they lose should get added as rake for the house. But there was always a gap. The first thing I fixed was the rounding issue of rake. The code was using deprecated version of Big decimal rounding macros. Replaced them with proper enum. The rake became proper but still loss amount was miles off the rake figure. Went through a sheet of over 1400 hands and found the issue to be missing entries for bots doing leave during a hand. Fixed that issue. Still the loss amount didn't match the rake figure. Went through a history of 2600 hands and found that because of my change, the bots who were doing sitouts were also being added to the grs table. So at least I have found the problem and so it will be fixed. But I had spent quiet some time in going through the excel data and was wondering if there could be a better way to crunch numbers. Vijay came to my rescue and used the pivot table to simplify calculations. I had seen pivot table in action before but had never found a practical need for it. If you have never used a pivot table before, learn to do so. It will save you a lot of time :-)
On Friday we were all talking about the food that we have and when I mentioned that we have non veg food once in 2 weeks, the audience was left dumbfounded. You see, Goans eat a lot of non veg especially fish and the concept of having only vegetables was something uniquely alien to them. Jai ho!!!!!! Now I understand the rationale behind the movement of promoting vegetarian food habits.

Friday, January 1, 2010

House edge of casino

Anybody who is familiar with casino will also be familiar with the term house edge. House edge basically means how much a casino earns on average from each bet. Of course that means that the number of hands played has to be substantially large so that the individual wins and losses of players get evened out. When I was asked to compute the house edge for Baccarat, I was stumped. On googling the term, I realized that there are different ways to compute house edges for different games. For Baccarat, we had to determine the frequency of wins if bets are placed on Banker, Player and Tie. This was easy. After getting data from DB, I got the frequency of wins. Then for Banker bets, I computed the actual expected earning of a player by multiplying the win factor (0.95) with the % of wins on Banker bets. Then finally, going by the logic, that the win % of Banker bets is actually inverse of how much the player should be losing, we get the amount of how much the casino is actually losing. Ideally, for a game with house edge of 0, these 2 figures should match. The difference is the house edge of the casino for Baccarat game for the bets placed on Banker. This was straightforward. The tougher part was the way Ties were figured out. I had to compute the odds of such events and then compare them with the frequency of Ties events occurring. The difference was the house edge. Well, was I proud? Not really, because the house edge came to be substantially larger than expected. The world wide figure is around 1.5% for bets placed on Banker, but for us, it came to be 15%.
Next day, I received the request for computing house edges for rest of games. For Roulette, it was trivial. As we play American Roulette, there are 38 pockets, but we pay only 36 times the bet amount for a win on point. That gives us the house edge of 2/38. This was corroborated by the data from the DB. The harder ones were Videopoker, Keno and Blackjack. The first 2 are enormous because there are so many permutations and combination that it defied logic. The last one involves skill too and so it leads to very difficult calculations. I googled it and I found that actually very complex mathematical models have to be constructed and that some people have made it their career :-). There is a guy who goes by the name Wizard of the Odds. There are some really impressive information over there. Do check them out :-)
Anyways, so I was in a conundrum. I had to give some values for house edges and I didn't know how to start. Well then I had this brainwave. Instead of computing the theoretical values of house edges for these game, I could compute the house edges due to our server implementation. Well, then I got the data from DB and for each game computed the sum of all the bet amount and win amount ever played on our live server. For Blackjack, there were more than 10000 hands. For Keno it was only 250, which is understandable. So, the formula goes like this ---
House Edge = (Total bet - Total win)/Total bet.
This formula will give the actual house edges as experienced by players. Voila, the problem solved, I shared the house edges with boss. For Roulette, our house edge is actually 3% (theory says it should be 5%). For Blackjack, it is 5%. For Videopoker, it is again 5%. For Keno, it came to be 27% which is understandable as hands played were less.
Meetu's birthday fell on 28th Dec. I was in office but her father had come to visit us and they did arrange for a small celebration. On 31st, I was finally able to complete the first draft of project plan. The same night was spent in a long drunken revelry. I came home at 4 AM but Meetu was not mad at me. Thank goodness for that :-) So here is wishing everyone a very happy new year 2010.