Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- b = []
- c = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- d = 0
- f = 0
- g = 0
- h = 0
- function newgame() {
- c = a
- a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- newtile()
- newtile()
- }
- function testtiles() {
- a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- }
- function swapitems(list, item1, item2) {
- b = [];
- for (let i = 0; i < list.length; i++) {
- if (i == item1) {
- b = b.concat([list[item2]])
- } else {
- if (i == item2) {
- b = b.concat([list[item1]])
- } else {
- b = b.concat([list[i]])
- }
- }
- }
- return b;
- }
- function move() {
- for (let j = 0; j < 4; j++) {
- if (a[4*j+2] == 0 && a[4*j+3] !== 0) {
- a = swapitems(a, 4*j+2, 4*j+3)
- }
- if (a[4*j+1] == 0 && a[4*j+2] !== 0) {
- a = swapitems(a, 4*j+1, 4*j+2)
- }
- if (a[4*j+0] == 0 && a[4*j+1] !== 0) {
- a = swapitems(a, 4*j+0, 4*j+1)
- }
- if (a[4*j+2] == 0 && a[4*j+3] !== 0) {
- a = swapitems(a, 4*j+2, 4*j+3)
- }
- if (a[4*j+1] == 0 && a[4*j+2] !== 0) {
- a = swapitems(a, 4*j+1, 4*j+2)
- }
- if (a[4*j+2] == 0 && a[4*j+3] !== 0) {
- a = swapitems(a, 4*j+2, 4*j+3)
- }
- }
- }
- function merge() {
- for (let j = 0; j < 4; j++) {
- if(a[4*j+0] == a[4*j+1] && a[4*j+0] !== 0) {
- a.splice(4*j+0, 1, a[4*j+0]+1)
- a.splice(4*j+1, 1, 0)
- }
- if(a[4*j+2] == a[4*j+3] && a[4*j+2] !== 0) {
- a.splice(4*j+2, 1, a[4*j+2]+1)
- a.splice(4*j+3, 1, 0)
- }
- if(a[4*j+1] == a[4*j+2] && a[4*j+1] !== 0) {
- a.splice(4*j+1, 1, a[4*j+1]+1)
- a.splice(4*j+2, 1, 0)
- }
- }
- }
- function rotate() {
- a = [].concat(a[12]).concat(a[8]).concat(a[4]).concat(a[0]).concat(a[13]).concat(a[9]).concat(a[5]).concat(a[1]).concat(a[14]).concat(a[10]).concat(a[6]).concat(a[2]).concat(a[15]).concat(a[11]).concat(a[7]).concat(a[3])
- }
- function newtile() {
- if (a.includes(0)) {
- d = Math.floor(Math.random()*16)
- while (a[d] !== 0) {
- d = Math.floor(Math.random()*16)
- }
- if (Math.random() > 0.1) {a.splice(d, 1, 1)} else {a.splice(d, 1, 2)}
- }
- }
- function moveA() {
- c = a
- move()
- merge()
- move()
- if (a.includes(0) && a !== c) {
- newtile()
- }
- }
- function moveW() {
- c = a
- rotate()
- rotate()
- rotate()
- move()
- merge()
- move()
- rotate()
- if (a.includes(0) && a !== c) {
- newtile()
- }
- }
- function moveD() {
- c = a
- rotate()
- rotate()
- move()
- merge()
- move()
- rotate()
- rotate()
- if (a.includes(0) && a !== c) {
- newtile()
- }
- }
- function moveS() {
- c = a
- rotate()
- move()
- merge()
- move()
- rotate()
- rotate()
- rotate()
- if (a.includes(0) && a !== c) {
- newtile()
- }
- }
- newtile()
- newtile()
- w.on("msg", (data) => {
- if (data.msg == "move left") {
- moveA()
- }
- if (data.msg == "move up") {
- moveW()
- }
- if (data.msg == "move right") {
- moveD()
- }
- if (data.msg == "move down") {
- moveS()
- }
- if (data.msg == "new game") {
- newgame()
- }
- });
- w.on("pong", (data) => {
- f = cursor.x
- g = cursor.start
- h = cursor.y
- for (let i = 0; i < 13; i++) {
- for (let j = 0; j < 13; j++) {
- cursor.x = j - 6
- cursor.y = i + 9
- writeChar(".", 0)
- }
- }
- for (let dx = 0; dx < 4; dx++) {
- for (let dy = 0; dy < 4; dy++) {
- cursor.x = dy*3-5
- cursor.y = dx*3+10
- writeChar(" 12482222"[a[dx*4+dy]], 0)
- }
- }
- for (let dx = 0; dx < 4; dx++) {
- for (let dy = 0; dy < 4; dy++) {
- cursor.x = dy*3-4
- cursor.y = dx*3+10
- writeChar(" 1250001^^^^"[a[dx*4+dy]], 0)
- }
- }
- for (let dx = 0; dx < 4; dx++) {
- for (let dy = 0; dy < 4; dy++) {
- cursor.x = dy*3-5
- cursor.y = dx*3+11
- writeChar(" 13625124991111"[a[dx*4+dy]], 0)
- }
- }
- for (let dx = 0; dx < 4; dx++) {
- for (let dy = 0; dy < 4; dy++) {
- cursor.x = dy*3-4
- cursor.y = dx*3+11
- writeChar(" 24862486248624567"[a[dx*4+dy]], 0)
- }
- }
- cursor.x = -6
- cursor.y = 7
- writeChar("2", 1)
- writeChar("0", 1)
- writeChar("4", 1)
- writeChar("8", 1)
- cursor.x = 10
- cursor.y = 14
- writeChar("W", 0)
- cursor.x = 8
- cursor.y = 15
- writeChar("A", 0)
- cursor.x = 10
- cursor.y = 16
- writeChar("S", 0)
- cursor.x = 12
- cursor.y = 15
- writeChar("D", 0)
- cursor.x = 10
- cursor.y = 18
- writeChar("+", 0)
- cursor.x = f
- cursor.start = g
- cursor.y = h
- });
- w.on("cursor", (data) => {
- if (data.l[0] ==10 && data.l[1] == 14) {
- moveW()
- }
- if (data.l[0] == 8 && data.l[1] == 15) {
- moveA()
- }
- if (data.l[0] == 10 && data.l[1] == 16) {
- moveS()
- }
- if (data.l[0] == 12 && data.l[1] == 15) {
- moveD()
- }
- if (data.l[0] == 10 && data.l[1] == 18) {
- newgame()
- }
- });
- w.chat.send("2048 bot initiated. say move direction to move tiles. say new game to make a new game. or maybe you can use the canvas keys if you don't wanna chat.", 0)
Advertisement
Add Comment
Please, Sign In to add comment