last day (19 days later) » 

7:22 PM
6
A: Skip other If conditions

KubaThis is more than you've asked but tell me if this works for you. I've added artificial border with 2s around the world :) init[] := (dim = {10, 10}; world = ArrayPad[RandomInteger[{1, 10}, dim], {1, 1}, 2]; known = ArrayPad[ConstantArray[0, dim], {1, 1}, 2]; p = {2, 2}; (known[[##]] = w...

 
@AndréF. The DeleteCases part is responsible for dropping walls. The direction is chosen from the remaining parts. You must skip this part and include your code then.
@AndréF. Try this Composition[ With[{val = #[[2]], pos = #[[1]]}, (known[[##]] = world[[##]]) & @@ pos; Switch[val, 10, p = pos; Break[], 2, {}, _, p = pos]] &, RandomChoice, Thread[{#, Extract[world, #]}] & ]. Materials about what? :)
@AndréF. I find those tutorials helpful. Choose one you want to focus at the moment and parse it.
 
I don't got exactly where I should change this part Composition[ With[{val = #[[2]], pos = #[[1]]}, (known[[##]] = world[[##]]) & @@ pos; Switch[val, 10, p = pos; Break[], 2, {}, _, p = pos]] &, RandomChoice, Thread[{#, Extract[world, #]}] &] Should I change the previous Composition for this or just some part of it? @Kuba
 
@AndréF. Switch those two compositions ;) Please delete old not relevant comments.
 
Its still not exactly how I need it to work. It needs to random select directions in Known and when it move update its value with the world value. If there is a wall in the world it must be updated to the known and than it should be excluded from the random selection when it start again. @Kuba
 
@AndréF. create additional list where you will store visited 2s and then take a complement of possible directions with this set before you choose each time.
 
7:22 PM
@Kuba Aren't those already visited 2s stored in the known? How can I make the DeleteCases work only for the 2s in known and not world?
Sorry for so many questions...
 
@AndréF. No problem ;)
Well, they are but they are not traced in any special way atm
 
My idea was just random moving at Known and updating it with World content
and if there is any wall or w/e on world that it cant pass
 
w/e?
 
the next time it wont use it as a valid direction
what ever
 
ok
 
7:27 PM
I was trying to apply one of the other answers on this part of choosing a direction but wasn't successful
 
@AndréF. What about 2s that were visited but now you are approaching them from different position?
 
wont be valid also
 
@AndréF. so I think you should introduce the list of visited 2s separately. Now they are stored in known but you are not parsing it at any time.
extracting 2's postitions from known and comparing with available directions would be the same, but probably slower than just keeping those positions all the time in separate list.
 
Humm...how can I do that? Maybe making another Array just full of 2s I've found and select direction based on it?
 
something like:
init[];
Module[{two = {}},
 While[True,
  Composition[

    With[{val = #[[2]], pos = #[[1]]},
      (known[[##]] = world[[##]]) & @@ pos;
      Switch[val, 10, p = pos; Break[], 2, AppendTo[two, pos], _,
       p = pos]] &,
    RandomChoice,
    Complement[#, two] &,
    Thread[{#, Extract[world, #]}] &
    ][# + p & /@ {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}]]]
 
7:36 PM
I'll try that
Thank you again
 
@AndréF. No problem :) but keep in mind it might not be the best approach. I'm not experienced with algorithms or IT. I just know mathematica and this is one strightforward approach :)
 
I'll keep working on that
But its already a good start
Specially that Dynamic part you make
It's going to be really usefull
made*
 
@AndréF. Ok, feel free to ask if you want :)
 
Thank you :)
 
@AndréF. Good luck and cya ;)
 
7:54 PM
Can I bother you again?
`init[] := (dim = {10, 10};
world = ArrayPad[ConstantArray[0, dim], {1, 1}, 2];
For[i = 10; j = 1, j < 12, j++, world[[i, j]] = 2];
world[[11, 5]] = 3;
known = ArrayPad[ConstantArray[0, dim], {1, 1}, 2];
p = {11, 2};
(known[[##]] = world[[##]]) & @@ p;)
init[];
n2 = 0;
Dynamic@MatrixPlot[known,
ColorRules -> {01 -> White, 2 -> Blue, 3 -> Yellow, 4 -> Black,
5 -> Red}, ImageSize -> Small]
pics = {};
Module[{two = {}},
While[True,
Composition[
With[{val = #[[2]], pos = #[[1]]}, (known[[##]] = world[[##]]) & @@
This it what Im using. The blue part would represent the wall and the yellow part the objective. In this particular case im using to test the maximum number of attempts to reach the goal would be 8
But the count is going way higher than it
the last piece of directions didnt fit
@Kuba
 
8:11 PM
Actually the last part would be
init[];
n2 = 0;
Dynamic@MatrixPlot[known,
ColorRules -> {01 -> White, 2 -> Blue, 3 -> Yellow, 4 -> Black,
5 -> Red}, ImageSize -> Small]
pics = {};
Module[{two = {}},
While[True,
Composition[
With[{val = #[[2]], pos = #[[1]]}, (known[[##]] = world[[##]]) & @@
pos; Pause@.1;
AppendTo[pics, known]; (known[[##]] = world[[##]]) & @@ p;
Switch[val, 3, p = pos; Print[n2]; Break[], 2,
AppendTo[two, pos]; n2++; p = {11, 2}, _, p = pos]] &,
RandomChoice, Complement[#, two] &,
 
8:22 PM
@AndréF. ok, what should I read now? :)
 
init[] := (dim = {10, 10};
world = ArrayPad[ConstantArray[0, dim], {1, 1}, 2];
For[i = 10; j = 1, j < 12, j++, world[[i, j]] = 2];
world[[11, 5]] = 3;
known = ArrayPad[ConstantArray[0, dim], {1, 1}, 2];
p = {11, 2};
(known[[##]] = world[[##]]) & @@ p;)
init[];
n2 = 0;
Dynamic@MatrixPlot[known,
ColorRules -> {01 -> White, 2 -> Blue, 3 -> Yellow, 4 -> Black,
5 -> Red}, ImageSize -> Small]
pics = {};
Module[{two = {}},
While[True,
Composition[
With[{val = #[[2]], pos = #[[1]]}, (known[[##]] = world[[##]]) & @@
pos; Pause@.1;
AppendTo[pics, known]; (known[[##]] = world[[##]]) & @@ p;
Switch[val, 3, p = pos; Print[n2]; Break[], 2,
AppendTo[two, pos]; n2++; p = {11, 2}, _, p = pos]] &,
RandomChoice, Complement[#, two] &,
Thread[{#, Extract[
Thats the code im using
I you check the "maze" im using to test
the maximum count until it reach the target would be 8
But the count is going waaaaay higher than that
(Sorry, failed on Copy and Paste again
 
@AndréF. Try to avoid for. Take a look at third line and replace it with world[[10, ;;]] = 2;
 
Didnt know about this. I know a bit of C++ thats why I use it
 
@AndréF. I'm sorry but I can't help you today. I'm quite busy, I will be available tomorrow. Try to parse it carefully, you can ad Print statements wherever you need to track the evaluation.
 
Ok. Sorry about that
 
8:28 PM
@AndréF. I know, but it is good to avoid procedural loops. Thery may be slower here.
No need to be sorry :)
 
I've been asking you about this for few days already
 
@AndréF. well, that's why I'm here to help and to learn :)
 
Thank you very much @Kuba
We continue this another time than
 
@AndréF. wolfram.com/learningcenter/tutorialcollection/CoreLanguage/… this tutorial is quite large but you may want to parse it. Those are basics that you may find useful.
I also had problem to get rid of old habits from C++
@AndréF. Good luck and see you soon :)
 
Im sure going to read it
Thank you again
 

  last day (19 days later) »