17
5
EDIT : Recently, my question has been proposed as a duplicate of 2048 Bot Challenge. I would like to stress that this question is different from that question, and will require answers to be thought of differently than that question. 2048 Bot Challenge asked the user to create a bot, and it would be run for an hour, with the highest score being the user's score. Additionally, it had a limit of 555 bytes. My challenge runs the code much less frequently, only 3 times. Your score is calculated by using the average score of those three times and dividing by the character length of your golfed code. My question encourages entries to be "smarter," and not try and get the highest score by brute force.
-
EDIT: The get method was changed to getTile, to avoid confliction with the JS keyword get. Additionally, a high score section was added.
Recently, I created a site that allows the popular game 2048 to be controlled using JavaScript. My site is linked here:
How:
An Ace Editor is located above the board. You place code in it, which is run once every 250 ms, or 4 times per second. This is called a cycle.
Use the following methods to control the board. You can't use the arrow keys.
up(); //move up
down(); //move down
left(); //move left
right(); //move right
move(integer); //integer is a direction. 0:up,1:right,2:down,3:left
getTile(y,x); //gets the value of the tile in position y,x on the board. See diagram
The following variables are defined for your convenience:
eother //boolean, alternates every cycle
frozen //integer, counts how many cycles the board has remained stationary
lastDir //integer, indicates the last direction that was tried to move in
//uses same format as the move method above.
startup //boolean, will always be true when the game first starts
//you can change it as you wish
a
b //a b and c are all persistant variables, they do not change each cycle
c //any other variables defined in the cycle will be reset every time
Rules:
- No Randomness, you must use logic. (Yes, I know the example code uses random.)
- No hooking into the game functions or cheating in other ways
- Generally, try to only call one move method per cycle. It is OK if you use more, but it screws with the animation
- The board must start in a random state, no modification of pre-game state
- You must provide both the uncompressed and golfed version of the code in your post.
- You must provide a link to the site that already loads the uncompressed version of your code, served via PasteBin (For example, ...thatcoolidea.com/2048?i=pH18GWtu loads the example code.)
Scoring:
- Your code will be scored by me.
- Part A of your score is an average of 3 runs of the code, rounded down.
- Part B of your score is the character length of your golfed code.
- Your final score is Part A divided by Part B
The winner will have their code immortalized as the example code on the site, if they choose, and acknowledged in a comment in the code.
Good luck! Hope you enjoy the challenge.
Current High Score 225.22 - Freezer - user3217109
10The fact that you've written a framework for 2048 is pretty awesome and very convenient for this type of challenge, but I don't see how it actually affects any of the strategies already found in our existing 2048 AI challenge. – Martin Ender – 2014-09-24T23:42:35.293
3Well I would say that mine Is different, simply because you are required to use one code base which will be the same each execution. This is much more user friendly and I don't think it would constitute a duplicate. – Sam Weaver – 2014-09-25T00:17:00.513
2The other question looks pretty dead. There were only four answers and a time limit of an hour, so I'm going to answer because this looks really cool. – krs013 – 2014-09-25T14:22:40.790
@samweaver add a note to the top of your question to explain why answers from the other question wouldnt be valid/competitive for your question, and then create a meta post for scrutiny. – rdans – 2014-09-25T20:36:29.240
If you cant do that, you will likely need to change your challenge in order to get it re-opened e.g. rules/scoring/restrictions – rdans – 2014-09-25T21:13:18.737
Clarified. Please enlighten me to create a meta post, I am not aware of the proper procedure. I am new to the SO scene. – Sam Weaver – 2014-09-26T22:24:38.883
@SamWeaver each SO site has an accompanying meta site in which users can ask about and discuss site policy. You can ask a question here and you may want to look at a few other meta questions to get a feel for what they're like. From what I've seen, you can directly reference your question in your meta question.
– krs013 – 2014-09-26T22:30:56.743I always remember this SO post each time there is a 2048 bot challenge, because his solution is so cool, achieving tile 8192 everytime on 100 runs.
– justhalf – 2014-10-01T01:26:06.817That's very very nice. – Sam Weaver – 2014-10-02T02:16:19.383
I will get to grading all the new submissions tomorrow. Sorry for the delay. :P – Sam Weaver – 2014-10-02T02:16:39.457