mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
+ Created function for generating a reproducable seed out of user code - as using JSON.stringify is not garanteed to be the same on every browser for objects.
This commit is contained in:
parent
efa39ffcd9
commit
521bc31fa5
1 changed files with 2 additions and 4 deletions
|
@ -31,15 +31,13 @@ module.exports = class World
|
|||
@systemMap = {}
|
||||
@scriptNotes = []
|
||||
# We want a seed thats not always 0 yet reproducable.
|
||||
console.log "Seed: ", @getSeed()
|
||||
@rand = new Rand @getSeed()
|
||||
@frames = [new WorldFrame(@, 0)]
|
||||
|
||||
getSeed: ->
|
||||
return 0 unless @userCodeMap #TODO: When does this happen?
|
||||
#Packs all methods in all thangs in one big array, then sorts and joins them. Then returns a hash value of the result.
|
||||
@hashString((methods for thangID, methods of @userCodeMap).reduce(((ret, methods) ->
|
||||
(method for methodID, method of methods).reduce(((ret, method) -> ret.push(method)), ret)
|
||||
ret.push method for methodID, method of methods
|
||||
), []).sort().join())
|
||||
|
||||
getFrame: (frameIndex) ->
|
||||
|
@ -497,4 +495,4 @@ module.exports = class World
|
|||
|
||||
#djb2 algorithm
|
||||
hashString: (str) ->
|
||||
(str.charCodeAt i for i in [0...str]).reduce(((hash, char) -> ((hash << 5) + hash) + char), 5381) # hash * 33 + c
|
||||
(str.charCodeAt i for i in [0...str.length]).reduce(((hash, char) -> ((hash << 5) + hash) + char), 5381) # hash * 33 + c
|
||||
|
|
Loading…
Reference in a new issue