Abstrct / Schemaverse

The Schemaverse is a space-based strategy game implemented entirely within a PostgreSQL database. Compete against other players using raw SQL commands to command your fleet. Or, if your PL/pgSQL-foo is strong, wield it to write AI and have your fleet command itself!
schemaverse.com
PostgreSQL License
356 stars 39 forks source link

Move Command #7

Closed AkiTensai closed 12 years ago

AkiTensai commented 12 years ago

At Defcon, I made a suggestion about altering the move function to help make movement easier to understand.

My suggestion was about using the destination x/y with the amount of fuel the player is willing to use and let the function do the rest. It appears the current move command already does mostly what I was suggesting at Defcon. Where I believe the function should change is to not need to be passed NULL based on using speed/direction vs speed/X/Y.

It appears postgresql supports overloads. This could be an avenue to not need nulls in function input values. ie the current function: MOVE(id, speed, NULL, X, Y) MOVE(id, speed, direction, NULL, NULL)

becomes: MOVE(id, speed, X, Y) MOVE(id, speed, direction)

An overload of 4 ints is used for X Y, and an overload of 3 ints is direction. It looks like the upper section of the current MOVE function could be pulled into the 4 int overload, and once the direction is calculated, it passes off to the 3 int overload which handles all of the validation and meat of the function.

Abstrct commented 12 years ago

https://github.com/Abstrct/Schemaverse/commit/ef8a31f05e9c2a10fa2227c119b2e7bb531a027b

So I gave this a go I think you will still be happy with the results. Admittedly, I had to make a couple changes from your original idea due to some added functionality but hopefully you agree with the changes. You now have the following options:

MOVE(ship, speed, x, y); -- automatically calculates direction. must have enough fuel still to stop MOVE(ship, x, y); -- automatically calculates direction and best possible speed MOVE(ship, speed, direction, x, y) -- Still works as before

I was not able to create the MOVE(ship, speed, direction) overload because the same parameters were already taken by MOVE(ship, x, y). I think MOVE(ship, X,Y), which will calculate both direction and optimal speed for you, will be a lot more popular of a command so I gave it the easier overload.

I also haven't moved any code to the other functions. I didn't write most of MOVE so I don't feel like changing other segments around. I will leave that to the MOVE expert (tigereye). Right now all the overloads just pass all the details to the main MOVE function.

Thanks again for your suggestion! If you don't agree with the way I implemented them I am certainly open to any constructive criticism you may have. -Abstrct

AkiTensai commented 12 years ago

Excellent work. I kept looking at the page threateningly, but my own projects yelled at me louder. Thank you Abstrct.