Conway jogo da vida em javascript (melhor sol [fechado]

Eu estou escrevendo um código para o jogo Conway da vida ...... Eu estou tomando 2> matrizes de uma geração de idade fr. e um para a 2ª geração.

** regras são: O universo do Jogo da Vida é uma grade ortogonal bidimensional de células quadradas, cada uma das quais está em um dos dois estados possíveis, vivos ou mortos. Cada célula interage com seus oito vizinhos, que são as células que estão na horizontal, vertical ou diagonalmente adjacentes. A cada passo no tempo, as seguintes transições ocorrem: ** 1. Qualquer célula viva com menos de dois vizinhos vivos morre, como se causada por subpopulação.

2. Qualquer célula viva com dois ou três vizinhos vivos vive para a próxima geração.

3. Qualquer célula viva com mais de três vizinhos vivos morre, como se estivesse em superlotação.

4.Qualquer célula morta com exatamente três vizinhos vivos se torna uma célula viva, como se fosse reproduzida. **

O padrão inicial constitui a semente do sistema. A primeira geração é criada aplicando as regras acima simultaneamente a cada célula da semente - nascimentos e mortes ocorrem simultaneamente, e o momento discreto em que isso acontece é às vezes chamado de carrapato (em outras palavras, cada geração é uma função pura do anterior). As regras continuam a ser aplicadas repetidamente para criar novas gerações. **

aqui está o código

Estou recebendo um soln, mas eu acho que não está me dando a solução correta, porque não está verificando os vizinhos dos cantos. Eu marquei essa parte

**

    window.conway =
    {
    };
    window.conway.maingame =
    {
    };
    conway.maingame = function(width, height)
    {
        window.a = [];
        this.width = width;
        this.height = height;
        this.map = new Array(width);
        for( i = 0; i < this.width; i++)
        {
            this.map[i] = new Array(height);
        }
        console.log(this.map, "map")
    }
    conway.maingame.prototype.randomize = function()
    {
        for( y = 0; y < this.height; y++)
        {
            //console.log("enter for loop")
            for( x = 0; x < this.width; x++)
            {
                if(Math.random() > .5)
                {
                    i =true;
                }
                else
                {
                    i = false;
                }
                //console.log("enter function")
                this.set(x, y, i);
            }
        }
    }
    conway.maingame.prototype.set = function(x, y, val)
    {
        x = x % this.width;
        y = y % this.height;
        this.map[x][y] = val;
        console.log(this.map, "map2");
    }
    conway.maingame.prototype.get = function(x, y)
    {
        x = x % this.width;
        y = y % this.height;
        return this.map[x][y];
    }
    *********************************************************************************
conway.maingame.prototype.neighbors = function(x, y)
    {
        count = 0;
        if(x > 0 && y > 0 && this.get(x + 1, y + 1))
        {
            console.log(this.get(x + 1, y + 1), "value neighbor");
            count++;
            console.log(count);
        }
        if(x > 0 && y > 0 && this.get(x + 1, y))
        {
            console.log(this.get(x + 1, y), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y > 0 && this.get(x + 1, y - 1))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y >=0 && this.get(x, y - 1))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y > 0 && this.get(x - 1, y - 1))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y > 0 && this.get(x - 1, y))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y > 0 && this.get(x - 1, y + 1))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        if(x > 0 && y > 0 &&this.get(x, y + 1))
        {
            console.log(this.get(x + 1, y - 1), "vallue neighbor");
            count++;
            console.log(count);
        }

        return count;
    }***
    conway.maingame.prototype.newgeneration = function()
    {
        var newMap = new Array(this.width);
        for( i = 0; i < this.width; i++)
        {
            newMap[i] = new Array(this.height);
        }
        for(var y = 0; y < this.height; y++)
        {
            for(var x = 0; x < this.width; x++)
            {
                console.log("enter all for");
                newMap[x][y] = this.get(x, y);
                console.log(newMap, "newarray");
                //Rule 1: any live cell with fewer than two live neighbors dies
                if(this.get(x, y) == true && this.neighbors(x, y) < 2)
                {
                    newMap[x][y] = false;
                    console.log("rule1");
                }
                //Rule 2: Any live cell with two or three live neighbours lives on to the next generation
                if(this.get(x, y) == true && this.neighbors(x, y) == 2 || this.neighbors(x, y) == 3)
                {
                    newMap[x][y] = true
                    console.log("rule2");
                }
                //Rule 3: any live cell with more than three live neighbors dies
                if(this.get(x, y) == true && this.neighbors(x, y) > 3)
                {
                    newMap[x][y] = false;
                    console.log("rule3");
                }
                //Rule 4: any dead cell with exactly three live neighbors becomes a live cell
                if(this.get(x, y) == false && this.neighbors(x, y) == 3)
                {
                    newMap[x][y] = true;
                    console.log("rule4");
                }
            }
        }
        this.map = newMap;
    console.log(this.map,"new generation")
    }

**

questionAnswers(1)

yourAnswerToTheQuestion