Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Is it possible to distinguish between coin types?

#22
  1. Get array of all items
  2. loop over each item
  3. for each item in that array loop over all items again (loop over each item for each item in the array) and store distance from first item to second item. Store data in a new object keyed by the item in loop 1 if it’s closer than a certain distance threshold.
    when all is said and done you should have an array with each item and a count of all other coins nearby it closer than a certain distance.

but as i said i had trouble getting coin.distanceTo(coin2); to give me the distance between 2 different coins, so without that it’s a lot more difficult.

1 Like

#23

You can get pretty advanced with it; check out some of the top strategies for the Greed tournament we had: http://blog.codecombat.com/a-31-trillion-390-billion-statement-programming-war-between-545-wizards

1 Like

#24

Pretty neat examples there. I noticed it’s using .distance instead of distanceTo() which is in the newer campaigns. Perhaps the bug is only in distanceTo. i’ll have to give another shot at writing that and file an official bug report when i get some time.

1 Like

#25

Thank you sotonin,
however, I’m not yet able to understand the use of “array”,
so, i mean, I don’t know what “Get array of all items” means neither than code it.

I’ve read nick’s linked paper.
Quite nice strategy, however, I’m definitely not yet able to understand some “unknown” functions …
I mean … what can i use, what does exist ? where can I find documentation about the things I’m able to use ? I’m a bit lost…
Even if I’ve lots of ideas, I’m not yet able to structure them in a proper coding method.

1 Like

#26

Get array of all items.

var items = this.findItems();
for(var i = 0; i < items.length; ++i) {
    var item = items[i];
    // do something
}
1 Like

#27

OK,
how do you know that we can use things like “self, this” ? is there other things to know ?
moreover, the same question about “length”, where is the list of the properties we can use ?

Thank you for your kind collaboration

1 Like

#28

@Amaury

check your gears ( equip ) to see witch code can you use , for example : a sword can give you attack a shield can give you shield action a book can give you loop , that’s how you get new properties , you can hover your equip to see how to use those tags/actions/code , i’m sure english isn’t your main language , and so am I , i’m an arabic but i still easy

2 Likes

#29

Pretty much anything in javascript (the language) is accessible in code combat. length is an automatic property of arrays and objects in javascript. Other than that. yes. as @ReFinig said, your methods are listed in the code combat window below your code.

1 Like

#30

Hum,
I’ve just discovered a new word : Library =)

so, my question is :smile:where can I find the libraries available in CodeCombat (or generally speaking, information about libraries available in an environnement ?)
As we can read, the “word” => “self.” is in the “method” listed into the window below.
However, “words” like “this.” or “*.length” are not listed.

Could you define me some words please, like “method” and “array” or the useful things like that ?
I still don’t understand what is an array and how to use it.

In addition, how can i take part in the “Greed Tournament” ?

Thank you for your kind collaboration.

1 Like

#31

Again. you need to google for the respective language. Javascript, Python etc. This is language specific and Codecombat will not define them for you.

To play this game (outside the scope of the tutorials given here) in an advanced manner you have to do outside research into the specific language you are trying to learn. Buy some books or search online.

this is used in javascript, it normally refers to the window or originating object (in codecombat thats usually the player object.) self is the same but for python.

in javascript when you create a “function” such as below

function test() {
    var test = this.something;
}

this changes “scope” so it is no longer the originating object but now it is the function object itself. so to get around this and still be able to access the originating object, people create a new variable named “self” (takeover from python i guess) and set it at the start of the script as equal to this.

example:

var self = this;

function test() {
    var test = self.something;
}

as far as length, that’s something different altogether. That is a “property” of whatever object you are calling it on. i dont recall off hand all the different types of objects that have it built in, but arrays, objects and strings do. there are many different types of objects and properties. but again. you are better off reading some javascript tutorials or books to discover them.

3 Likes

#32

i would move the self.move(item.pos) outside of the for loop.

1 Like