Juego de la vida de Conway en javascript (mejor sol [cerrado]

Estoy escribiendo un código para el juego de la vida de Conway ...... Estoy tomando 2> arreglos de una generación anterior. y uno para 2ª generación.

** las reglas son: El universo del Juego de la Vida es una cuadrícula ortogonal infinita bidimensional de celdas cuadradas, cada una de las cuales se encuentra en uno de los dos estados posibles, vivo o muerto. Cada celda interactúa con sus ocho vecinos, que son las celdas que son horizontal, vertical o diagonalmente adyacentes. En cada paso en el tiempo, ocurren las siguientes transiciones: ** 1. Cualquier célula viva con menos de dos vecinos vivos muere, como si fuera causada por una subpoblación.

2. Cualquier célula viva con dos o tres vecinos vivos vive en la siguiente generación.

3. Cualquier célula viva con más de tres vecinos vivos muere, como por hacinamiento.

4. Cualquier célula muerta con exactamente tres vecinos vivos se convierte en una célula viva, como por reproducción. **

El patrón inicial constituye la semilla del sistema. La primera generación se crea aplicando las reglas anteriores simultáneamente a cada célula de la semilla: los nacimientos y las muertes ocurren simultáneamente, y el momento discreto en el que esto sucede a veces se llama una garrapata (en otras palabras, cada generación es una función pura de la una precedente). Las reglas se siguen aplicando repetidamente para crear generaciones futuras. **

aquí está el código

Estoy recibiendo una solución pero supongo que no me está dando la solución correcta porque no está verificando a los vecinos de las esquinas. he marcado esa 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")
    }

**

Respuestas a la pregunta(1)

Su respuesta a la pregunta