Ejemplo n.º 1
0
        public void MoveCurrentTetriminoLeft()
        {
            ValidateCurrentTetriminoMissing();

            if (TetrisBoard.CanMoveTetrimino(CurrentTetrimino, new Point(-1, 0)))
            {
                TetrisBoard.MoveTetrimino(CurrentTetrimino, new Point(-1, 0));
            }
        }
Ejemplo n.º 2
0
 public void CleanRows()
 {
     foreach (Block[] row in TetrisBoard.BlocksInRows())
     {
         int at_y = TetrisBoard.BlockPoint(row[0]).Y;
         ClearRow(row);
         FillRowGapAt(at_y);
     }
 }
Ejemplo n.º 3
0
 void Awake()
 {
     if (board == null)
     {
         board = ScriptableObject.CreateInstance <TetrisBoard>();
         board.parentWindow = this;
         Repaint();
     }
 }
Ejemplo n.º 4
0
        public void RotateCurrentTetrimino(Rotation rotation)
        {
            ValidateCurrentTetriminoMissing();

            if (TetrisBoard.CanRotate(CurrentTetrimino, rotation))
            {
                TetrisBoard.Rotate(CurrentTetrimino, rotation);
            }
        }
Ejemplo n.º 5
0
    public override void InstallBindings()
    {
        var gameSettings = GameSettingsInstaller.InstallFromResource("GameSettingsInstaller") as GameSettingsInstaller;

        this.tetrisBoard = new TetrisBoard(gameSettings.BoardRow, gameSettings.BoardCol);

        Container.Bind <GameObject>().WithId("TetrisBlockPrefab").FromInstance(gameSettings.TetrisBlockPrefab);
        Container.Bind <float>().WithId("IterateTestWaitTime").FromInstance(0.1f);
        Container.Bind <TetrisBoard>().FromInstance(tetrisBoard).AsSingle();
        Container.BindFactory <TetrisPiece, TetrisPiece.Factory>();
    }
Ejemplo n.º 6
0
    // ACCESSOR PARTS
    //static bool UpdateOverclock = true;

    public void Setup()
    {
        TetrisBoard.Setup();

        // Get Histogram
        OPH = MonoBehaviour.FindObjectOfType <OutputPerceptronHistogram>();
        if (OPH == null)
        {
            Debug.LogError("Missing Output Perceptron Histogram");
        }
    }
Ejemplo n.º 7
0
        public void DropCurrentTetrimino()
        {
            ValidateCurrentTetriminoMissing();

            if (TetrisBoard.CanMoveTetrimino(CurrentTetrimino, new Point(0, 1)))
            {
                TetrisBoard.MoveTetrimino(CurrentTetrimino, new Point(0, 1));
            }
            else
            {
                CurrentTetriminoIsLocked = true;
            }
        }
Ejemplo n.º 8
0
    void OnGUI()
    {
        if (board != null)
        {
            Event e = Event.current;

            switch (e.type)
            {
            case EventType.keyDown:
                if ((e.keyCode == KeyCode.A || e.keyCode == KeyCode.LeftArrow) && areKeysUp)
                {
                    board.MoveShapeLeft();
                    areKeysUp = false;
                }
                else if ((e.keyCode == KeyCode.D || e.keyCode == KeyCode.RightArrow) && areKeysUp)
                {
                    board.MoveShapeRight();
                    areKeysUp = false;
                }
                else if (e.keyCode == KeyCode.J || e.keyCode == KeyCode.Z)
                {
                    board.RotateShape(TetrisShape.RotateDirection.CounterClockwise);
                }
                else if (e.keyCode == KeyCode.L || e.keyCode == KeyCode.C)
                {
                    board.RotateShape(TetrisShape.RotateDirection.Clockwise);
                }
                else if (e.keyCode == KeyCode.Space && areKeysUp)
                {
                    board.DropShape();
                    areKeysUp = false;
                }

                break;

            case EventType.keyUp:
                areKeysUp = true;
                break;
            }

            board.Draw();
        }
        else
        {
            if (GUILayout.Button("New Game?"))
            {
                board = ScriptableObject.CreateInstance <TetrisBoard>();
                board.parentWindow = this;
            }
        }
    }
Ejemplo n.º 9
0
    void CommonInstall()
    {
        PreInstall();

        var gameSettings = GameSettingsInstaller.InstallFromResource("GameSettingsInstaller");

        TetrisBoard tetrisBoard = new TetrisBoard(gameSettings.BoardRow, gameSettings.BoardCol);

        Container.Bind <GameObject>().WithId("TetrisBlockPrefab").FromInstance(gameSettings.TetrisBlockPrefab);
        Container.Bind <TetrisBoard>().FromInstance(tetrisBoard).AsSingle();
        Container.BindFactory <TetrisPiece, TetrisPiece.Factory>();

        PostInstall();
    }
Ejemplo n.º 10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            board.insertionPoint = new PointF(this.Attributes.Pivot.X - (float)((board.columns / 2.0) * board.cellSize), this.Attributes.Pivot.Y + 20);


            Grasshopper.Instances.ActiveCanvas.CanvasPaintBackground -= canvasPaintHandler;
            Grasshopper.Instances.ActiveCanvas.CanvasPaintBackground += canvasPaintHandler;

            if (board.gameActive)
            {
                if (Keyboard.IsKeyDown(Key.Right))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveRight();
                }

                if (Keyboard.IsKeyDown(Key.Left))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveLeft();
                }

                if (Keyboard.IsKeyDown(Key.Down))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveDown();
                }

                if (Keyboard.IsKeyDown(Key.Up))
                {
                    Thread.Sleep(50);
                    board.activepiece.Rotate();
                }

                board.CheckForFullRows();
            }

            else
            {
                if (Keyboard.IsKeyDown(Key.Enter))
                {
                    this.board             = new TetrisBoard(Grasshopper.Instances.ActiveCanvas, 20, 10, 35);
                    this.board.activepiece = board.NewRandomPiece();
                    board.insertionPoint   = new PointF(this.Attributes.Pivot.X - (float)((board.columns / 2.0) * board.cellSize), this.Attributes.Pivot.Y + 20);
                }
            }


            ExpireSolution(true);
        }
Ejemplo n.º 11
0
        public RussianInterlocking()
            : base("Russian Interlocking", "Tetris",
                   "Move with arrows, rotate with arrow up, reset with enter",
                   "Interlocking System", "Components")
        {
            board             = new TetrisBoard(Grasshopper.Instances.ActiveCanvas, 20, 10, 35);
            board.activepiece = board.NewRandomPiece();

            //Change the panning function froms the arrows to WASD keys so arrows can be use to play

            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanRight = System.Windows.Forms.Keys.A;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanLeft  = System.Windows.Forms.Keys.D;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanDown  = System.Windows.Forms.Keys.W;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanUp    = System.Windows.Forms.Keys.S;
        }
Ejemplo n.º 12
0
    // Called to figure out next move of AI
    public void UpdateAI()
    {
        // Update Input
        float[] InputArray = TetrisBoard.GetData();

        Tetris.Move Choice = Tetris.Move.WAIT;

        // Update Epoch
        int BestOutput = _EpochManager.GetCurrentEpochBestOutput(InputArray);

        if (BestOutput != -1)
        {
            Choice = (Tetris.Move)BestOutput;
        }

        // Set Winning Move
        _AI_Move = Choice;
    }
Ejemplo n.º 13
0
    // End Current Game
    private void EndGame()
    {
        //Debug.Log("GAMEOVER");
        if (_Controller == Control.NEURAL_NETWORL)
        {
            // Count total empty spaces
            float empty_slots = TetrisBoard._TotalCells - TetrisBoard.CountSolidsInBoard();
            IncreaseFitness(ScoreSystemManager.GetCurrent().GameOver_EmptySlots *empty_slots);

            // Increase Fitness by the
            IncreaseFitness(ScoreSystemManager.GetCurrent().Per_Piece_Placed *(float)_PiecesUsed);

            // Calculate Fitness from Heuristics
            TetrisPerceptronManager.GetInstance().FinishCurrentAI(_Fitness);
            GameplayManager.GetInstance()._Histogram.AddValue(_Fitness);
        }

        ResetGame();
    }
Ejemplo n.º 14
0
    public Tetromino(int gridWidth, TetrisBoard board)
    {
        int i = Random.Range(0, 7);

        switch (i)
        {
        case 0:
            type = S_LEFT;
            break;

        case 1:
            type = S_RIGHT;
            break;

        case 2:
            type = L_LEFT;
            break;

        case 3:
            type = L_RIGHT;
            break;

        case 4:
            type = CROSS;
            break;

        case 5:
            type = STRAIGHT;
            break;

        default:
            type = SQUARE;
            break;
        }

        rotation       = Random.Range(0, 4);
        column         = 3;
        this.gridWidth = gridWidth;
        this.board     = board;

        ResolvePosition();
    }
    void OnDrawGizmos()
    {
        TetrisBoard board = gameObject.GetComponent <TetrisBoard>();
        float       xs    = transform.lossyScale.x;
        float       ys    = transform.lossyScale.y;

        float   width  = board.Width * board.PrefabSize.x;
        float   height = board.Height * board.PrefabSize.y;
        Vector3 size   = new Vector3(width * xs, height * ys, 0);

        float x = transform.position.x + (board.StartingLocation.x +
                                          width / 2 - board.PrefabSize.x / 2) * xs;
        float y = transform.position.y + (board.StartingLocation.y -
                                          height / 2 + board.PrefabSize.y / 2) * ys;
        float z = transform.position.z + board.StartingLocation.z;

        Vector3 position = new Vector3(x, y, z);

        Gizmos.DrawCube(position, size);
    }
Ejemplo n.º 16
0
        private void FillRowGapAt(int atY)
        {
            for (int y = TetrisBoard.Height - 1; y >= 0; y--)
            {
                if (y > atY)
                {
                    continue;
                }

                for (int x = 0; x < TetrisBoard.Width; x++)
                {
                    Block block = TetrisBoard.BlockAt(new Point(x, y));
                    if (block == null)
                    {
                        continue;
                    }

                    TetrisBoard.MoveBlock(block, new Point(0, 1));
                }
            }
        }
Ejemplo n.º 17
0
    void ApplyTetromino()
    {
        if (tetr != null)
        {
            List <IntPair> list = tetr.GetTileCoordinates();
            if (tetr.isValid())
            {
                foreach (IntPair p in list)
                {
                    GameBoard.set(p.x, p.y, 1);
                }

                List <int> rows = GameBoard.getCompletedRows();
                if (rows.Count > 0)
                {
                    GameBoard.deleteRows(rows);
                }

                piecesLeft--;
                if (piecesLeft > 0)
                {
                    tetr = new Tetromino(G_WIDTH, GameBoard, GetPiece());
                }
                else
                {
                    NeedyModule.HandlePass();
                    tetr = null;
                }
                UpdateGrid();
            }
            else
            {
                NeedyModule.OnStrike();
                NeedyModule.HandlePass();
                tetr      = null;
                GameBoard = new TetrisBoard(G_WIDTH, G_WIDTH);
                UpdateGrid();
            }
        }
    }
Ejemplo n.º 18
0
    void Init(
        TetrisPiece.Factory tetrisPieceFactory,
        TetrisBoard tetrisBoard,
        [Inject(Id = "TetrisBlockPrefab")]
        GameObject tetrisBlockPrefab
        )
    {
        this.tetrisPieceFactory = tetrisPieceFactory;
        this.tetrisBoard        = tetrisBoard;
        this.tetrisBlockPrefab  = tetrisBlockPrefab;

        tetrisBoard.onCellCleared += TetrisBoard_OnCellCleared;

        // setup block size
        BoxCollider boxCollider = tetrisBlockPrefab.GetComponent <BoxCollider>();

        blockSize.x = tetrisBlockPrefab.transform.localScale.x * boxCollider.size.x;
        blockSize.y = tetrisBlockPrefab.transform.localScale.y * boxCollider.size.y;
        blockSize.z = tetrisBlockPrefab.transform.localScale.z * boxCollider.size.z;

        InitDebug();
    }
Ejemplo n.º 19
0
        public GameScreen CreateGameScreen()
        {
            GameScreen.KeyMapping keyMapping;

            if (_gameSettings.Controlls == "simple ")
            {
                keyMapping = GameScreen.KeyMapping.SIMPLE;
            }
            else if (_gameSettings.Controlls == "complex")
            {
                keyMapping = GameScreen.KeyMapping.COMPLEX;
            }
            else
            {
                throw new System.Exception("Non-existant keyMapping");
            }

            TetrisBoard         tetrisBoard         = new TetrisBoard(10, 20);
            TetrisBoardOperator tetrisBoardOperator = new TetrisBoardOperator(tetrisBoard);

            Tetriminos.Factory tetriminoFactory = new Tetriminos.Factory(_colorHelper);

            return(new GameScreen(this, keyMapping, tetrisBoardOperator, tetriminoFactory));
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Spawn the tetromino at the given position.
 /// Returns false if the tetromino could not be spawned.
 /// </summary>
 public bool Spawn(TetrisBoard board, Vector2Int position)
 {
     this.Position = position;
     this.Board    = board;
     return(board.IsValidPosition(position, this));
 }
Ejemplo n.º 21
0
 // Use this for initialization
 void Awake()
 {
     game  = gameObject.GetComponent <TetrisGame>();
     board = gameObject.GetComponent <TetrisBoard>();
 }
Ejemplo n.º 22
0
    // Add piece to board
    private void AddPieceToBoard()
    {
        // Move piece back up 1
        _Piece._y++;

        // Score from crowded section
        int section = TetrisBoard.CheckPieceInCrowd(ScoreSystemManager.GetCurrent().Section_Counts_As_Width_Divided_By);

        if (section == -1)
        {
            IncreaseFitness(ScoreSystemManager.GetCurrent().NonCrowded_Section);
        }
        else if (section == 1)
        {
            IncreaseFitness(ScoreSystemManager.GetCurrent().Crowded_Section);
        }

        // Current Bumpiness
        float Bump_Old = TetrisHeuristics.CalculateBumpiness();
        // Current Holes
        float Holes_Old = TetrisHeuristics.CountHoles();

        /* */
        /* */

        // Add piece to board
        TetrisBoard.AddSolidsToBoardFromPiece();

        // Remove Horizontal Lines
        LineClear LC = TetrisBoard.UpdateCompletedLines();

        // Give score for those lines
        if (!GameplayManager.GetInstance().LinesDoNotClear)
        {
            IncreaseScoreFromLineClear(LC);
        }

        /* */
        /* */

        // Current Bumpiness
        float Bump = TetrisHeuristics.CalculateBumpiness();

        IncreaseFitness(ScoreSystemManager.GetCurrent().BumpAverage *Bump);

        // Change in Bumpiness
        float Bump_Change = Bump - Bump_Old;

        IncreaseFitness(ScoreSystemManager.GetCurrent().BumpFixMultiplier *Bump_Change);

        // Change in Holes
        float Holes_Change = Mathf.Max(0.0f, TetrisHeuristics.CountHoles() - Holes_Old);

        IncreaseFitness(ScoreSystemManager.GetCurrent().HoleAdded *Holes_Change);
        // Current Aggregate Height Score
        float AggregateHeightScore = TetrisHeuristics.AggregateHeight() * ScoreSystemManager.GetCurrent().AggregateHeightChangedMultiplier;

        IncreaseFitness(AggregateHeightScore);

        // Check Values for Testing
        //Debug.Log("Aggregate Height: " + TetrisHeuristics.AggregateHeight());
        //Debug.Log("Complete Rows: " + TetrisHeuristics.CalculateCompleteRows());
        //Debug.Log("Holes: " + TetrisHeuristics.CountHoles());
        //Debug.Log("Bumpiness: " + TetrisHeuristics.CalculateBumpiness());
        //Debug.Log("~~~");

        // Score from height
        float y_level      = (float)(_Piece._WorldMin.y) / 24.0f;
        float height_score = Mathf.Lerp(
            ScoreSystemManager.GetCurrent().Height_Lerp_Bot,
            ScoreSystemManager.GetCurrent().Height_Lerp_Top,
            y_level);

        IncreaseFitness(height_score);

        // Score from bottom row
        float BottomCount = TetrisHeuristics.CountTetrisPiecesRow(0);

        IncreaseFitness(ScoreSystemManager.GetCurrent().Bottom_Row *BottomCount);

        // Score from top 2 rows
        float TopCount = TetrisHeuristics.CountTetrisPiecesRow(TetrisBoard._Height - 1);

        TopCount += TetrisHeuristics.CountTetrisPiecesRow(TetrisBoard._Height - 2);
        IncreaseFitness(ScoreSystemManager.GetCurrent().Top_2_Rows *TopCount);

        // Reset Piece
        _Piece._Type = Tetrominoes.NONE;

        // Add Total Pieces Added
        _PiecesUsed++;
    }
Ejemplo n.º 23
0
 public TetrisBoardOperator(TetrisBoard tetrisBoard)
 {
     TetrisBoard = tetrisBoard;
 }
 // Use this for initialization
 void Start()
 {
     board = gameObject.GetComponent <TetrisBoard>();
     //board.BoardChanged += Board_BoardChanged;
 }
Ejemplo n.º 25
0
 public int Rows()
 {
     return(TetrisBoard.BlocksInRows().Count);
 }
Ejemplo n.º 26
0
 void ITetrisStateObserver.HandleBoardUpdated(TetrisBoard newBoard)
 {
     _board = newBoard;
     Update();
 }
Ejemplo n.º 27
0
        //private int _shapeColor = 1;

        public GameScreen(int x, int y, int width, int height, char borderChar) : base(x, y, width, height, borderChar)
        {
            _tetrisBoard = new TetrisBoard(x, y, width, height);

            //bool checkTest = _tetrisBoard.IsPointInGridPlace(58,6);
        }
Ejemplo n.º 28
0
    public static Epoch LoadFile(string Data)
    {
        int _ExpectedLength = 8;

        // Expect 2 variables
        if (Data.Length < _ExpectedLength)
        {
            Debug.LogError("File too small (a)");
            return(null);
        }

        // File index
        int FileIndex = 0;

        // Important Data from start of file
        int hidden_layers = (int)FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));

        FileIndex += 4;
        Debug.Log("hidden layers: " + hidden_layers);

        int hidden_layers_size = (int)FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));

        FileIndex += 4;
        Debug.Log("hidden layer sizes: " + hidden_layers_size);

        // Expect (hidden_layers * hidden_layers_size * 4)
        // Expect 2 more variables (output size + output weight count)
        _ExpectedLength += (hidden_layers * hidden_layers_size * 4) + 8;
        if (Data.Length < _ExpectedLength)
        {
            Debug.LogError("File too small (b)");
            return(null);
        }

        List <int> hidden_layer_weight_count = new List <int>();

        for (int i = 0; i < hidden_layers; i++)
        {
            for (int j = 0; j < hidden_layers_size; j++)
            {
                hidden_layer_weight_count.Add((int)FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4)));
                FileIndex += 4;
                //Debug.Log("Hidden Layer: " + (i + 1) + ", Perceptron: " + (j + 1) + ", Size: " + hidden_layer_weight_count[j]);
            }
        }

        int output_layer_size = (int)FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));

        FileIndex += 4;
        Debug.Log("output layer size: " + output_layer_size);

        int output_layer_weightcount = (int)FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));

        FileIndex += 4;
        Debug.Log("Output Layer, Perceptron Size: " + output_layer_weightcount);

        Debug.Log("~~~");

        // Check if file is correct size

        // Expect
        for (int i = 0; i < hidden_layers; i++)
        {
            for (int j = 0; j < hidden_layers_size; j++)
            {
                _ExpectedLength += 4;
                _ExpectedLength += hidden_layer_weight_count[j] * 4;
            }
        }
        for (int i = 0; i < output_layer_size; i++)
        {
            _ExpectedLength += 4;
            _ExpectedLength += output_layer_weightcount * 4;
        }
        for (int i = 0; i < TetrisBoard.GetDataSize(); i++)
        {
            _ExpectedLength += 8;
        }
        if (Data.Length < _ExpectedLength)
        {
//#if UNITY_EDITOR
//            string Message = "File Too Small\n";
//            Message += "File Count: " + Data.Length.ToString() + "\n";
//            Message += "Expected Count: " + _ExpectedLength.ToString() + "\n";
//            EditorUtility.DisplayDialog("File Size", Message, "Continue");
//#endif
            return(null);
        }
        else if (Data.Length > _ExpectedLength)
        {
//#if UNITY_EDITOR
//            string Message = "File Too Big\n";
//            Message += "File Count: " + Data.Length.ToString() + "\n";
//            Message += "Expected Count: " + _ExpectedLength.ToString() + "\n";
//            EditorUtility.DisplayDialog("File Size", Message, "Continue");
//#endif
            return(null);
        }
//#if UNITY_EDITOR
//        else
//        {
//            EditorUtility.DisplayDialog("File Size", "Correct Size", "Continue");
//        }
//#endif


        // Read Hidden Layers
        List <List <Perceptron> > All_HiddenLayer = new List <List <Perceptron> >();

        for (int i = 0; i < hidden_layers; i++)
        {
            List <Perceptron> HiddenLayer = new List <Perceptron>();
            for (int j = 0; j < hidden_layers_size; j++)
            {
                // Get Bias
                float bias = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
                FileIndex += 4;
                //Debug.Log("Layer: " + (i + 1) + ", Perceptron: " + (j + 1) + ", Bias: " + bias);
                // Get all weights
                float[] weights = new float[hidden_layer_weight_count[j]];
                for (int k = 0; k < hidden_layer_weight_count[j]; k++)
                {
                    weights[k] = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
                    FileIndex += 4;
                    //Debug.Log("Layer: " + (i + 1) + ", Perceptron: " + (j + 1) + ", Weight[" + (k) + "]: " + weights[k]);
                }
                Perceptron P = new Perceptron(weights, bias);
                HiddenLayer.Add(P);
            }
            All_HiddenLayer.Add(HiddenLayer);
        }

        // Read Output Layer
        List <Perceptron> OutputLayer = new List <Perceptron>();

        for (int i = 0; i < output_layer_size; i++)
        {
            // Get Bias
            float bias = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
            FileIndex += 4;
            //Debug.Log("Output Perceptron: " + (i + 1) + ", Bias: " + bias);
            // Get all weights
            float[] weights = new float[output_layer_weightcount];
            for (int k = 0; k < output_layer_weightcount; k++)
            {
                weights[k] = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
                FileIndex += 4;
                //Debug.Log("Output Perceptron: " + (i + 1) + ", Weight[" + (k) + "]: " + weights[k]);
            }
            Perceptron P = new Perceptron(weights, bias);
            OutputLayer.Add(P);
        }

        // Read Input Layer
        List <Perceptron> InputLayer = new List <Perceptron>();

        for (int i = 0; i < TetrisBoard.GetDataSize(); i++)
        {
            // Get Bias
            float bias = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
            FileIndex += 4;
            //Debug.Log("Output Perceptron: " + (i + 1) + ", Bias: " + bias);
            // Get all weights
            float[] weights = new float[1];
            weights[0] = FloatByteConverter.CharStringOfBytesToFloat(Data.Substring(FileIndex, 4));
            FileIndex += 4;

            Perceptron P = new Perceptron(weights, bias);
            InputLayer.Add(P);
        }

        // Created Epoch
        Epoch NewEpoch = new Epoch(TetrisBoard.GetDataSize(), hidden_layers, hidden_layers_size, (int)Tetris.Move.TOTAL);

        NewEpoch.SetHiddenLayerData(All_HiddenLayer);
        NewEpoch.SetOutputLayerData(OutputLayer);
        NewEpoch.SetInputLayerData(InputLayer);

        return(NewEpoch);
    }
Ejemplo n.º 29
0
 void Awake()
 {
     board = GetComponent <TetrisBoard> ();
     game  = GetComponent <TetrisGame> ();
 }
Ejemplo n.º 30
0
        public void ClearRows()
        {
            var board = new TetrisBoard(new Vec2i(3, 10));

            board.Cells = new TetrisCell[10][] {
                new TetrisCell[3] {
                    TetrisCell.Z, TetrisCell.Z, 0
                },
                new TetrisCell[3] {
                    TetrisCell.J, TetrisCell.Z, TetrisCell.Z
                },
                new TetrisCell[3] {
                    TetrisCell.J, TetrisCell.J, TetrisCell.J
                },
                new TetrisCell[3] {
                    TetrisCell.L, TetrisCell.L, TetrisCell.L
                },
                new TetrisCell[3] {
                    TetrisCell.L, 0, TetrisCell.Z
                },
                new TetrisCell[3] {
                    0, TetrisCell.Z, TetrisCell.Z
                },
                new TetrisCell[3] {
                    TetrisCell.J, TetrisCell.Z, 0
                },
                new TetrisCell[3] {
                    TetrisCell.J, TetrisCell.J, TetrisCell.J
                },
                new TetrisCell[3] {
                    TetrisCell.T, TetrisCell.T, TetrisCell.T
                },
                new TetrisCell[3] {
                    0, TetrisCell.T, 0
                },
            };

            var expectedBoard = new TetrisCell[10][] {
                new TetrisCell[3] {
                    0, 0, 0
                },
                new TetrisCell[3] {
                    0, 0, 0
                },
                new TetrisCell[3] {
                    0, 0, 0
                },
                new TetrisCell[3] {
                    0, 0, 0
                },
                new TetrisCell[3] {
                    0, 0, 0
                },
                new TetrisCell[3] {
                    TetrisCell.Z, TetrisCell.Z, 0
                },
                new TetrisCell[3] {
                    TetrisCell.L, 0, TetrisCell.Z
                },
                new TetrisCell[3] {
                    0, TetrisCell.Z, TetrisCell.Z
                },
                new TetrisCell[3] {
                    TetrisCell.J, TetrisCell.Z, 0
                },
                new TetrisCell[3] {
                    0, TetrisCell.T, 0
                },
            };

            var fullRows         = board.FindFullLines();
            var expectedFullRows = new int[] { 1, 2, 3, 7, 8 };

            Assert.Equal(expectedFullRows, fullRows);

            board.ClearFullLines();
            Assert.Equal(expectedBoard, board.Cells);
        }