Untrusted is a great game ..
It turns out that programming can be so interesting ~~
Game address: http://alexnisnevich.github.io/untrusted/
The following is the analysis and answer to the 1-21 mark ....
-----------------------------------------
01-CellBlockA
There's nothing to say .. Don't try it later ..
Delete all editable parts.
-----------------------------------------
02-theLongWayOut
It is more difficult than the first level. But I still don't have to do it ..
If you cannot delete it, comment it out.
Comment out the red part in the middle.
-----------------------------------------
03-validationEngaged
It is also very simple .. It seems that it cannot be deleted .. At least numBlocks is required ..
Now, at least, a little more...
As a result, the box is expanded until both the start point and exit are included.
The Code is as follows:
for (y = 2; y <= map.getHeight() - 3; y++) { map.placeObject(5, y, 'block'); map.placeObject(map.getWidth() - 5, y, 'block');} for (x = 5; x <= map.getWidth() - 5; x++) { map.placeObject(x, 2, 'block'); map.placeObject(x, map.getHeight() - 3, 'block');}
-----------------------------------------
04-multiplicity
Bad! More Restrictive!
Only the middle part can be modified. That is to say, you cannot change the entire box !..
What should I do? Note the above prompt: Level filenames can be hints, by the way. Have I mentioned that before?
The name of this parameter is a prompt. Diversity? What is the diversity? It cannot be a square ..
That's right! Exit! Define an exit ~
Add
map.placeObject(map.getWidth() - 5, map.getHeight()-6, 'exit');
You can.
-----------------------------------------
05-minesweeper
Mine clearance.
Let's look at the middle line .. This line is in the process of setting up Thunder.
Our goal is to avoid all the thunder, that is, mark the thunder.
How to mark it? The background color .. Add the following code.
map.setSquareColor(x, y, '#000000');
Then, the black part will be removed and the pass will be successful.
-----------------------------------------
06-drones101
It is difficult to start from this question.
The topic defines a d, which will be closer to you every time you act.
Our idea is to stop this d so that it cannot touch you. We noticed that the condition for moving d is that canMove () is true, so we can try to prevent canMove.
Therefore, you must define an item yourself .. This item needs to be able to stop d, but it is safe, that is, it will not fail.
The Code is as follows:
map.defineObject('safeDrone', { 'type': 'dynamic', 'symbol': 'h', 'color': 'blue', 'onCollision': function (player) { // nothing here! }, 'behavior': function (me) { moveToward(me, 'player'); } }); map.placeObject(map.getWidth()-3, 12, 'safeDrone');Then you can find a way to hide and hide d, which is easy.
-----------------------------------------
07-colors
Make sure that the characters and squares are in the same color.
Set it ..
After receiving the phone, you can set the callback function of callback. Each time a square passes, it is called, the color is changed, and the next one goes through.
The Code is as follows:
If (player. atLocation (23, 12) {player. setColor ('# f00');} // 23: The first green block is followed by the other one. The following is the same. If (player. atLocation (26, 12) {player. setColor ('# ff0');} if (player. atLocation (29, 12) {player. setColor ('#0f0');} if (player. atLocation (32, 12) {player. setColor ('# f00');} if (player. atLocation (35, 12) {player. setColor ('# ff0 ');}
-----------------------------------------
08-define thewoods
Well, there seems to be nothing to say ..
Enter "generateForest" in the box"
Then, try to move toward the end .. If you die, press Q to regenerate the forest. Water.
-----------------------------------------
09-fordingTheRiver
Cross the river. Just a few more raft.
But it is stipulated later that there can be only one raft. Difficult to handle ,,,
Since raft can only have one... So I can redefine a raft myself, right? That's not enough ..
map.defineObject('raftt', { 'type': 'dynamic', 'symbol': '▓', 'color': '#420', 'transport': true, // (prevents player from drowning in water) 'behavior': function (me) { } });for (var y = 5; y < 15; y++) { map.placeObject(22, y, 'raftt'); }
-----------------------------------------
10-ambush
It is also very simple .. Just define your own behavior so it won't block you.
Red:
if (me.getY()==12) { if (me.getX()==23) me.move('left'); else me.move('down');}Do not fill in yellow.
Green:
if (me.getY()==12) { if (me.getX()==27) me.move('right'); else me.move('down');}
-----------------------------------------
11-robot
Just define it as long as the robot can go to the exit.
if (me.getX()!=map.getWidth()-2) me.move('right');else me.move('down');
-----------------------------------------
12-robotNav
.. Bottom -- right -- top -- right -- bottom order
if (me.getX()<=map.getWidth()/2){ if (me.canMove('down')) me.move('down'); else me.move('right');}else if (me.getX()==map.getWidth()-2) me.move('down');else { if (me.canMove('up')) me.move('up'); else me.move('right');}
-----------------------------------------
13-robotMaze
This is one of the few rare challenges. Robots walk through the maze. The maze is randomly generated. We need to develop a policy for the robot to bring it out.
The key to the problem is: how can we determine how to proceed at every step of the robot?
It took me a long time to answer this question. Finally, I had the opportunity:
I thought of win98 Screen Saver a long time ago, that is, the screen saver of the 3D maze.
The strategy for everyone to go through the maze is:
Go straight in the current direction. If you can turn left, turn left.
In other words, the policy is as follows:
1. Determine whether the current status can be left turn. If yes, turn left and Rotate 90 degrees in the current direction.
2. If you cannot turn left, determine whether you can go straight.
3. If neither 1 nor 2 can be performed, determine whether to turn right.
4. If neither 1, 2, or 3 works, turn around 180 degrees, that is, back.
In this way, you will surely get out of the maze.
The key to the problem is:How can we determine whether a specific step is the current direction of the robot?(Is it right, up, left, or down ?)
So we need to mark it.
There are many tag methods. Here I use the Player Color for marking.
When the color is #0f0, the table goes to the right. # ff0 indicates the upward direction. # f00 indicates the left direction. # 0ff indicates the downward direction.
Then, each time, take the current color, get the current direction, and determine whether to turn left or not. If the direction changes, the color will change accordingly.
The Code is as follows.
// player color: // #0f0: right // #ff0: up // #f00: left // #0ff: down // turn left - go ahead - turn right - turn back if (me.getX()==map.getWidth()-2 && me.getY()>=8) // has get the key me.move('down'); if (player.getColor()=='#0f0') { // now: right if (me.canMove('up')) { player.setColor('#ff0'); me.move('up'); } else if (me.canMove('right')) { player.setColor('#0f0'); me.move('right'); } else if (me.canMove('down')) { player.setColor('#0ff'); me.move('down'); } else if (me.canMove('left')) { player.setColor('#f00'); me.move('left'); } } else if (player.getColor()=='#ff0') { // now: up if (me.canMove('left')) { player.setColor('#f00'); me.move('left'); } else if (me.canMove('up')) { player.setColor('#ff0'); me.move('up'); } else if (me.canMove('right')) { player.setColor('#0f0'); me.move('right'); } else if (me.canMove('down')) { player.setColor('#0ff'); me.move('down'); } } else if (player.getColor()=='#f00') { // now: left if (me.canMove('down')) { player.setColor('#0ff'); me.move('down'); } else if (me.canMove('left')) { player.setColor('#f00'); me.move('left'); } else if (me.canMove('up')) { player.setColor('#ff0'); me.move('up'); } else if (me.canMove('right')) { player.setColor('#0f0'); me.move('right'); } } else if (player.getColor()=='#0ff') { // now: down if (me.canMove('right')) { player.setColor('#0f0'); me.move('right'); } else if (me.canMove('down')) { player.setColor('#0ff'); me.move('down'); } else if (me.canMove('left')) { player.setColor('#f00'); me.move('left'); } else if (me.canMove('up')) { player.setColor('#ff0'); me.move('up'); } }
-----------------------------------------
14-crispsContest
Looking at the description of the question, it seems that it has something to do with 3-SAT?
If there are so many of them, it's okay to do it!
We need to see what keys need to be consumed when we pass through the green door. Obviously, it cannot be a Green Key.
The key may only be a red key or a blue key.
There are a lot of blue keys, and they look very reliable. In fact, they are blue keys.
Enter the blueKey and pass the following rule:
Enter the left room through the blue door (yellow key) -- enter the upper left room through the green door (blue key) -- return to the middle through the blue door -- enter the upper right room through the Red Door (red key) -- enter the right room through the green door (blue key) -- enter the left lower room through the yellow door (A) -- enter the right lower room through the blue door (yellow key) -- return to the center
-----------------------------------------
15-predictionalcrossing
A cheap question!
We found that you want to cross the river, but you cannot define anything. That is to say, you have to work hard on your head.
OnCollision has defined that when a collision with water occurs, the killedBy function can be called, that is, only the strings to be hung can be customized.
What should I do if it seems like there is no solution?
We found that onCollision must be called if it is needed. OnCollision calls the killedBy function and then fails.
In the middle of this article, you can make a fuss! Can we not call killedBy when we call onCollision?
Yes. OnCollision is reloaded.
So this very cheap method came out.
Complete line 31-33 as follows:
'onCollision': function (player) { player.killedBy('');},'onCollision':function(){a(1); }Then you can pass.
This method is really cheap ..
-----------------------------------------
16-lasers
This question is also quite difficult.
We need to find a way to change the color of the laser when the person approaches a laser.
Naturally, you need to define your own object and set the Collision Condition to change the player color to the object color when you encounter an object.
My approach is to take the right center point of each laser (x, y), then (x-1, Y-1), (x-1, y + 1), (x + 1, y-1), (x + 1, y + 1) Place the custom object, color for the laser color, Collision Condition, change the Player Color to this color.
Note 1:
Objects can only be defined in functions and can only be defined once. Therefore, it can only be defined during the first loop.
To determine whether it is the first cycle, you can only use global variables. Fortunately, javascript is object-oriented. That is, the variable declaration can be placed after the function.
So you can declare the variable after the function is complete.
NOTE 2:
CenterX and centerY are pixel coordinates, which need to be converted into grid coordinates.
Scale down according to width: length = 600: 500.
The code in the function is as follows:
if (xxx!=1) // Is the first time? { xxx=1; map.defineObject('r', { 'type': 'dynamic', 'symbol': 'R', 'color': 'red', 'onCollision': function (player, me) { player.setColor("red"); }}); map.defineObject('y', { 'type': 'dynamic', 'symbol': 'Y', 'color': 'yellow', 'onCollision': function (player, me) { player.setColor("yellow"); }}); map.defineObject('t', { 'type': 'dynamic', 'symbol': 'T', 'color': 'teal', 'onCollision': function (player, me) { player.setColor("teal") }}); } var ctx = map.getCanvasContext(); ctx.beginPath(); ctx.strokeStyle = color; ctx.lineWidth = 5; ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); var cx=Math.floor(centerX*map.getWidth()/600); var cy=Math.floor(centerY*map.getHeight()/500); if (color=="red") { map.placeObject(cx-1, cy-1, 'r'); map.placeObject(cx+1, cy+1, 'r'); map.placeObject(cx-1, cy+1, 'r'); map.placeObject(cx+1, cy-1, 'r'); } else if (color=="yellow") { map.placeObject(cx-1, cy-1, 'y'); map.placeObject(cx+1, cy+1, 'y'); map.placeObject(cx-1, cy+1, 'y'); map.placeObject(cx+1, cy-1, 'y'); } else { map.placeObject(cx-1, cy-1, 't'); map.placeObject(cx+1, cy+1, 't'); map.placeObject(cx-1, cy+1, 't'); map.placeObject(cx+1, cy-1, 't'); }
Only one line of code outside the function is the declaration of xxx:
var xxx;
-----------------------------------------
17-pointers
Traps & portals.
The portals are completely randomly connected, and some portals are directly connected to the traps.
The part to be filled in is the part when the portal is connected to each other.
We can mark the door.
When a transport door is connected to a trap, the transport door and the trap are red, representing danger. What we get is that a non-red portal will not be connected to a trap, which is safe.
Then let's go. Because the map is randomly generated, there may be no solution. Just take a few more chances and try again. It's quite simple.
The code to be filled in is as follows:
if (t1.getType()=='trap' || t2.getType()=='trap') { map.setSquareColor(t1.getX(), t1.getY(), 'red'); map.setSquareColor(t2.getX(), t2.getY(), 'red'); }
-----------------------------------------
18-superDrEvalBros
The gravity has all come out.
We can see that the player falls under the condition that the player is empty.
So we can leave it empty. That is, you can build your own object and then complete the bridge.
The Code is as follows:
map.defineObject('r', { 'type': 'none', 'symbol': 'A', 'color': 'red' }); for (var x=fl(w/2)-5;x<=fl(w/2)+4;x++) map.placeObject(x,fl(h/2),'r');
-----------------------------------------
19-incluentobjectmadness
I am not sure what this question is about.
It seems to be. Green is controlled by you, and red is random. Then, you only need to bring red and green together.
Just press one button. Believe me.
-----------------------------------------
20-bossFight
This question is very interesting.
We have to defeat the boss. How to defeat?
The API providesObject. projectileIf this item is true, it will destroy the dynamic item that it [actively encounters.
Boss is also a dynamic.
Therefore, we need to create an object, set its projectile to true, and then let it actively touch the boss, and then we can get rid of all the boss.
Note that the object cannot be generated at the beginning. That is, you can only call back to generate an object after obtaining the call.
As a result, first escape the bullet rain (it seems that it is not too troublesome. It's easy .), Obtain the phone number. Generate an object and kill the boss
The Code is as follows:
map.defineObject('bomb', { 'type': 'dynamic', 'symbol': 'o', 'color': 'gray', 'projectile': true, 'interval': 100, 'behavior': function (me) { me.move("up"); } }); map.getPlayer().setPhoneCallback(function(){ for (var x=0;x<=map.getWidth()-1;x++) { map.placeObject(x,7,'bomb');} });
-----------------------------------------
21-endOfTheLine
You can directly modify the source code.
Compared with the previous comparison, we found that the reason for the failure was that there was an additional map. finalLevel = true;
So we can find the finalLevel when we exit.
Enter Menu/scripts/object. js
Delete the judgment on game. map. finalLevel in line 28-30.
Then it's over.
So far, customs clearance.
Really fun games. Tell the truth.
We strongly recommend that you do this independently.