Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just curious, O(1)? #6

Closed
toqueteos opened this issue May 27, 2014 · 6 comments
Closed

Just curious, O(1)? #6

toqueteos opened this issue May 27, 2014 · 6 comments

Comments

@toqueteos
Copy link

Unless you have discovered something new, you have to iterate all ships at least once. Something in my guts tells me once is a bit low no matter how probabilistic this is.

So what is actually O(1) compared to all other battle sims?

@toqueteos
Copy link
Author

Example: This https://github.com/jstar88/opbe/blob/master/combatObject/Fire.php#L158 doesn't seem O(1) at all. It's O(n) no matter how hard you try.

@jstar88
Copy link
Owner

jstar88 commented May 28, 2014

The combat engine compute size is n, a variable counting the amount of ships.
Standard combat engines are O(n^2) because there is an iteration over all enemy ships for each your ship.

As you can see from the code, the iteration run on each ship TYPE group, not in EVERY ships in them.
Since the ships types are limited,the problem is O(1).
It's not possible build an O(1) engine without probability theorems

@toqueteos
Copy link
Author

defenderFleet looked like a list of all ships instead of a collection of (ship, count). My bad.

Is this approach suitable for games like the old XWars?

@jstar88
Copy link
Owner

jstar88 commented May 29, 2014

i dont know what game it is. Anyway it's a general approach :)

@toqueteos
Copy link
Author

XWars was the successor of Ogame by GameForge but it didn't turn out as well as they expected so they killed it. It was active a year or so. Ships were customizable by players instead of premade.

@jstar88
Copy link
Owner

jstar88 commented May 31, 2014

if there are infinite combinations of customization, then the ship types amount is not costant.
For example: if a player has 100 ships and 1 ship of each type, then he has 100 ship types.(worst case)
But he could has only one ship type containing 100 same ships.(best case)
Generally we can say that in a game like that:
-standard battle engine is Θ(n_n) because has quadratic complexity in every case;
-OPBE is O(n_n): Θ(1) in best case and Θ(n*n) in worst.

if you want implement opbe for xwars, you should make a key ID for every ship type: since they are unlimited you can use ID = md5(sum(ship_params))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants