Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2017-02-19 13:12:35

Soubr
Member
Joined: 2015-02-18
Posts: 36

Tetris Bot [open source]

This bot idea has been done before but i decided to make my own version. The code is extremely unprofessional and hard to read, but since some people asked i'll post it . Also, i can't use github or anything like that so i'll just put the code written down here. If you want use it you must adjust it to your world (because of coordinates and so on), and in case you do it please give some credits.

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PlayerIOClient;
using System.Threading;
using System.IO;

/* bot by SOUB*/

namespace TetrisBot
{
    public partial class Form1 : Form
    {
        public static string[] leaderBoard1 = new string[2];
        public static string[] leaderBoard2 = new string[2];
        public static string[] leaderBoard3 = new string[2];
        public static StreamReader reader;
        public static StreamWriter writer;
        public static bool espaço = false;
        public static int rotou = 1;
        public static bool isRunning = false;
        public static int jogador;
        public static List<Player> fila = new List<Player>();
        public static List<Player> lista = new List<Player>();
        public Client client;
        public static Connection con;
        public static uint[, ,] salaData;

        public static int controle = 0;
        public Form1()
        {
            InitializeComponent();
        }
        public static void sendBlock(int layer, int x, int y, int id)
        {
            con.Send("b", layer, x, y, id);
            salaData[layer, x, y] = Convert.ToUInt32(id);
        }
        public static int[,] RotateMatrix(int[,] matrix, int n)
        {
            int[,] ret = new int[n, n];

            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    ret[i, j] = matrix[n - j - 1, i];
                }
            }

            return ret;
        }
        public static int[,] RotateCounter(int[,] matrix, int n)
        {
            int[,] ret = new int[n, n];
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    ret[i, j] = matrix[j, n - i - 1];
                }
            }

            return ret;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            reader = new StreamReader(@"C:\Users\Usuário\Desktop\Salas\leaderboard.txt");
            leaderBoard1 = reader.ReadLine().Split(' ');
            leaderBoard2 = reader.ReadLine().Split(' ');
            leaderBoard3 = reader.ReadLine().Split(' ');
            reader.Close();
        }
        static void Connection_OnMessage(object sender, PlayerIOClient.Message e)
        {
            switch (e.Type)
            {
                case "init":
                    con.Send("init2");
                    var roomData = new uint[2, e.GetInt(18), e.GetInt(19)];
                    var chunks = InitParse.Parse(e);
                    foreach (var chunk in chunks)
                        foreach (var pos in chunk.Locations)
                            roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
                    salaData = roomData;
                    break;
                case "b":
                    if (e.GetInteger(3) == 1029)
                    {
                        Console.WriteLine(e.GetInteger(1) + " " + e.GetInteger(2));
                    }
                    break;
                case "m":
                    if (e.GetInteger(0) == jogador)
                    {
                        if (e.GetInteger(7) == -1)
                        {
                            controle = 1;
                        }
                        if (e.GetInteger(7) == 1)
                        {
                            controle = 2;
                        }
                        /*if (e.GetInteger(7) == 0)
                        {
                            controle = 0;
                        }*/
                        if (e.GetInteger(8) == 1)
                        {
                            rotou = 1;
                        }
                        if (e.GetInteger(8) == -1)
                        {
                            rotou = -1;
                        }
                        if (e.GetBoolean(10))
                        {
                            for (int i = 0; i < lista.Count; i++)
                            {
                                if (lista[i].ID == jogador)
                                {
                                    if (lista[i].eHold)
                                    {
                                        espaço = true;
                                    }
                                }
                            }
                        }
                    }

                    break;
                case "say":
                    Console.WriteLine("MTT");
                    if (e.GetString(1) == "!play")
                    {
                        Point pont = new Point(92, 88);
                        Jogo j = new Jogo(pont);
                        Thread t = new Thread(j.gameLoop);
                    }
                    if (e.GetString(1) == "!queue" || e.GetString(1) == "!crises" || e.GetString(1) == "!check")
                    {
                        bool naFila = false;
                        for (int a = 0; a < fila.Count; a++)
                        {
                            if (fila[a].ID == e.GetInteger(0))
                            {
                                int x = a + 1;
                                con.Send("say", "/pm " + fila[a].nome + " You already in the queue in the position: " + x + " .To leave the queue type !leave");
                                naFila = true;
                            }
                        }
                        if (!naFila)
                        {
                            for (int q = 0; q < lista.Count; q++)
                            {
                                if (lista[q].ID == e.GetInteger(0))
                                {
                                    fila.Add(lista[q]);
                                    con.Send("say", "/pm " + lista[q].nome + " You have entered the queue in the position: " + fila.Count);
                                }
                            }
                        }
                    }
                    if (e.GetString(1) == "!leave")
                    {
                        for (int a = 0; a < fila.Count; a++)
                        {
                            if (fila[a].ID == e.GetInteger(0))
                            {
                                con.Send("say", "/pm " + fila[a].nome + " You have left the queue.");
                                fila.RemoveAt(a);
                            }
                        }
                    }
                    if (e.GetString(1) == "!hold")
                    {
                        for (int a = 0; a < lista.Count; a++)
                        {
                            if (lista[a].ID == e.GetInteger(0))
                            {
                                if (lista[a].eHold)
                                {
                                    con.Send("say", "/pm " + lista[a].nome + " You have disabled Hold (space)");
                                    lista[a].eHold = false;
                                }
                                else
                                {
                                    con.Send("say", "/pm " + lista[a].nome + " You have enabled Hold (space)");
                                    lista[a].eHold = true;
                                }
                            }
                        }
                    }
                    if (e.GetString(1) == "!commands")
                    {
                        for (int a = 0; a < lista.Count; a++)
                        {
                            if (lista[a].ID == e.GetInteger(0))
                            {
                                con.Send("say", "/pm " + lista[a].nome + " !hold - Enable/Disable hold feature;!queue - enter/check your position in queue;!leave - leave the queue; !leaderboards");
                            }
                        }
                    }
                    if (e.GetString(1) == "!leaderboards")
                    {
                        for (int a = 0; a < lista.Count; a++)
                        {
                            if (lista[a].ID == e.GetInteger(0))
                            {
                                con.Send("say", "/pm " + lista[a].nome + " 1- " + leaderBoard1[0] + ": " + leaderBoard1[1] + ". 2- " + leaderBoard2[0] + ": " + leaderBoard2[1] + ". 3- " + leaderBoard3[0] + ": " + leaderBoard3[1]);
                            }
                        }
                    }
                    break;
                case "add":
                    bool logado = false;

                    for (int a = 0; a < lista.Count; a++)
                    {
                        if (lista[a].ID == e.GetInteger(0))
                        {
                            logado = true;
                        }
                    }
                    if (!logado)
                    {
                       // Console.WriteLine("bemvindo");
                        lista.Add(new Player(e.GetInteger(0), e.GetString(1)));
                        con.Send("say", "/pm " + e.GetString(1) + " Welcome to Tetris Bot. Type '!queue' to play. Type '!commands' so see all the comands.");
                    }
                    break;
                case "left":

                    for (int a = 0; a < lista.Count; a++)
                    {
                        if (lista[a].ID == e.GetInteger(0))
                        {
                            if (jogador == lista[a].ID)
                            {
                               // Console.WriteLine("quitou");
                                isRunning = false;
                            }
                        }
                    }
                    for (int a = 0; a < fila.Count; a++)
                    {
                        if (fila[a].ID == e.GetInteger(0))
                        {
                            fila.RemoveAt(a);
                        }
                    }
                    break;


            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", textBox1.Text, textBox2.Text, null);
                con = client.Multiplayer.CreateJoinRoom(textBox3.Text, "public", true, new Dictionary<string, string>(), new Dictionary<string, string>());
                con.OnMessage += new MessageReceivedEventHandler(Connection_OnMessage);
                con.Send("init");

            }
            catch (Exception except)
            {
                MessageBox.Show("Erro" + except.ToString());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            while (true)
            {
                if (!isRunning)
                {
                    Point pont = new Point(92, 88);
                    Jogo j = new Jogo(pont);
                    j.gameLoop();
                }
            }
        }
    }

    public class Jogo
    {
        public bool holded = false;
        public bool holded2 = false;
        public bool maxSpeed = false;
        public int pontuaçao = 0;
        public Point display = new Point(104, 90);
        public Point displayH = new Point(104, 104);
        public int proxTipo = 4;
        public Point inicio;
        public double tickspeed = 17;
        public int currentTick = 0;
        public int[,] mapData = new int[20, 10];
        public int[,] ultimaPos = new int[4, 10];
        public Peça p;
        public Random r = new Random();
        public int hold;
        public void gameRender()
        {
            int test;
            for (int q = 0; q < 4; q++)
            {
                for (int w = 0; w < 10; w++)
                {
                    if (ultimaPos[q, w] != 0)
                    {
                        if (p.desceu)
                        {
                            test = 1;
                        }
                        else
                        {
                            test = 0;
                        }
                        if (q - test >= 0)
                        {
                            if (p.posiçao[q - test, w] == 0)
                            {
                                Form1.sendBlock(0, inicio.X + w, inicio.Y + p.altura + q - test, 0);
                                //Thread.Sleep(20);
                            }
                        }
                        else if (p.altura + q != 0)
                        {
                            Form1.sendBlock(0, inicio.X + w, inicio.Y + p.altura + q - test, 0);
                            //Thread.Sleep(20);
                        }
                        else
                        {
                            //Thread.Sleep(20);
                        }
                    }
                }
            }
            for (int a = 0; a < 4; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    if (p.posiçao[a, b] != 0)
                    {
                        if (Form1.salaData[0, inicio.X + b, inicio.Y + p.altura + a] == 0)
                        {
                            Form1.sendBlock(0, inicio.X + b, inicio.Y + p.altura + a, p.blocoId);
                            //Thread.Sleep(20);
                        }
                        else
                        {
                            //Thread.Sleep(20);
                        }
                    }
                }
            }
            Thread.Sleep(20);
        }
        public void novaPeça(int h)
        {
            holded = false;
            if (tickspeed > 6)
            {
                tickspeed -= 0.5;
            }
            else
            {
                tickspeed -= 0.06;
                if (!maxSpeed)
                {
                    Form1.con.Send("say", "Game has just reached hard mode");
                    maxSpeed = true;
                }
            }
            pontuaçao += 110;
            if (h != 0)
            {
                p = new Peça(h);
            }
            else
            {
                p = new Peça(proxTipo);
                proxTipo = r.Next(1, 8);
                for (int a = 0; a < 4; a++)
                {
                    for (int b = 0; b < 4; b++)
                    {
                        Form1.sendBlock(0, display.X + b, display.Y + a, 0);
                        Thread.Sleep(20);

                    }
                }
                int displayArray;
                if (proxTipo == 1)
                {
                    displayArray = 4;
                }
                else
                {
                    displayArray = 3;
                }
                int[,] displayPos = new int[displayArray, displayArray];
                displayPos = p.goThroughTipo(proxTipo, false);
                int displayId = p.goThroughId(proxTipo);

                for (int a = 0; a < displayArray; a++)
                {
                    for (int b = 0; b < displayArray; b++)
                    {
                        if (displayPos[a, b] != 0)
                        {
                            Form1.sendBlock(0, display.X + b, display.Y + a, displayId);
                            Thread.Sleep(20);
                        }

                    }
                }
            }

            for (int a = 0; a < 4; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    if (p.posiçao[a, b] != 0)
                    {
                        if (mapData[a, b] != 0)
                        {
                            Form1.isRunning = false;
                        }
                    }
                }
            }
            Array.Copy(p.posiçao, 0, ultimaPos, 0, p.posiçao.Length);
        }
        public void gameUpdate()
        {
            int cq = checarQuebra();
            int bonus = 0;
            while (cq != 420 && p.caindo == 2)
            {
                pontuaçao += 600 + bonus * 100;
                for (int a = 0; a < 10; a++)
                {
                    mapData[cq, a] = 0;
                    Form1.sendBlock(0, inicio.X + a, inicio.Y + cq, 0);
                    Thread.Sleep(20);
                }
                for (int a = cq - 1; a >= 0; a--)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        if (mapData[a, b] != 0)
                        {
                            Form1.sendBlock(0, inicio.X + b, inicio.Y + a, 0);
                            Thread.Sleep(35);
                            Form1.sendBlock(0, inicio.X + b, inicio.Y + a + 1, mapData[a, b]);
                            Thread.Sleep(35);
                            mapData[a + 1, b] = mapData[a, b];

                            mapData[a, b] = 0;
                        }
                    }
                }
                cq = checarQuebra();
                bonus += 1;
            }
            if (p.caindo == 2)
            {
                novaPeça(0);
            }
            p.desceu = false;
            if (!p.primeira)
            {
                if (currentTick >= tickspeed)
                {
                    p.descer(this);
                    if (Form1.espaço && !holded && !holded2 && p.caindo == 0)
                    {
                        Form1.espaço = false;
                        holded = true;
                        holded2 = true;
                        for (int i = 0; i < 4; i++)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                int test = 0;
                                if (p.desceu)
                                {
                                    test = 1;
                                }
                                if (ultimaPos[i, j] != 0)
                                {
                                    Form1.sendBlock(0, inicio.X + j, inicio.Y + p.altura + i - test, 0);
                                    Thread.Sleep(20);
                                }
                            }

                        }
                        for (int a = 0; a < 4; a++)
                        {
                            for (int b = 0; b < 4; b++)
                            {
                                Form1.sendBlock(0, displayH.X + b, displayH.Y + a, 0);
                                Thread.Sleep(20);

                            }
                        }
                        int displayArrayH;
                        if (p.tipo == 1)
                        {
                            displayArrayH = 4;
                            //Console.WriteLine("TA FAUDGASUDVYAS");
                        }
                        else
                        {
                            displayArrayH = 3;
                        }
                        int[,] displayHPos = new int[displayArrayH, displayArrayH];
                        displayHPos = p.goThroughTipo(p.tipo, false);
                        int displayIdH = p.goThroughId(p.tipo);

                        for (int a = 0; a < displayArrayH; a++)
                        {
                            for (int b = 0; b < displayArrayH; b++)
                            {
                                if (displayHPos[a, b] != 0)
                                {
                                    Form1.sendBlock(0, displayH.X + b, displayH.Y + a, displayIdH);
                                    Thread.Sleep(20);
                                }

                            }
                        }
                        int antigoH = hold;
                        hold = p.tipo;
                        novaPeça(antigoH);
                    }
                    currentTick = 0;
                }
                else
                {
                    currentTick += 1;
                }
            }
            else
            {
                if (holded2)
                {
                    p.descer(this);
                }
                p.primeira = false;
            }
            switch (Form1.controle)
            {
                case 1:
                    if (!holded2 || !p.primeira)
                    {
                        p.moverEsquerda(this);
                    }
                    break;
                case 2:
                    if (!holded2 || !p.primeira)
                    {
                        p.moverDireita(this);
                    }
                    break;
            }
            if (Form1.rotou == 1)
            {
                if (!holded2 || !p.primeira)
                {
                    p.rodar(this, 1);
                    Form1.rotou = 0;
                }
            }
            if (Form1.rotou == -1)
            {
                if (!holded2 || !p.primeira)
                {
                    p.rodar(this, -1);
                    Form1.rotou = 0;
                }
            }
            Form1.controle = 0;
            if (holded || holded2)
            {
                Form1.espaço = false;
            }
        }
        public int checarQuebra()
        {
            int coluna = 420;
            bool completo;
            for (int a = 0; a < 20; a++)
            {
                completo = true;
                for (int b = 0; b < 10; b++)
                {
                    if (mapData[a, b] == 0)
                    {
                        completo = false;
                        break;
                    }
                }
                if (completo)
                {
                    coluna = a;
                    break;
                }
            }
            return coluna;
        }
        public void gameLoop()
        {
            bool podeEntrar = false;
            while (!podeEntrar)
            {
                if (Form1.fila.Count > 0)
                {
                    Form1.jogador = Form1.fila[0].ID;
                    podeEntrar = true;
                    try
                    {
                        Thread.Sleep(100);
                        Form1.con.Send("say", "/tp " + Form1.fila[0].nome + " 105 98");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                    string exNome;
                    exNome = Form1.fila[0].nome;
                    Form1.fila.Add(Form1.fila[0]);
                    int tamanho = Form1.fila.Count - 1;
                    Thread.Sleep(200);
                    Form1.con.Send("say", "/pm " + exNome + " You have been relocated in the queue in the position: " + tamanho);
                    Thread.Sleep(20);
                    Form1.fila.RemoveAt(0);
                }

            }
            Thread.Sleep(1000);
            while (Form1.isRunning)
            {
                Thread.Sleep(10);
                Array.Copy(p.posiçao, 0, ultimaPos, 0, p.posiçao.Length);
                gameUpdate();
                gameRender();
                Console.WriteLine(p.caindo);
            }
            Thread.Sleep(4000);
            for (int a = 0; a < 20; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    Form1.sendBlock(0, inicio.X + b, inicio.Y + a, 0);
                    Thread.Sleep(35);
                }
            }
            for (int a = 0; a < 3; a++)
            {
                for (int b = 0; b < 3; b++)
                {
                    Form1.sendBlock(0, display.X + b, display.Y + a, 0);
                    Thread.Sleep(35);

                }
            }
            int[,] displayPos = p.goThroughTipo(4, false);
            for (int a = 0; a < 3; a++)
            {
                for (int b = 0; b < 3; b++)
                {
                    if (displayPos[a, b] != 0)
                    {
                        Form1.sendBlock(0, display.X + b, display.Y + a, 13);
                        Thread.Sleep(20);
                    }

                }
            }
            for (int a = 0; a < Form1.lista.Count; a++)
            {
                if (Form1.lista[a].ID == Form1.jogador)
                {
                    Form1.con.Send("say", "/kill " + Form1.lista[a].nome);
                    Thread.Sleep(200);
                    Form1.con.Send("say", Form1.lista[a].nome + " has just lost and made " + pontuaçao + " Points .A new game will start soon");
                    Thread.Sleep(2000);
                }
            }
            bool achou = false;
            if (Int32.Parse(Form1.leaderBoard1[1]) < pontuaçao)
            {
                Form1.writer = new StreamWriter(@"C:\Users\Usuário\Desktop\Salas\leaderboard.txt");
                string n = null;
                for (int x = 0; x < Form1.lista.Count; x++)
                {
                    if (Form1.lista[x].ID == Form1.jogador)
                    {
                        n = Form1.lista[x].nome;
                    }
                }

                Form1.writer.WriteLine(n + " " + pontuaçao);
                Form1.writer.WriteLine(Form1.leaderBoard1[0] + " " + Form1.leaderBoard1[1]);
                Form1.writer.WriteLine(Form1.leaderBoard2[0] + " " + Form1.leaderBoard2[1]);
                Form1.writer.Close();
                Form1.leaderBoard3[0] = Form1.leaderBoard2[0];
                Form1.leaderBoard3[1] = Form1.leaderBoard2[1];
                Form1.leaderBoard2[0] = Form1.leaderBoard1[0];
                Form1.leaderBoard2[1] = Form1.leaderBoard1[1];
                Form1.leaderBoard1[0] = n;
                Form1.leaderBoard1[1] = pontuaçao.ToString();
                Form1.con.Send("say", n + " Now holds the first position in the leaderboards!");
                achou = true;

            }
            if (Int32.Parse(Form1.leaderBoard2[1]) < pontuaçao && !achou)
            {
                Form1.writer = new StreamWriter(@"C:\Users\Usuário\Desktop\Salas\leaderboard.txt");
                string n = null;
                for (int x = 0; x < Form1.lista.Count; x++)
                {
                    if (Form1.lista[x].ID == Form1.jogador)
                    {
                        n = Form1.lista[x].nome;
                    }
                }

                Form1.writer.WriteLine(Form1.leaderBoard1[0] + " " + Form1.leaderBoard1[1]);
                Form1.writer.WriteLine(n + " " + pontuaçao);
                Form1.writer.WriteLine(Form1.leaderBoard2[0] + " " + Form1.leaderBoard2[1]);
                Form1.writer.Close();
                Form1.leaderBoard3[0] = Form1.leaderBoard2[0];
                Form1.leaderBoard3[1] = Form1.leaderBoard2[1];
                Form1.leaderBoard2[0] = n;
                Form1.leaderBoard2[1] = pontuaçao.ToString();
                Form1.con.Send("say", n + " Now holds the second position in the leaderboards!");
                achou = true;

            }
            if (Int32.Parse(Form1.leaderBoard3[1]) < pontuaçao && !achou)
            {
                Form1.writer = new StreamWriter(@"C:\Users\Usuário\Desktop\Salas\leaderboard.txt");
                string n = null;
                for (int x = 0; x < Form1.lista.Count; x++)
                {
                    if (Form1.lista[x].ID == Form1.jogador)
                    {
                        n = Form1.lista[x].nome;
                    }
                }

                Form1.writer.WriteLine(Form1.leaderBoard1[0] + " " + Form1.leaderBoard1[1]);
                Form1.writer.WriteLine(Form1.leaderBoard2[0] + " " + Form1.leaderBoard2[1]);
                Form1.writer.WriteLine(n + " " + pontuaçao);
                Form1.writer.Close();
                Form1.leaderBoard3[0] = n;
                Form1.leaderBoard3[1] = pontuaçao.ToString();
                Form1.con.Send("say", n + " Now holds the third position in the leaderboards!");
                achou = true;

            }
            for (int a = 0; a < 4; a++)
            {
                for (int b = 0; b < 4; b++)
                {
                    Form1.sendBlock(0, displayH.X + b, displayH.Y + a, 0);
                    Thread.Sleep(20);

                }
            }

        }
        public Jogo(Point ponto)
        {
            hold = r.Next(1, 8);
            Form1.isRunning = true;
            inicio = ponto;
            Array.Clear(mapData, 0, mapData.Length);
            novaPeça(0);
        }
    }
    public class Peça
    {
        public int tamanhoArray = 3;
        public bool desceu = false;
        public bool primeira;
        public int altura;
        public int movH = 0;
        public int tipo;
        public int[,] posiçao;
        public int[,] posRes = new int[4, 10];
        public int caindo = 0;
        public int blocoId;
        public bool possivel = true;
        public int[,] aRot = null;
        public int[,] bRot = null;
        public int[,] cRot = null;

        public Peça(int tipo)
        {
            primeira = true;
            this.tipo = tipo;
            altura = 0;
            caindo = 0;
            movH = 3;
            aRot = goThroughTipo(tipo, true);
            blocoId = goThroughId(tipo);
            if (tipo == 1)
            {
                tamanhoArray = 4;
            }
            bRot = new int[tamanhoArray, tamanhoArray];
            cRot = new int[tamanhoArray, tamanhoArray];
            Array.Copy(aRot, bRot, aRot.Length);
            switch (this.tipo)
            {
                case 1:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,0,15,0,0,0,0,0},
                    {0,0,0,0,15,0,0,0,0,0},
                    {0,0,0,0,15,0,0,0,0,0},
                    {0,0,0,0,15,0,0,0,0,0},
                    };
                    break;
                case 2:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,10,0,0,0,0,0,0},
                    {0,0,0,10,10,10,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
                case 3:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,0,0,1018,0,0,0,0},
                    {0,0,0,1018,1018,1018,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
                case 4:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,0,13,13,0,0,0,0},
                    {0,0,0,0,13,13,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
                case 5:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,0,12,12,0,0,0,0},
                    {0,0,0,12,12,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
                case 6:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,0,11,0,0,0,0,0},
                    {0,0,0,11,11,11,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
                case 7:
                    posiçao = new int[4, 10]{ 
                    {0,0,0,14,14,0,0,0,0,0},
                    {0,0,0,0,14,14,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0,0,0},
                    };
                    break;
            }

        }
        public int goThroughId(int e)
        {
            if (e == 1)
            {
                return 15;
            }
            else if (e == 2)
            {
                return 10;
            }
            else if (e == 3)
            {
                return 1018;
            }
            else if (e == 4)
            {
                return 13;
            }
            else if (e == 5)
            {
                return 12;
            }
            else if (e == 6)
            {
                return 11;
            }
            else if (e == 7)
            {
                return 14;
            }
            else
            {
                return 0;
            }
        }
        public int[,] goThroughTipo(int e, bool b)
        {
            if (e == 1)
            {
                return new int[4, 4]{
                        {0,15,0,0},
                        {0,15,0,0},
                        {0,15,0,0},
                        {0,15,0,0},
                    };
            }
            else if (e == 2)
            {
                return new int[3, 3]{
                        {10,0,0},
                        {10,10,10},
                        {0,0,0},
                    };
            }
            else if (e == 3)
            {
                return new int[3, 3]{
                        {0,0,1018},
                        {1018,1018,1018},
                        {0,0,0},
                    };
            }
            else if (e == 4)
            {
                if (b)
                {
                    this.possivel = false;
                }
                return new int[3, 3]{
                        {13,13,0},
                        {13,13,0},
                        {0,0,0},
                        };
            }
            else if (e == 5)
            {
                return new int[3, 3]{
                        {0,12,12},
                        {12,12,0},
                        {0,0,0},
                    };
            }
            else if (e == 6)
            {
                return new int[3, 3]{
                        {0,11,0},
                        {11,11,11},
                        {0,0,0},
                    };
            }
            else if (e == 7)
            {
                return new int[3, 3]{
                        {14,14,0},
                        {0,14,14},
                        {0,0,0},
                    };
            }
            else
            {
                return null;
            }

        }
        public void moverEsquerda(Jogo j)
        {
            int[,] casoQuebre = new int[4, 10];
            bool quebrou = false;
            if (posiçao[0, 0] == 0 && posiçao[1, 0] == 0 && posiçao[2, 0] == 0 && posiçao[3, 0] == 0)
            {
                Array.Clear(posRes, 0, posRes.Length);
                Array.Copy(posiçao, 0, casoQuebre, 0, posiçao.Length);
                for (int a = 0; a < 4; a++)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        if (posiçao[a, b] != 0)
                        {


                            if (j.mapData[altura + a, b - 1] == 0)
                            {
                                posRes[a, b - 1] = posiçao[a, b];
                                posiçao[a, b] = 0;
                            }
                            else
                            {
                                quebrou = true;
                                a = 10;
                                Array.Copy(casoQuebre, 0, posiçao, 0, casoQuebre.Length);
                                break;
                            }
                        }
                    }
                }
                if (!quebrou)
                {
                    movH -= 1;
                    Array.Copy(posRes, 0, posiçao, 0, posiçao.Length);
                }
            }
        }
        public void moverDireita(Jogo j)
        {
            int[,] casoQuebre = new int[4, 10];
            bool quebrou = false;
            if (posiçao[0, 9] == 0 && posiçao[1, 9] == 0 && posiçao[2, 9] == 0 && posiçao[3, 9] == 0)
            {
                Array.Copy(posiçao, 0, casoQuebre, 0, casoQuebre.Length);
                Array.Clear(posRes, 0, posRes.Length);
                for (int a = 0; a < 4; a++)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        if (posiçao[a, b] != 0)
                        {

                            if (j.mapData[altura + a, b + 1] == 0)
                            {
                                posRes[a, b + 1] = posiçao[a, b];
                                posiçao[a, b] = 0;
                            }
                            else
                            {
                                quebrou = true;
                                a = 10;
                                Array.Copy(casoQuebre, 0, posiçao, 0, posiçao.Length);
                                break;
                            }
                        }
                    }
                }
                if (!quebrou)
                {
                    movH += 1;
                    Array.Copy(posRes, 0, posiçao, 0, posRes.Length);
                }
            }
        }
        public void descer(Jogo j)
        {
            bool válido = true;
            desceu = true;
            for (int a = 0; a < 4; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    if (posiçao[a, b] != 0)
                    {
                        if (altura + a == 19 || j.mapData[altura + a + 1, b] != 0)
                        {
                            válido = false;
                            j.holded2 = false;
                            desceu = false;
                            for (int q = 0; q < 4; q++)
                            {
                                for (int w = 0; w < 10; w++)
                                {
                                    if (posiçao[q, w] != 0)
                                    {
                                        j.mapData[altura + q, w] = posiçao[q, w];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (válido)
            {
                altura += 1;
                caindo = 0;
            }
            else
            {
                caindo += 1;
            }


        }
        public void rodar(Jogo j, int w)
        {
            bool rodando = true;
            bool dnv = false;
            bool ruim = false;
            int[,] backup = new int[4, 10];
            Array.Copy(posiçao, backup, backup.Length);
            if (possivel)
            {
                if (w == 1)
                {
                    cRot = Form1.RotateMatrix(bRot, tamanhoArray);
                }
                if (w == -1)
                {
                    cRot = Form1.RotateCounter(bRot, tamanhoArray);
                }
                Array.Copy(cRot, bRot, cRot.Length);
                Array.Clear(posiçao, 0, posiçao.Length);
                while (rodando)
                {
                    dnv = false;
                    for (int a = 0; a < tamanhoArray; a++)
                    {
                        for (int b = 0; b < tamanhoArray; b++)
                        {
                            if (b + movH < 0)
                            {
                                moverDireita(j);
                                dnv = true;
                                a = 10;
                                break;
                            }
                            if (b + movH > 9)
                            {
                                moverEsquerda(j);
                                dnv = true;
                                a = 10;
                                break;
                            }
                            if (a + altura + 1 < 20 && !dnv)
                            {
                                posiçao[a, b + movH] = bRot[a, b];
                                if (j.mapData[a + altura + 1, b + movH] != 0)
                                {
                                    ruim = true;
                                    a = 10;
                                    rodando = false;
                                    break;
                                }
                            }
                            else if (a + altura + 1 >= 20)
                            {
                                rodando = false;
                                ruim = true;
                                a = 10;
                                break;
                            }
                        }
                    }
                    if (ruim)
                    {
                        Array.Copy(backup, posiçao, posiçao.Length);
                    }
                    else if (!dnv)
                    {
                        rodando = false;
                    }
                }
            }
        }

    }
    public static class InitParse
    {
        public static DataChunk[] Parse(PlayerIOClient.Message m)
        {
            if (m == null) throw new ArgumentNullException("m");
            if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");

            // Get world data
            var p = 0u;
            var data = new Stack<object>();
            while (m[p++] as string != "ws") { }
            while (m[p] as string != "we") { data.Push(m[p++]); }

            // Parse world data
            var chunks = new List<DataChunk>();
            while (data.Count > 0)
            {
                var args = new Stack<object>();
                while (!(data.Peek() is byte[]))
                    args.Push(data.Pop());

                var ys = (byte[])data.Pop();
                var xs = (byte[])data.Pop();
                var layer = (int)data.Pop();
                var type = (uint)data.Pop();

                chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
            }
            return chunks.ToArray();
        }
    }
    public class DataChunk
    {
        public int Layer { get; set; }
        public uint Type { get; set; }
        public Point[] Locations { get; set; }
        public object[] Args { get; set; }

        public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
        {
            this.Layer = layer;
            this.Type = type;
            this.Args = args;
            this.Locations = GetLocations(xs, ys);
        }
        private static Point[] GetLocations(byte[] xs, byte[] ys)
        {
            var points = new List<Point>();
            for (var i = 0; i < xs.Length; i += 2)
                points.Add(new Point(
                    (xs[i] << 8) | xs[i + 1],
                    (ys[i] << 8) | ys[i + 1]));
            return points.ToArray();
        }
    }
    public class Player
    {
        public bool eHold = false;
        public int ID;
        public string nome;
        public Player(int id, string nome)
        {
            this.ID = id;
            this.nome = nome;
        }
    }
}

There're still some glitches unpatched, feel free to try to fix them.

Offline

Wooted by: (2)
Soubr1487506355648203

Board footer

Powered by FluxBB

[ Started around 1713400556.1842 - Generated in 0.219 seconds, 13 queries executed - Memory usage: 1.45 MiB (Peak: 1.72 MiB) ]