*Author

Offline OldTreesTopic starter

  • Legendary Member
  • ******
  • Posts: 10297
  • Reputation Power: 114
  • OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.OldTrees is a mythical and divine giver of immortality, one of the Turquoise Nymphs.
  • I was available for questions.
  • Awards: Brawl #2 Winner - Team FireTeam Card Design Winner
Some information about the code from Chriskang. https://elementscommunity.org/forum/index.php?topic=30889.msg392607#msg392607
« on: September 12, 2011, 06:44:42 pm »
Some coding lore about the game. All of this information is old posts from Chriskang and the code has changed in some ways since then. Please note the dates and use your best judgement about Zanz and Chriskang to estimate what is no longer accurate.

The link to the post is above each quote.

http://elementscommunity.org/forum/index.php/topic,654.0.html
In case The Archduke's comment wasn't clear yesterday, my WIP on the wiki is not speculation from my side, it's the real AI algorithm.
The page is about 90% done now and you can already find answers to your last questions there (about Miracle, Poison & Unborrow)
The WIP is linked at the bottom since it was a work in progress and I am listing chronologically.
http://elementscommunity.org/forum/index.php/topic,654.msg7358#msg7358
Now that the trick is revealed, I think I have to give an explanation here before someone asks "how do you decompile a swf".

So yes, I used a decompiler to look at the source code and to extract some pieces of information from it that weren't well known (drop rates, mutation effect, AI algorithm, ...)
Inside the source code, I spotted half a dozen bugs that I wrote in the wiki page and I also found a few major security holes. Chances are high that those holes are the ones abused by cheaters to get a score in t50 ten minutes after their account creation.
I wrote to Zanzarino immediatly to offer my help in solving those issues. But for now, I got no answer.

So I ask everyone who has some knowledge in engineering NOT TO give advices on how to decompile and how to read an actionscript code until those problems are fixed.
I hope you understand that having a "cheater free" game is more important than anything else.
http://elementscommunity.org/forum/index.php/topic,606.msg7464#msg7464
There's definitely a flaw here.
Let me try an explanation and again, forgive my frenglish.

So the game has 2 ways to pick up a random number:
- the first way is a native method of Actionscript called "Math.random()". If you're interested, see this:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary466.html
This one should always work fine and give accurate (pseudo)random numbers.
- the second method consists in taking the number from a pool build by Zanzarino. That's the one used by the "mutation" code.

Here's the detailed algorithm of the second method:
- function newseed() picks up 200 random number (by calling Math.random()) between 0 and 9 and concatenates them in a string of size 200.
- function rand() has an internal counter called "nnn" that is increased by 1 each time the function is called and reset to 0 when it reaches 197. This function returns the substring (of size 4) from the previous 200 characters string, starting at position "nnn" and divided by 10000 to produce a number between 0 and 1.
This is probably quite hard to understand so here's an example:
Let's say the first function produces the string "12345678901234 ... 67890" (size 200)
Then the first call to rand() will return 0.1234 (first 4 characters divided by 10000)
The second call will return 0.2345 (4 characters starting at the next position in the long string)
Then 0.3456 and so on.

Obviously, there is a strong correlation between 2 consecutive numbers picked by rand().
And there is more: for unknown reasons, the function newseed() that produces the 200 characters string is only called at the launch of the game (and when I say "launch" I mean before the login screen, not each time you start a new battle).
So, while you don't refresh the page in your internet browser (and retype your login name/password), you'll keep on getting the same 197 numbers over and over again.
This is exactly why the odds to see the same exact creature on the battlefield are so high (1 out of 197 if you just mutate 1 creature, much more if you mutate more).

The second problem (only 197 different "random" numbers) looks to me like the most serious one. Pick up a pen and paper, mutate like hell, write down the stats of all the different creatures you get, and when your list counts 197 mutants you can be sure that all the next mutations will produce a mutant from the list. And if you don't reload the swf, you'll stick with this list forever.
The impact of the first problem (correlation between 2 consecutive call) is harder to evaluate as it is very hard for me to know what calls are consecutive without the original source code from Zanzarino. I spotted a link between mutant skill and life bonus as I'm sure those are consecutive:
if (mutant skill is hatch, burrow, steal, heal, paradox, scavenger, gravity pull, mutation, ablaze or deja vu) then life bonus is between 0 and 2, with higher chances to be 0 or 1.
if (mutant skill is freeze, destroy, dive, momentum, lycanthropy, infection, devour, growth, poison or immaterial) then life bonus is between 2 and 4, with higher chances to be 3 or 4.
As for a link between creature's appearance and skill, I'm not able to give you an answer, as I don't know if those calls are consecutive or not. PuppyChow said that he saw sparks with ablaze, deja vu and steal and I provided screenshots of other sparks with poison, immaterial and momentum. Without more evidence, I'll just suppose there is no link here.
http://elementscommunity.org/forum/index.php/topic,763.msg7981#msg7981
The client (swf) is created with Flash 8.0 and counts about 15000 lines of code (all in actionscript).
The data persistence part is handled by a MySQL database but, as MySQL cannot be accessed directly by actionscript, Zanzarino had to create some wrappers to link both worlds.
Those wrappers are written in PHP. The client simply calls them with an HTTP POST and reads the result in plain text.

AI decks are all loaded at startup and while you play AI1, AI2, AI3 or FG, the only communication with the database is to store your score.
For t50, the game asks MochiAd for the list of the 50 top players, then randomly picks one, and finally retrieves the deck of this player from Zanzarino's database. Once the deck is loaded, there's no more communication with the server.
The hardest part is pvp/duel:
After each "end turn" from your side, your client sends the current game state to the server which stores it into the database and somehow transmits it to the other player.
I'm not 100% sure here, but I think the "standby" client just keeps asking for some news every second or so, until it gets a positive response from the server.
http://elementscommunity.org/forum/index.php/topic,778.msg8123#msg8123
In all the code, there are 43 calls to the (good) actionscript random and 53 to Zanzarino's rand()

Deck shuffling uses the Fisher–Yates algorithm with actionscript random.
Wikipedia says it's a good idea:
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

Spinners use Math.random() from actionscript too, so no problem there either.

After a quick check, Zanzarino's (flawed) rand() is used by:
* mutations (creature's appearance, skill, skill cost, attack & life bonus)
* chances to freeze target with Ice Bolt/Ice Shield
* quantums gained with Quantum Pillars/Towers
* quantums lost with Dissipation Field
* quantums absorbed by Devourers
* quantums changed by Scramble effect
* effect from Chaos Seed/Chaos Power
* chances to miss with Fog Shield/Dusk Mantle
http://elementscommunity.org/forum/index.php/topic,778.msg8125#msg8125
The (good) Math.random() from actionscript is used for:
* Hatch effect
* all AI decisions (see my post on the wiki for a complete list)
* picking opponent in t50
* deck shuffling
* coin spinning (at the beginning)
* card spinning (after a victory)
* building deck of level 0 & 1 AI
* choosing your opponent in level 2, 3 & 6

Opponent for ranked pvp is chosen by the server, so I don't know how it's done.
http://elementscommunity.org/forum/index.php/topic,1019.msg10673#msg10673
There's a reason this process in M:tG is called a stack.  It's a data structure that executes in reverse order of the actions that were put on it.
Elements doesn't work like that at all.
There is no server/client calls in the middle of a player's turn so it's completely impossible for your opponent to know anything about what you do during your turn.
Changing this behavior would require a complete rewrite of all php functions. This is FAR from being trivial.
http://elementscommunity.org/forum/index.php/topic,1129.msg12154#msg12154
Sorry to kill your expectations but it's just impossible with the current database design.
This would require a complete rewrite of all the current cards code. I seriously doubt you'll ever see something like that in a near future.

It might be interesting though.
^ Was about Multielemental cards. The image is gone so I am unsure if this was about Dual (1 :aether AND 1 :air) or Hybrid (1 :aether or 1 :air)
http://elementscommunity.org/forum/index.php/topic,1132.msg12526#msg12526
Code: [Select]
var SavedDeck = {Card1, Card2, Card3, Card4, Card5, Card6, Card7, Card8}
var CurrentDeck = { }

Shuffle:
var SavedDeck = {Card1, Card2, Card3, Card4, Card5, Card6, Card7, Card8}
var CurrentDeck = {Card5, Card7, Card1, Card2, Card8, Card6, Card4, Card3}

Draw first card:
var SavedDeck = {Card1, Card2, Card3, Card4, Card5, Card6, Card7, Card8}
var CurrentDeck = {Card5, Card7, Card1, Card2, Card8, Card6, Card4}

Draw second card:
var SavedDeck = {Card1, Card2, Card3, Card4, Card5, Card6, Card7, Card8}
var CurrentDeck = {Card5, Card7, Card1, Card2, Card8, Card6}

...

Draw last card:
var SavedDeck = {Card1, Card2, Card3, Card4, Card5, Card6, Card7, Card8}
var CurrentDeck = { }

There's NO discard pile. Period.
http://elementsthegame.wikia.com/wiki/User:Chriskang/Sandbox/10#Main_loop
"It is common sense to listen to the wisdom of the wise. The wise are marked by their readiness to listen to the wisdom of the fool."
"Nothing exists that cannot be countered." -OldTrees on indirect counters
Ask the Idea Guru: http://elementscommunity.org/forum/index.php/topic,32272.0.htm

Offline The_Mormegil

  • Legendary Member
  • ******
  • Posts: 2262
  • Country: it
  • Reputation Power: 32
  • The_Mormegil is a Ghost, obsessed with their Elemental pursuits.The_Mormegil is a Ghost, obsessed with their Elemental pursuits.The_Mormegil is a Ghost, obsessed with their Elemental pursuits.The_Mormegil is a Ghost, obsessed with their Elemental pursuits.The_Mormegil is a Ghost, obsessed with their Elemental pursuits.The_Mormegil is a Ghost, obsessed with their Elemental pursuits.
  • Intelligence is overrated.
  • Awards: Slice of Elements 10th Birthday CakeWar #5 Winner - Team AetherTeam PvP WinnerNew Slot Winner - FamiliarDeadly Sin Winner - GluttonyFirst Budosei of BudokanWinner of Revive the Archive
Re: Some information about the code from Chriskang. https://elementscommunity.org/forum/index.php?topic=30889.msg392617#msg392617
« Reply #1 on: September 12, 2011, 07:07:35 pm »
Very informative.
[18:21:43] jmdt: elements is just math over top of a GUI
Kakerlake: I believe that there is no God as in something that can think by itself and does stuff that sounds way OP.

 

blarg: