Categories
Uncategorized

How to randomize a list in order

I don’t remember the link but there was a gambling site a while back that published their randomization algorithm in an attempt to show how fair they were. It went as follows:

for each element in list
pick position in the entire list to put this element in the list.
swap elements with the current and picked position

The problem with that is that items at the front of the list will be moved more times on average than items at the end of this list. This is because items which are moved earlier (items at the front of the list) have more chance to be moved past the current index into the list, thus being picked to be moved again. This distorts the randomization curve such that items at the end of the list are more likely to stay there.

As a result, they got hacked.

Here’s the proper way to randomly sort a list in place:


void SystemAddressList::RandomizeOrder(void)
{
unsigned index, size, randIndex;
PlayerID temp;
size = systemList.Size();
for (index=0; index < size; index++) { randIndex=index + (randomMT() % (size-index)); if (randIndex!=index) { temp=systemList[index]; systemList[index]=systemList[randIndex]; systemList[randIndex]=temp; } } }

Categories
Uncategorized

What’s the big deal about Las Vegas?

I hear people talk excitedly about Las Vegas and have to wonder what the big deal is.

  • Hot
  • Dry
  • An enviromental nightmare
  • Smokey everywhere, including the restaurants
  • Certain things are hugely overpriced

The first and last time I went there

  • I tried gambling on the slot machines. My wife and I put in $20 on the quarter machines and won about $2. Is that supposed to be fun?
  • A photographer charged $60, got a $20 tip, and only took 5 pictures which were so half-assed (off-center, misframed, no technique) it was obvious he was incompetent even to someone such as myself with no experience or training
  • My wife had her hair done. The hairdresser charged $200, used some cheap spray that gave her a rash, put rubber bands in her hair rather than proper hair bands, accidently took wife’s glasses, and was extremely reluctant to return them. I had to offer a bribe to get them back (I didn’t pay though).
  • I couldn’t eat at the restaurants because it was so smokey I had to hold my breath the entire time.
Categories
Game Development Uncategorized

Titan quest is an example of graphics over gamplay

The problem with the growth of the game industry is that every new AAA game needs to outspend every AAA game that came before it. By outspend I mean better graphics, more sounds, more models, bigger worlds, real physics, voice acting for every character, and so on. However, game sales per game are relatively the same as they always were and games cost about the same too.

What this means is that each game is a bigger risk to publishers. There are more failures each of which cost more. So publishers need to stick to licenses and sequels because they can cost less to make (Madden 2004 vs. Madden 2005) and are more likely to sell due to an installed fanbase.

Titan Quest is a good example of how this has gone wrong. It comes on 5 CDs. The world is huge, with detailed models, voice acting for all the characters, and handcrafted levels. The problem is that the game itself is boring. Although the world is huge, the gameplay is the same the last 40 hours as it is the first hour. You don’t notice the detail on the models because you will always play with the camera zoomed out. You don’t listen to the voice acting because the voice acting is boring and too slow. Plus all the usual complaints apply: The characters are unbalanced, the game doesn’t ramp up in difficulty, the story is background filler, etc.

Diablo 2, which is what Titan Quest copied, I would guess has an equal sized or roughly smaller world. Yet it is far more fun and interesting, despite being a 2D game and coming on fewer CDs.

How many games have you seen with the latest physics which have no relevance on the gameplay at all? Other than Half Life 2 that would be all of them for me. How many older games do you know of, with 10% worse graphics that are far more fun than a more recent game?

A game is not just a contract to develop thousands of models, huge worlds, the latest physics, and special shaders. It’s an artform and iterative process to make something that is fun and interesting. Judging by recent games, very few developers seem to iteratively playtest their games these days.

Categories
Uncategorized

Fog shader

This is a shader I wrote, with help, that determines the amount of fog between the top of the fog layer and the ground beneath using the z-buffer. It then applies alpha to the fog based on that amount. The shader also supports fog holes where you can use a heighfield that will reduce the fog based on the image. It uses parallax mapping to give the appearance of a 3D fog basin.

Fog

The fog is less nearer the bottom of the screen because of the camera angle. It is also less around the rocks because it is closer to the ground there.

The fog does not clip the rocks because of this technique.

Categories
Uncategorized

How to fix the patent system in 3 easy steps

I was thinking about the problem of corruption and how systems of accountability tend to reduce corruption. I then thought of how this relates to the patent system. Part of the problem with the patent system is a lack of accountability.

Originally I came up with a list of 10 steps to fix the patent system, but this doesn’t fix the underlying problem, which is the patent lawyers themselves. So here’s a simpler version that will do a better job.

How to fix the patent system in 3 easy steps

  1. Patent lawyers make minimum wage.
  2. Every patent granted pays a bonus of $10,000, 10% as an end-of-year bonus and the majority after the patent expires.
  3. If a patent is overturned in court, the legal fees incurred to overturn the patent are reinbursed to the challenger and come out of the bonus.

So there you go. If the patent lawyers do their jobs and only grant meaningful, non-obvious patents they can make a great wage. If they do the job they are currently doing they make squat, which with the current state of the patent system is what they deserve. Companies win because the cost to fight frivolous patents comes from those responsible for granting them in the first place.

Categories
Uncategorized

Useful data structure of the day: BPlus tree

In RakNet, when I sent a message I put it on a queue. When an acknowlegment arrives, I look at the head of the queue and assuming that acknowlegement matches what is there, I pop the queue. Most of the time that works great – O(1) both ways. But there is a problem – with large blocks lost, you get the folloowing bug:

(assuming I missed out on elements 0-1000)
Search through a 1000 element list for element # 1001
Search through a 1000 element list for element # 1002
Search through a 1000 element list for element # 1003
Search through a 1000 element list for … 2000

Assuming the list went from 0 to 1000, this is 1 million iterations because in the worst case I did a linear search through the queue.

This rarely happened because usually acknowlegements came in the order I did sends, so 99.99% of the time there wasn’t a problem and it was O(1). But I needed a data structure that, given input not in the set, would still do a relatively fast find. However, it also had to do fast insertions and deletions (which was why I used a queue to begin with).

I could have used my AVL Balanced binary tree. It’s a binary tree that automatically rebalances after every insertion and deletion. It’s pretty good for unsorted data – finds, insertions, and deletions are all Log2(n). However, I wrote it back in college so it wasn’t as efficient as it could be. The main problem was that there was a lot of node creation and destruction.

I also wrote a B Tree and a BPlus tree in college. A BPlus tree is an n-way tree of order o where each node contains o keys and o+1 children. Each leaf contains an ordered list of key/data pairs. The leftmost child of a node points to the subtree where all keys are less than node key 0, the child o+1 is the value of the lowest key of that subtree, and so on. All leaves are linked in a linked list. In essence, it’s an ordered list divided up among leaves with the branches of the tree pointing into that list.

I thought it would be a one day at most project since that’s about how long it took me in college. However, I did two things differently:
1. I didn’t remember how to do it. Thinking it would be easy, I started coding without full understanding of the data structure.
2. I wanted something very optimal so went to extreme lengths to make it so.

So it took a week 🙁

Anyway it’s done now and it’s a good data structure. If you need an ordered list where insertions, deletions, and searches are all fast, and/or you want to linearly traverse the list, a B+ is the way to go. If you need fast insertions, deletions, and searches but your data doesn’t have to be ordered and you don’t need linear traversals very often, an AVL tree is slightly more efficient.

It’s in RakNet as the file DS_BPlusTree.h.

Categories
Uncategorized

Why you shouldn’t partner in business

Some people ask me why I’m working on something as big as an MMOG by myself. Here’s a list of reasons why you shouldn’t partner with someone in a business:

A partnership is a marriage
My neighbor runs the biggest Mailboxes Etc. in Newport Beach and complains about this topic every time I bring up the issue. When you have a partner no longer can you do what is best for the business. On all major points you now need to consult your partner. You’re going to spend most of your waking hours with your partner, more than your girlfriend or wife. If you don’t get along a ‘divorce’ is going to be just as expensive as a real divorce, and possibly kill the business you put the years of your life into. You wouldn’t marry someone unless you knew them well first and only 1 person in 1000 is worthy marrying. How many people do you know that well at all, much less are worth partnering with?

Your reasons for finding a partner is probably short-term but the partnership is long-term
When starting a business there’s a lot to do and a lot of difficulties that can be most easily and effectively solved by someone else. In my case, I need art for my game and I don’t have much money to pay for it. One solution is to partner with an artist. So lets say I were to grab a friend who I know well, get along with, and who does a good job at art. If the business is successful, 10 years from now I gave up half the business so I could save 30K on artwork. Stupid.

It’s like those idiots who get venture capital from Y Combinator. They give up some percentage of their startup for a measly $6000 per founder. If you are so hard up you can’t scrape together $6000 you don’t have the connections, work experience, or qualifications to run a business.

Your payoff is p/n, where n goes up by 1 for each partner
That’s profit / number of partners. Of course p may go up too, and if p goes up by more than the inverse of (n+1) then it’s worth it. But that’s unlikely unless you partner with a superstar. At n=1 you’d have to double your profit to make up for it. It’s easy to envision two people doubling income but I didn’t say that. I said two partners doubling profit. Would a partner, vs. an employee, make that much more? Keep in mind a partner, unless they work for free, is going to draw a salary from your income too, thus reducing profit.

Do you need a partner, or an employee?
Following from my previous message, do you really need a partner, as opposed to an employee? You have to ask yourself “Am I partnering for someone to do a specific job?” Because if you are, hire an employee instead. If you can’t afford an employee… this is one reason to find a partner. They can bring the money you need where otherwise it would be impossible to make your business succeed (I’m talking hundreds of thousands, not $6000). Another reason is if your partner is such a superstar and they are so critical to the business that you would never be able to hire them otherwise. That’s rarely the case.

Most people aren’t cut out to run a business
Not everyone is a superstar. If they were, we wouldn’t call them superstars anymore. We’d call them average. Most people are average by the very definition of the word, with half the people below average and half above average. How many superstars do you know at work? Probably 1 or 2 right? So they can program, or do art, or whatever. How are their social skills? Their business sense? Do they bring capital with them that they are willing to part with? Are they good at managing people? Are they a superstar at every one of these things, or enough of them to compliment yourself? You have a 1 / p^n chance of finding such a person. So the odds are, whoever you are thinking of partnering with might help you today but won’t be carrying their weight tomorrow.

Some people can’t hold long-term interests
A business isn’t a 9-5 job. It’s a 9-9 job, and will be for some number of years, if not the rest of your life. Can your potential partner stick with things this long? If not, it’s going to cost you a lot of stress and money down the road when they decide they work too hard and should stick to management.

Back when I was in Alaska there was a good opportunity to start a computer store. There was only one other computer store in the city and they overcharged, were rude, and had a poor selection. At the time the internet was still growing so there was no real way to order over the internet either. At the time I didn’t have much business sense so I partnered with my cousin to start such a store. I wrote up some business proposals to send to family to try to get money to get the initial batch of parts and open the storefront. I called and looked around to try to find a suitable location. I worked out the math on the finances and contacted a vendor who I could order from. My cousin… well he was excited to talk about what to name the store. After a week of my bitching at him to help, he said “Why should I do anything when you’re doing it all?”

As it turns out I was right. About 2 years later a Computer City opened there. They went out of business, but then CompUSA opened a year later and has been there since. With a 2 year lead into the market I could have potentially done very well for myself.

Summary
Don’t partner with someone just because it’s exciting to do so, or you need a short-term employee. Partnerships only make sense if you

  • Know someone incredibly talented in a wide variety of fields
  • Will make you far more money than not partnering with them
  • Is mission critical
  • You have no other way to get what you need
Categories
Uncategorized

Political compass test

Political compass test

I got:

Economic Left/Right: -0.25
Social Libertarian/Authoritarian: -2.92

The maximum is 10 on the scale, so I’m right in the middle for the economy and more towards Anarchism than goverment control. I think this is because of the current goverment oppression I’m strongly against any goverment control.

Categories
Uncategorized

Am I in the wrong line of business?

As a programmer I make a decent living. But it seems like I make a pittance compared to certain kinds of labor that you don’t even need a high-school education to perform.

Case 1:
Barber
I went to get a haircut today. The first place I went to charged $17. So I walked across the street to this place with “Salon” in the name, as if that made it any different from any place that cut your hair. They charged

  • $28 for a junior haircutter
  • $35 for an experienced haircutter
  • $40 for a senior haircutter

Plus tip of course.

Lets give them the benefit of the doubt and say that a haircut takes half an hour. The senior haircutter then makes $80 an hour (plus tip). A 15% tip adds $12 to that. Lets say that the store takes half of that $80. That’s still $40 + $12 = $52 an hour which is pretty damn good considering you don’t even need a high school education to be a barber.
Hourly Wage: $52

Case 2:
Waiter
I took my wife to a fancy restaurant for our annivesary. The meal came out to be about $150 and we didn’t order wine. We took about 45 minutes but to make the math easy make it an hour (for cleaning the table and crap). There were 8 people total serviced from this waiter, including us. Assuming the average customer spends $75 on food, that’s $600 an hour on food. The wine there was between $50 and $200 per person. We didn’t order wine but the other 6 did. Assuming they each spent $75 on average on wine that’s 6 * 75 = $450. So the restaurant takes in $1050 an hour per waiter. If the waiter gets 15% of that as tip that’s $157.5 untaxed income, plus whatever their usual salary is!
Hourly Wage: $157.50 + salary.

Case 3:
Rental agents
When I was in Germany my wife and I were looking for apartments. We had a rental agent (the company got her) with us who did the following:

  • Unlock the door
  • Tell us about the apartment
  • Stand there for 15 minutes while we looked around

The apartment seemed OK. When asked the price, the agent responded something to the effect of “$800 a month, utilities included. [Pause] Plus my fee.”
Me: “Um… Fee? How much is the fee?”
Her: “2 months rent.”
Me: “So you mean $1600???”
Her: “Yes.”

Counting everything everything we spent about 40 minutes there. But to make the math easy lets make it an hour to count for incidental time incurred.
Hourly Wage: $1600

Case 4:
Real Estate Agent
This one isn’t by the hour so much as it is by the house – usually 6% of the selling price. Around here the average selling price is $750,000. That’s $45,000! I’ve read that they sometimes lower the commision rate after the first $100,000. So to give them the benefit of the doubt, lets make it $30,000. Lets say you are a discriminating client and look at 50 houses before buying one. Each house takes 1 hour to show around.
Hourly Wage: $600

Lawyers and recruiters are also overpaid according to the work they do but at least you need an education for that. These are all uneducated semi-skilled jobs, which shouldn’t pay more than $20 an hour at most.

Categories
Uncategorized

The pursuit of self-interest in goverment

The reason why Capitalism works is that it is based on the pursuit of self-interest in such a way that it benefits society. All people are naturally inclined to pursue their own interests. Therefore, Capitalism works because it is based (among other things) on the natural motivations of people.

Systems fail when they do not follow the natural motivations of people. For example, government. People in government (politicians) are inclined to pursue their own interest. In theory, this corresponds to the interests of the electorate, but in practice it’s a leaky abstraction. The interests of people in government is to make laws and systems that benefit themselves and give the appearance of benefitting their constituency so that they get reelected. In practice, this is not one and the same. For example, Digital Rights Management benefits politicians, who get compensation from special interests for passing these laws, while DRM does not benefit the electorate. Therefore, DRM passes, which hurts the populace but benefits the politician. But it passes because to the uninformed it gives the appearance of helping the industry. We can’t really blame the politician because he is following his own self-interest, anymore than we can blame the lion for killing the idiot who jumped in the zoo. It’s the system that is broken.

The reason why the Judicial branch works better than the Executive or Legislative branches is because, for a judge, there is less power and thus less self-interest involved. A judge theorectically doesn’t have the power to make laws, only to interpret existing laws. So a judge has less at stake, meaning that it is harder to bribe him or her and you don’t necessarily know which judge will take your case, and even if you bribe one the judge that gets the appeal may not accept your bribe. More people involved in a process tend to give better results than fewer people and people who have different levels of self-interest tend to form a more fair group that one that doesn’t.

Since we only have two effective political parties there are only two sets of self-interested parties. Also, by definition it’s in your own interest to get into Congress (so you can benefit yourself) and it’s easier to get into Congress by being dishonest than by being honest simply because lying works better than telling the truth as long as you don’t get caught. Since only liars win elections it’s no surprise that Congress is full of liars.

So what’s the solution? I think a system of government that would work is one that works best when people follow their own interests, as long as there is transparency of information. Because as soon as you start lying self-interest doesn’t work the same way Capitalism doesn’t work when people lie and cheat.

I’m proposing nearly a true democracy. Eliminate the legislative branch entirely. Instead, ALL laws are drafted and passed through a simple majority vote by those parties that have an interest in the matter. So state laws by state and federal laws by the country. In order to prevent lying, there needs to be a simple framework:

1. Each law up for vote needs to be fully described in the voting pamphlet in a factual and neutral way (think Wikipedia), including how much it will cost you, the long term effects, who it will benefit, who supports the law, etc.
2. There can’t be any voter fraud. This means keeping out qualified voters, cheating at the polls, allowing illegal aliens to vote, etc, a lot of which people claim happened for the Presidential election for G.B. 2nd term.

The judicial system can be kept intact to review and interpret laws that are passed to make sure they are fair and non-contradictory.

The executive branch should be severely curtailed to be solely a figurehead position to represent the country. The populace should be able to kick out the President at any time with a majority vote.