Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2048
#31
Wait what do you mean? Not sure if that's what you meant, but it works for me: http://prntscr.com/35scx0
(You need to pass "grid" as an argument for the function; next move seems to be the API's "main{}")
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#32
That's what I did, and it didn't work. I'll have another go.

edit: I can get it to work now. Debugging however is horrible. The console could at least give you a shout instead of ignoring wrong syntax and just running the previously working stuff.
Reply
Thanks given by:
#33
(03-31-2014, 03:52 PM)YinYin Wrote:  Debugging however is horrible. The console could at least give you a shout instead of ignoring wrong syntax and just running the previously working stuff.
I second this. Hopefully, Silva is going to fix it in order for YinYin to do the superb artificial intelligence Twisted.
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:
#34
(03-31-2014, 05:14 PM)A-MAN Wrote:  I second this. Hopefully, Silva is going to fix it in order for YinYin to do the superb artificial intelligence :twisted:.
Nah. I think I already lost interest.

For anyone who still wants to attempt it here are some useful functions:
    C-Code:
function next_move(grid, console_log) {
  if (!ful_col(grid, 3)&&
      can_move_right(grid)) {
      return 'right';
    }  else if (can_move_up(grid)) {
      return 'up';
    } else if (can_move_right(grid)) {
      return 'right';
    } else if (can_move_down(grid)) {
      return 'down';
    } else if (can_move_left(grid)) {
      return 'left';
    }
}
function can_move_up(grid) {
  for (var i=0;i<4;++i) {
    for (var j=1;j<4;++j) {
      if (grid.cells[i][j]) {
        if (!grid.cells[i][j-1]) {
          return true;
        } else if (grid.cells[i][j].value==
                   grid.cells[i][j-1].value) {
          return true;
        }
      }
    }
  }
  return false;
}
function can_move_down(grid) {
  for (var i=0;i<4;++i) {
    for (var j=0;j<3;++j) {
      if (grid.cells[i][j]) {
        if (!grid.cells[i][j+1]) {
          return true;
        } else if (grid.cells[i][j].value==
                   grid.cells[i][j+1].value) {
          return true;
        }
      }
    }
  }
  return false;
}
function can_move_left(grid) {
  for (var i=1;i<4;++i) {
    for (var j=0;j<4;++j) {
      if (grid.cells[i][j]) {
        if (!grid.cells[i-1][j]) {
          return true;
        } else if (grid.cells[i][j].value==
                   grid.cells[i-1][j].value) {
          return true;
        }
      }
    }
  }
  return false;
}
function can_move_right(grid) {
  for (var i=0;i<3;++i) {
    for (var j=0;j<4;++j) {
      if (grid.cells[i][j]) {
        if (!grid.cells[i+1][j]) {
          return true;
        } else if (grid.cells[i][j].value==
                   grid.cells[i+1][j].value) {
          return true;
        }
      }
    }
  }
  return false;
}
function sum_col(grid, i) {
  var s=0;
  if (grid.cells[i][0]) {
    s=s+grid.cells[i][0].value;
  }
  if (grid.cells[i][1]) {
    s=s+grid.cells[i][1].value;
  }
  if (grid.cells[i][2]) {
    s=s+grid.cells[i][2].value;
  }
  if (grid.cells[i][3]) {
    s=s+grid.cells[i][3].value;
  }
  return s;
}
function sum_row(grid, i) {
  var s=0;
  if (grid.cells[0][i]) {
    s=s+grid.cells[0][i].value;
  }
  if (grid.cells[1][i]) {
    s=s+grid.cells[1][i].value;
  }
  if (grid.cells[2][i]) {
    s=s+grid.cells[2][i].value;
  }
  if (grid.cells[3][i]) {
    s=s+grid.cells[3][i].value;
  }
  return s;
}
function ful_col(grid, i) {
  if (grid.cells[i][0]&&
      grid.cells[i][1]&&
      grid.cells[i][2]&&
      grid.cells[i][3]) {
    return true;
  }
  return false;
}
function ful_row(grid, i) {
  if (grid.cells[0][i]&&
      grid.cells[1][i]&&
      grid.cells[2][i]&&
      grid.cells[3][i]) {
    return true;
  }
  return false;
}
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)