简体   繁体   English

Scribd开发人员挑战:JavaScript

[英]Scribd Developer Challenge: JavaScript

I'm trying to learn a bit of JavScript and Hack on the Scribed Developer Challenge, However, I can't get even the most basic thing to work. 我正在尝试在Scribed Developer Challenge上学习一些JavScript和Hack,但是,即使是最基本的东西也无法使用。

Here is the Javascript I have: 这是我拥有的Javascript:

function new_game() {
}

function make_move() {

  var board = get_board();
  var lat = get_my_x();
  var longt = get_my_y();
  trace("("+ lat + "," + longt + ")")

   // we found an item! take it!
   if (board[get_my_x()][get_my_y()] > 0) {
       return TAKE;
   }

   var rand = Math.random() * 4;

   if (rand < 1) return NORTH;
   if (rand < 2) return SOUTH;
   if (rand < 3) return EAST;
   if (rand < 4) return WEST;

   return PASS;

}

And my output looks like this: 我的输出如下所示:

在此处输入图片说明

The weird thing is that the robot went in a straight line up and so he(the green one) is currently in what I would call position(1,9). 奇怪的是,机器人沿直线上升,因此他(绿色的)当前处于我称之为position(1,9)的位置。 However, the output reads (4,0). 但是,输出为(4,0)。 Here is how they map. 这是他们的地图。

(4,0) => (1,7) (5,0) => (1,8) (4,0) => (1,9) (4,0)=>(1,7)(5,0)=>(1,8)(4,0)=>(1,9)

It doesn't seem to me to have any correspondence, and appears random. 在我看来,没有任何对应关系,并且看起来是随机的。 If you need more you can find the API online as well as a testing framework on github . 如果您需要更多资源,可以在线找到API以及github上测试框架

Am I calling get_my_x and get_my_y correctly? 我是否正确调用get_my_x和get_my_y?

Thank you in advance. 先感谢您。

EDIT: 编辑:

在此处输入图片说明

My green robot started on the same tile as the purple robot. 我的绿色机器人与紫色机器人在同一块瓷砖上启动。 The first move was up and the output was (2,2). 第一步向上移动,输出为(2,2)。 The second bove was back down the output was (2,1). 第二个bove退回,输出为(2,1)。 Then it moved to the left and the output was (2,2). 然后它向左移动,输出为(2,2)。 How can this be? 怎么会这样? Two grid tiles with the same coordinates! 具有相同坐标的两个网格块!

I'll answer this although it is a little embarrassing: 我会回答这个问题,尽管有点尴尬:

Essentially, I wanted the output number to tell me where I was at, instead of my last position. 本质上,我希望输出数字告诉我我现在所在的位置,而不是我的上一个职位。 I had the wrong expectations, and once that is solved it all makes sense. 我有错误的期望,一旦解决,一切都变得有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM